Debian Codegraph @

src/org/tukaani/xz/LZMA2Encoder.java

raw symbols SCIP
1 // SPDX-License-Identifier: 0BSD
2 // SPDX-FileCopyrightText: The XZ for Java authors and contributors
3 // SPDX-FileContributor: Lasse Collin <[email protected]>
4
5 package org.tukaani.xz;
6
7 import org.tukaani.xz.lzma.LZMAEncoder;
8
9 class LZMA2Encoder extends LZMA2Coder implements FilterEncoder {
10 private final LZMA2Options options;
11 private final byte[] props = new byte[1];
12
13 LZMA2Encoder(LZMA2Options options) {
14 if (options.getPresetDict() != null)
15 throw new IllegalArgumentException(
16 "XZ doesn't support a preset dictionary for now");
17
18 if (options.getMode() == LZMA2Options.MODE_UNCOMPRESSED) {
19 props[0] = (byte)0;
20 } else {
21 int d = Math.max(options.getDictSize(),
22 LZMA2Options.DICT_SIZE_MIN);
23 props[0] = (byte)(LZMAEncoder.getDistSlot(d - 1) - 23);
24 }
25
26 // Make a private copy so that the caller is free to change its copy.
27 this.options = (LZMA2Options)options.clone();
28 }
29
30 @Override
31 public long getFilterID() {
32 return FILTER_ID;
33 }
34
35 @Override
36 public byte[] getFilterProps() {
37 return props;
38 }
39
40 @Override
41 public boolean supportsFlushing() {
42 return true;
43 }
44
45 @Override
46 public FinishableOutputStream getOutputStream(FinishableOutputStream out,
47 ArrayCache arrayCache) {
48 return options.getOutputStream(out, arrayCache);
49 }
50 }