1/*
2 * BCJEncoder
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
12class BCJEncoder extends BCJCoder implements FilterEncoder {
13    private final BCJOptions options;
14    private final long filterID;
15    private final byte[] props;
16
17    BCJEncoder(BCJOptions options, long filterID) {
18        assert isBCJFilterID(filterID);
19        int startOffset = options.getStartOffset();
20
21        if (startOffset == 0) {
22            props = new byte[0];
23        } else {
24            props = new byte[4];
25            for (int i = 0; i < 4; ++i)
26                props[i] = (byte)(startOffset >>> (i * 8));
27        }
28
29        this.filterID = filterID;
30        this.options = (BCJOptions)options.clone();
31    }
32
33    public long getFilterID() {
34        return filterID;
35    }
36
37    public byte[] getFilterProps() {
38        return props;
39    }
40
41    public boolean supportsFlushing() {
42        return false;
43    }
44
45    public FinishableOutputStream getOutputStream(FinishableOutputStream out) {
46        return options.getOutputStream(out);
47    }
48}
49