blob: 142b518db18c0055347b6ffc808530ea18b76d26 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
/*
* RangeDecoderFromStream
*
* Authors: Lasse Collin <lasse.collin@tukaani.org>
* Igor Pavlov <http://7-zip.org/>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
package org.tukaani.xz.rangecoder;
import java.io.InputStream;
import java.io.DataInputStream;
import java.io.IOException;
import org.tukaani.xz.CorruptedInputException;
public final class RangeDecoderFromStream extends RangeDecoder {
private final DataInputStream inData;
public RangeDecoderFromStream(InputStream in) throws IOException {
inData = new DataInputStream(in);
if (inData.readUnsignedByte() != 0x00)
throw new CorruptedInputException();
code = inData.readInt();
range = 0xFFFFFFFF;
}
public boolean isFinished() {
return code == 0;
}
public void normalize() throws IOException {
if ((range & TOP_MASK) == 0) {
code = (code << SHIFT_BITS) | inData.readUnsignedByte();
range <<= SHIFT_BITS;
}
}
}
|