| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package org.tukaani.xz; |
| 6 |
|
| 7 |
import java.io.InputStream; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
public final class DeltaOptions extends FilterOptions { |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public static final int DISTANCE_MIN = 1; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public static final int DISTANCE_MAX = 256; |
| 34 |
|
| 35 |
private int distance = DISTANCE_MIN; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public DeltaOptions() {} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public DeltaOptions(int distance) throws UnsupportedOptionsException { |
| 46 |
setDistance(distance); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public void setDistance(int distance) throws UnsupportedOptionsException { |
| 54 |
if (distance < DISTANCE_MIN || distance > DISTANCE_MAX) |
| 55 |
throw new UnsupportedOptionsException( |
| 56 |
"Delta distance must be in the range [" + DISTANCE_MIN |
| 57 |
+ ", " + DISTANCE_MAX + "]: " + distance); |
| 58 |
|
| 59 |
this.distance = distance; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public int getDistance() { |
| 66 |
return distance; |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
public int getEncoderMemoryUsage() { |
| 71 |
return DeltaOutputStream.getMemoryUsage(); |
| 72 |
} |
| 73 |
|
| 74 |
@Override |
| 75 |
public FinishableOutputStream getOutputStream(FinishableOutputStream out, |
| 76 |
ArrayCache arrayCache) { |
| 77 |
return new DeltaOutputStream(out, this); |
| 78 |
} |
| 79 |
|
| 80 |
@Override |
| 81 |
public int getDecoderMemoryUsage() { |
| 82 |
return 1; |
| 83 |
} |
| 84 |
|
| 85 |
@Override |
| 86 |
public InputStream getInputStream(InputStream in, ArrayCache arrayCache) { |
| 87 |
return new DeltaInputStream(in, distance); |
| 88 |
} |
| 89 |
|
| 90 |
@Override |
| 91 |
FilterEncoder getFilterEncoder() { |
| 92 |
return new DeltaEncoder(this); |
| 93 |
} |
| 94 |
|
| 95 |
@Override |
| 96 |
public Object clone() { |
| 97 |
try { |
| 98 |
return super.clone(); |
| 99 |
} catch (CloneNotSupportedException e) { |
| 100 |
assert false; |
| 101 |
throw new RuntimeException(); |
| 102 |
} |
| 103 |
} |
| 104 |
} |