source: josm/trunk/src/org/tukaani/xz/LZMA2Encoder.java@ 15948

Last change on this file since 15948 was 13350, checked in by stoecker, 7 years ago

see #15816 - add XZ support

File size: 1.4 KB
Line 
1/*
2 * LZMA2Encoder
3 *
4 * Author: Lasse Collin <lasse.collin@tukaani.org>
5 *
6 * This file has been put into the public domain.
7 * You can do whatever you want with this file.
8 */
9
10package org.tukaani.xz;
11
12import org.tukaani.xz.lzma.LZMAEncoder;
13
14class LZMA2Encoder extends LZMA2Coder implements FilterEncoder {
15 private final LZMA2Options options;
16 private final byte[] props = new byte[1];
17
18 LZMA2Encoder(LZMA2Options options) {
19 if (options.getPresetDict() != null)
20 throw new IllegalArgumentException(
21 "XZ doesn't support a preset dictionary for now");
22
23 if (options.getMode() == LZMA2Options.MODE_UNCOMPRESSED) {
24 props[0] = (byte)0;
25 } else {
26 int d = Math.max(options.getDictSize(),
27 LZMA2Options.DICT_SIZE_MIN);
28 props[0] = (byte)(LZMAEncoder.getDistSlot(d - 1) - 23);
29 }
30
31 // Make a private copy so that the caller is free to change its copy.
32 this.options = (LZMA2Options)options.clone();
33 }
34
35 public long getFilterID() {
36 return FILTER_ID;
37 }
38
39 public byte[] getFilterProps() {
40 return props;
41 }
42
43 public boolean supportsFlushing() {
44 return true;
45 }
46
47 public FinishableOutputStream getOutputStream(FinishableOutputStream out,
48 ArrayCache arrayCache) {
49 return options.getOutputStream(out, arrayCache);
50 }
51}
Note: See TracBrowser for help on using the repository browser.