{
Object value = parseNextToken();
imageParams.setItem( (COSName)nextToken, (COSBase)value );
}
//final token will be the image data, maybe??
PDFOperator imageData = (PDFOperator)nextToken;
lastBIToken.setImageData( imageData.getImageData() );
}
break;
}
case 'I':
{
//ImageParameters imageParams = lastBIToken.getImageParameters();
//int expectedBytes = (int)Math.ceil(imageParams.getHeight() * imageParams.getWidth() *
// (imageParams.getBitsPerComponent()/8) );
//Special case for ID operator
String id = "" + (char)pdfSource.read() + (char)pdfSource.read();
if( !id.equals( "ID" ) )
{
throw new IOException( "Error: Expected operator 'ID' actual='" + id + "'" );
}
ByteArrayOutputStream imageData = new ByteArrayOutputStream();
//boolean foundEnd = false;
if( this.isWhitespace() )
{
//pull off the whitespace character
pdfSource.read();
}
int twoBytesAgo = 0;
int lastByte = pdfSource.read();
int currentByte = pdfSource.read();
int count = 0;
//PDF spec is kinda unclear about this. Should a whitespace
//always appear before EI? Not sure, I found a PDF
//(UnderstandingWebSphereClassLoaders.pdf) which has EI as part
//of the image data and will stop parsing prematurely if there is
//not a check for <whitespace>EI<whitespace>.
while( !(isWhitespace( twoBytesAgo ) &&
lastByte == 'E' &&
currentByte == 'I' &&
isWhitespace() //&&
//amyuni2_05d__pdf1_3_acro4x.pdf has image data that
//is compressed, so expectedBytes is useless here.
//count >= expectedBytes
) &&
!pdfSource.isEOF() )
{
imageData.write( lastByte );
twoBytesAgo = lastByte;
lastByte = currentByte;
currentByte = pdfSource.read();
count++;
}
pdfSource.unread( 'I' ); //unread the EI operator
pdfSource.unread( 'E' );
retval = PDFOperator.getOperator( "ID" );
((PDFOperator)retval).setImageData( imageData.toByteArray() );
break;
}
case ']':
{
// some ']' around without its previous '['