{
String next = readString();
retval = PDFOperator.getOperator( next );
if( next.equals( "BI" ) )
{
PDFOperator beginImageOP = (PDFOperator)retval;
COSDictionary imageParams = new COSDictionary();
beginImageOP.setImageParameters( new ImageParameters( imageParams ) );
Object nextToken = null;
while( (nextToken = parseNextToken()) instanceof COSName )
{
Object value = parseNextToken();
imageParams.setItem( (COSName)nextToken, (COSBase)value );
}
//final token will be the image data, maybe??
PDFOperator imageData = (PDFOperator)nextToken;
beginImageOP.setImageData( imageData.getImageData() );
}
break;
}
case 'I':
{
//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();
if( isWhitespace() )
{
//pull off the whitespace character
pdfSource.read();
}
int lastByte = pdfSource.read();
int currentByte = pdfSource.read();
// PDF spec is kinda unclear about this. Should a whitespace
// always appear before EI? Not sure, so that we just read
// until EI<whitespace>.
// Be aware not all kind of whitespaces are allowed here. see PDFBOX-1561
while( !(lastByte == 'E' &&
currentByte == 'I' &&
hasNextSpaceOrReturn() &&
hasNoFollowingBinData( pdfSource ) &&
!hasPrecedingAscii85Data(imageData)) &&
!pdfSource.isEOF() )
{
imageData.write( lastByte );
lastByte = currentByte;
currentByte = pdfSource.read();
}
// the EI operator isn't unread, as it won't be processed anyway
retval = PDFOperator.getOperator( "ID" );
// save the image data to the operator, so that it can be accessed later
((PDFOperator)retval).setImageData( imageData.toByteArray() );
break;
}
case ']':
{
// some ']' around without its previous '['