seqSource.unread(nextThreeBytes, 0, amountRead);
/** * This will read an long from the stream. * * @return The long that was read from the stream. * * @throws IOException If there is an error reading from the stream. */ protected long readLong() throws IOException { skipSpaces(); long retval = 0; StringBuilder longBuffer = readStringNumber(); try { retval = Long.parseLong( longBuffer.toString() ); } catch( NumberFormatException e ) { seqSource.unread(longBuffer.toString().getBytes(ISO_8859_1)); throw new IOException( "Error: Expected a long type at offset " + seqSource.getPosition() + ", instead got '" + longBuffer + "'", e); } return retval; }
protected void skipWhiteSpaces() throws IOException { //PDF Ref 3.2.7 A stream must be followed by either //a CRLF or LF but nothing else. int whitespace = seqSource.read(); //see brother_scan_cover.pdf, it adds whitespaces //after the stream but before the start of the //data, so just read those first while (ASCII_SPACE == whitespace) { whitespace = seqSource.read(); } if (ASCII_CR == whitespace) { whitespace = seqSource.read(); if (ASCII_LF != whitespace) { seqSource.unread(whitespace); //The spec says this is invalid but it happens in the real //world so we must support it. } } else if (ASCII_LF != whitespace) { //we are in an error. //but again we will do a lenient parsing and just assume that everything //is fine seqSource.unread(whitespace); } }
/** * This will read an integer from the stream. * * @return The integer that was read from the stream. * * @throws IOException If there is an error reading from the stream. */ protected int readInt() throws IOException { skipSpaces(); int retval = 0; StringBuilder intBuffer = readStringNumber(); try { retval = Integer.parseInt( intBuffer.toString() ); } catch( NumberFormatException e ) { seqSource.unread(intBuffer.toString().getBytes(ISO_8859_1)); throw new IOException( "Error: Expected an integer type at offset "+ seqSource.getPosition(), e); } return retval; }
seqSource.unread(lastByte);
pdfSource.unread(binCharTestArr, 0, readBytes);
/** * This will read the next string from the stream. * * @return The string that was read from the stream, never null. * * @throws IOException If there is an error reading from the stream. */ protected String readString() throws IOException { skipSpaces(); StringBuilder buffer = new StringBuilder(); int c = seqSource.read(); while( !isEndOfName((char)c) && c != -1 ) { buffer.append( (char)c ); c = seqSource.read(); } if (c != -1) { seqSource.unread(c); } return buffer.toString(); }
seqSource.unread(c);
seqSource.unread(c);
private void parseCOSDictionaryNameValuePair(COSDictionary obj) throws IOException { COSName key = parseCOSName(); COSBase value = parseCOSDictionaryValue(); skipSpaces(); if (((char) seqSource.peek()) == 'd') { // if the next string is 'def' then we are parsing a cmap stream // and want to ignore it, otherwise throw an exception. String potentialDEF = readString(); if (!potentialDEF.equals(DEF)) { seqSource.unread(potentialDEF.getBytes(ISO_8859_1)); } else { skipSpaces(); } } if (value == null) { LOG.warn("Bad dictionary declaration at offset " + seqSource.getPosition()); } else { // label this item as direct, to avoid signature problems. value.setDirect(true); obj.setItem(key, value); } }
/** * This will skip all spaces and comments that are present. * * @throws IOException If there is an error reading from the stream. */ protected void skipSpaces() throws IOException { int c = seqSource.read(); // 37 is the % character, a comment while( isWhitespace(c) || c == 37) { if ( c == 37 ) { // skip past the comment section c = seqSource.read(); while(!isEOL(c) && c != -1) { c = seqSource.read(); } } else { c = seqSource.read(); } } if (c != -1) { seqSource.unread(c); } }
seqSource.unread(leftBracket);
seqSource.unread(isThisTheEnd.getBytes(ISO_8859_1)); if(ENDOBJ_STRING.equals(isThisTheEnd) || ENDSTREAM_STRING.equals(isThisTheEnd))
seqSource.unread(c); return false;
/** * This will read an integer from the stream. * * @return The integer that was read from the stream. * * @throws IOException If there is an error reading from the stream. */ protected int readInt() throws IOException { skipSpaces(); int retval = 0; StringBuilder intBuffer = readStringNumber(); try { retval = Integer.parseInt( intBuffer.toString() ); } catch( NumberFormatException e ) { seqSource.unread(intBuffer.toString().getBytes(ISO_8859_1)); throw new IOException( "Error: Expected an integer type at offset "+ seqSource.getPosition(), e); } return retval; }
/** * This will read an long from the stream. * * @return The long that was read from the stream. * * @throws IOException If there is an error reading from the stream. */ protected long readLong() throws IOException { skipSpaces(); long retval = 0; StringBuilder longBuffer = readStringNumber(); try { retval = Long.parseLong( longBuffer.toString() ); } catch( NumberFormatException e ) { seqSource.unread(longBuffer.toString().getBytes(ISO_8859_1)); throw new IOException( "Error: Expected a long type at offset " + seqSource.getPosition() + ", instead got '" + longBuffer + "'", e); } return retval; }
/** * This will read the next string from the stream. * * @return The string that was read from the stream, never null. * * @throws IOException If there is an error reading from the stream. */ protected String readString() throws IOException { skipSpaces(); StringBuilder buffer = new StringBuilder(); int c = seqSource.read(); while( !isEndOfName((char)c) && c != -1 ) { buffer.append( (char)c ); c = seqSource.read(); } if (c != -1) { seqSource.unread(c); } return buffer.toString(); }
/** * This will read the next string from the stream. * * @return The string that was read from the stream, never null. * * @throws IOException If there is an error reading from the stream. */ protected String readString() throws IOException { skipSpaces(); StringBuilder buffer = new StringBuilder(); int c = seqSource.read(); while( !isEndOfName((char)c) && c != -1 ) { buffer.append( (char)c ); c = seqSource.read(); } if (c != -1) { seqSource.unread(c); } return buffer.toString(); }