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