This is the used for the LZWDecode filter. This represents the dictionary mappings
between codes and their values.
Method from org.apache.pdfbox.filter.LZWDictionary Detail: |
public void clear() {
buffer.reset();
}
This will crear the internal buffer that the dictionary uses. |
public int getCodeSize() {
return codeSize;
}
This will get the size of the code in bits, 9, 10, or 11. |
public byte[] getData(long code) {
return (byte[])codeToData.get( new Long( code ) );
}
This will get the value for the code. It will return null if the code is not
defined. |
public long getNextCode() {
return nextCode;
}
This will get the next code that will be created. |
public LZWNode getNode(byte[] data) {
return root.getNode( data );
}
This will folow the path to the data node. |
public void visit(byte[] data) throws IOException {
for( int i=0; i< data.length; i++ )
{
visit( data[i] );
}
}
This will take a visit from a byte[]. This will create new code entries as
necessary. |
public void visit(byte data) throws IOException {
buffer.write( data );
byte[] curBuffer = buffer.toByteArray();
LZWNode previous = null;
LZWNode current = root;
boolean createNewCode = false;
for( int i=0; i< curBuffer.length && current != null; i++ )
{
previous = current;
current = current.getNode( curBuffer[i] );
if( current == null )
{
createNewCode = true;
current = new LZWNode();
previous.setNode( curBuffer[i], current );
}
}
if( createNewCode )
{
long code = nextCode++;
current.setCode( code );
codeToData.put( new Long( code ), curBuffer );
/**
System.out.print( "Adding " + code + "='" );
for( int i=0; i< curBuffer.length; i++ )
{
String hex = Integer.toHexString( ((curBuffer[i]+256)%256) );
if( hex.length() < =1 )
{
hex = "0" + hex;
}
if( i != curBuffer.length -1 )
{
hex += " ";
}
System.out.print( hex.toUpperCase() );
}
System.out.println( "'" );
**/
buffer.reset();
buffer.write( data );
resetCodeSize();
}
}
This will take a visit from a byte. This will create new code entries as
necessary. |