org.apache.pdfbox.io
public class: NBitInputStream [javadoc |
source]
java.lang.Object
org.apache.pdfbox.io.NBitInputStream
This is an n-bit input stream. This means that you can read chunks of data
as any number of bits, not just 8 bits like the regular input stream. Just set the
number of bits that you would like to read on each call. The default is 8.
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.pdfbox.io.NBitInputStream Detail: |
public int getBitsInChunk() {
return bitsInChunk;
}
Getter for property bitsToRead. |
public long read() throws IOException {
long retval = 0;
for( int i=0; i< bitsInChunk && retval != -1; i++ )
{
if( bitsLeftInCurrentByte == 0 )
{
currentByte = in.read();
bitsLeftInCurrentByte = 8;
}
if( currentByte == -1 )
{
retval = -1;
}
else
{
retval < < = 1;
retval |= ((currentByte > > (bitsLeftInCurrentByte-1))&0x1);
bitsLeftInCurrentByte--;
}
}
return retval;
}
This will read the next n bits from the stream and return the unsigned
value of those bits. |
public void setBitsInChunk(int bitsInChunkValue) {
bitsInChunk = bitsInChunkValue;
}
Setter for property bitsToRead. |
public void unread(long data) {
data < < = bitsLeftInCurrentByte;
currentByte |= data;
bitsLeftInCurrentByte += bitsInChunk;
}
This will unread some data. |