source: josm/trunk/src/org/tukaani/xz/BCJDecoder.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.8 KB
Line 
1/*
2 * BCJDecoder
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 java.io.InputStream;
13import org.tukaani.xz.simple.*;
14
15class BCJDecoder extends BCJCoder implements FilterDecoder {
16 private final long filterID;
17 private final int startOffset;
18
19 BCJDecoder(long filterID, byte[] props)
20 throws UnsupportedOptionsException {
21 assert isBCJFilterID(filterID);
22 this.filterID = filterID;
23
24 if (props.length == 0) {
25 startOffset = 0;
26 } else if (props.length == 4) {
27 int n = 0;
28 for (int i = 0; i < 4; ++i)
29 n |= (props[i] & 0xFF) << (i * 8);
30
31 startOffset = n;
32 } else {
33 throw new UnsupportedOptionsException(
34 "Unsupported BCJ filter properties");
35 }
36 }
37
38 public int getMemoryUsage() {
39 return SimpleInputStream.getMemoryUsage();
40 }
41
42 public InputStream getInputStream(InputStream in, ArrayCache arrayCache) {
43 SimpleFilter simpleFilter = null;
44
45 if (filterID == X86_FILTER_ID)
46 simpleFilter = new X86(false, startOffset);
47 else if (filterID == POWERPC_FILTER_ID)
48 simpleFilter = new PowerPC(false, startOffset);
49 else if (filterID == IA64_FILTER_ID)
50 simpleFilter = new IA64(false, startOffset);
51 else if (filterID == ARM_FILTER_ID)
52 simpleFilter = new ARM(false, startOffset);
53 else if (filterID == ARMTHUMB_FILTER_ID)
54 simpleFilter = new ARMThumb(false, startOffset);
55 else if (filterID == SPARC_FILTER_ID)
56 simpleFilter = new SPARC(false, startOffset);
57 else
58 assert false;
59
60 return new SimpleInputStream(in, simpleFilter);
61 }
62}
Note: See TracBrowser for help on using the repository browser.