public void decode(InputStream compressedData,
OutputStream result,
COSDictionary options,
int filterIndex) throws IOException {
int value = 0;
int firstByte = 0;
int secondByte = 0;
while ((firstByte = compressedData.read()) != -1)
{
// always after first char
while(isWhitespace(firstByte))
{
firstByte = compressedData.read();
}
if(isEOD(firstByte))
{
break;
}
if(REVERSE_HEX[firstByte] == -1)
{
System.out.println("Invalid Hex Code; int: " + firstByte + " char: " + (char) firstByte);
}
value = REVERSE_HEX[firstByte] * 16;
secondByte = compressedData.read();
if(isEOD(secondByte))
{
// second value behaves like 0 in case of EOD
result.write( value );
break;
}
if(secondByte >= 0)
{
if(REVERSE_HEX[secondByte] == -1)
{
System.out.println("Invalid Hex Code; int: " + secondByte + " char: " + (char) secondByte);
}
value += REVERSE_HEX[secondByte];
}
result.write( value );
}
result.flush();
}
|