Skip to content

Commit daface1

Browse files
committed
Add LZMA2 encoder.
1 parent 617ea17 commit daface1

18 files changed

Lines changed: 3298 additions & 56 deletions

src/org/tukaani/xz/LZMA2Encoder.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,26 @@
1010
package org.tukaani.xz;
1111

1212
import java.io.OutputStream;
13+
import org.tukaani.xz.lzma.LZMAEncoder;
1314

1415
class LZMA2Encoder extends LZMA2Coder implements FilterEncoder {
1516
private LZMA2Options options;
1617
private byte[] props = new byte[1];
1718

1819
LZMA2Encoder(LZMA2Options options) {
19-
// Make a private copy so that the caller is free to change its copy.
20-
this.options = (LZMA2Options)options.clone();
20+
if (options.getPresetDict() != null)
21+
throw new IllegalArgumentException(
22+
"XZ doesn't support a preset dictionary for now");
2123

22-
// TODO: Props!!!
24+
if (options.getMode() == LZMA2Options.MODE_UNCOMPRESSED) {
25+
props[0] = (byte)0;
26+
} else {
27+
int d = Math.max(options.getDictSize(), options.DICT_SIZE_MIN);
28+
props[0] = (byte)(LZMAEncoder.getDistSlot(d - 1) - 23);
29+
}
2330

31+
// Make a private copy so that the caller is free to change its copy.
32+
this.options = (LZMA2Options)options.clone();
2433
}
2534

2635
public long getFilterID() {

0 commit comments

Comments
 (0)