/** * Reads the next token skipping over the comments. * @return {@code true} if a token was read, {@code false} if the end of content was reached. * @throws java.io.IOException on error. */ public boolean nextValidToken() throws java.io.IOException { while (tokeniser.nextToken()) { if (tokeniser.getTokenType() == TokenType.Comment) continue; return true; } return false; }
/** * Reads the next token skipping over the comments. * @return {@code true} if a token was read, {@code false} if the end of content was reached. * @throws java.io.IOException on error. */ public boolean nextValidToken() throws java.io.IOException { while (tokeniser.nextToken()) { if (tokeniser.getTokenType() == TokenType.Comment) continue; return true; } return false; }
/** * Reads the next token skipping over the comments. * @return <CODE>true</CODE> if a token was read, <CODE>false</CODE> if the end of content was reached * @throws IOException on error */ public boolean nextValidToken() throws IOException { while (tokeniser.nextToken()) { if (tokeniser.getTokenType() == PdfTokenizer.TokenType.Comment) continue; return true; } return false; } }
protected PdfArray readArray(boolean objStm) throws IOException { PdfArray array = new PdfArray(); while (true) { PdfObject obj = readObject(true, objStm); if (obj == null) { if (tokens.getTokenType() == PdfTokenizer.TokenType.EndArray) break; if (tokens.getTokenType() == PdfTokenizer.TokenType.EndDic) tokens.throwError(PdfException.UnexpectedGtGt); } array.add(obj); } return array; }
while ((ob = readObject()) != null) { ls.add(ob); if (tokeniser.getTokenType() == PdfTokenizer.TokenType.Other) { if (ob.toString().equals("BI")) { PdfStream inlineImageAsStream = InlineImageParsingUtils.parse(this, currentResources.getResource(PdfName.ColorSpace));
@Override public boolean nextValidToken() throws IOException { getTokeniser().nextValidToken(); switch (getTokeniser().getTokenType()) { case StartArray: ++openArraysCount; break; case EndArray: --openArraysCount; break; case StartDic: ++openDictionaryCount; break; case EndDic: --openDictionaryCount; break; case Obj: case EndObj: throw new RuntimeException(getTokeniser().getTokenType() + LoggerMessages.CHUNK_OF_THIS_TYPE_NOT_ALLOWED_HERE); case EndOfFile: return false; default: break; } return true; } }
protected PdfDictionary readDictionary(boolean objStm) throws IOException { PdfDictionary dic = new PdfDictionary(); while (true) { tokens.nextValidToken(); if (tokens.getTokenType() == PdfTokenizer.TokenType.EndDic) break; if (tokens.getTokenType() != PdfTokenizer.TokenType.Name) tokens.throwError(PdfException.DictionaryKey1IsNotAName, tokens.getStringValue()); PdfName name = readPdfName(true); PdfObject obj = readObject(true, objStm); if (obj == null) { if (tokens.getTokenType() == PdfTokenizer.TokenType.EndDic) tokens.throwError(PdfException.UnexpectedGtGt); if (tokens.getTokenType() == PdfTokenizer.TokenType.EndArray) tokens.throwError(PdfException.UnexpectedCloseBracket); } dic.put(name, obj); } return dic; }
/** * Reads an array. The tokeniser must be positioned past the "[" token. * @return an array * @throws IOException on error */ public PdfArray readArray() throws IOException { PdfArray array = new PdfArray(); while (true) { PdfObject obj = readObject(); if (!obj.isArray() && tokeniser.getTokenType() == PdfTokenizer.TokenType.EndArray) break; if (tokeniser.getTokenType() == PdfTokenizer.TokenType.EndDic && obj.getType() != PdfObject.DICTIONARY) tokeniser.throwError(PdfException.UnexpectedGtGt); array.add(obj); } return array; }
/** * Check whether line starts with object declaration. * @param lineTokenizer tokenizer, built by single line. * @return object number and generation if check is successful, otherwise - null. */ public static int[] checkObjectStart(PdfTokenizer lineTokenizer) { try { lineTokenizer.seek(0); if (!lineTokenizer.nextToken() || lineTokenizer.getTokenType() != TokenType.Number) return null; int num = lineTokenizer.getIntValue(); if (!lineTokenizer.nextToken() || lineTokenizer.getTokenType() != TokenType.Number) return null; int gen = lineTokenizer.getIntValue(); if (!lineTokenizer.nextToken()) return null; if (!Arrays.equals(Obj, lineTokenizer.getByteContent())) return null; return new int[]{num, gen}; } catch (Exception ioe) { // empty on purpose } return null; }
/** * Check whether line starts with object declaration. * @param lineTokenizer tokenizer, built by single line. * @return object number and generation if check is successful, otherwise - null. */ public static int[] checkObjectStart(PdfTokenizer lineTokenizer) { try { lineTokenizer.seek(0); if (!lineTokenizer.nextToken() || lineTokenizer.getTokenType() != TokenType.Number) return null; int num = lineTokenizer.getIntValue(); if (!lineTokenizer.nextToken() || lineTokenizer.getTokenType() != TokenType.Number) return null; int gen = lineTokenizer.getIntValue(); if (!lineTokenizer.nextToken()) return null; if (!Arrays.equals(Obj, lineTokenizer.getByteContent())) return null; return new int[]{num, gen}; } catch (Exception ioe) { // empty on purpose } return null; }
/** * Reads a dictionary. The tokeniser must be positioned past the {@code "<<"} token. * @return the dictionary * @throws java.io.IOException on error */ public CMapObject readDictionary() throws java.io.IOException { Map<String, CMapObject> dic = new HashMap<>(); while (true) { if (!nextValidToken()) throw new IOException("Unexpected end of file."); if (tokeniser.getTokenType() == TokenType.EndDic) break; if (tokeniser.getTokenType() == TokenType.Other && "def".equals(tokeniser.getStringValue())) continue; if (tokeniser.getTokenType() != TokenType.Name) throw new IOException("Dictionary key {0} is not a name.").setMessageParams(tokeniser.getStringValue()); String name = tokeniser.getStringValue(); CMapObject obj = readObject(); if (obj.isToken()) { if (obj.toString().equals(">>")) { tokeniser.throwError(IOException.UnexpectedGtGt); } if (obj.toString().equals("]")) { tokeniser.throwError(IOException.UnexpectedCloseBracket); } } dic.put(name, obj); } return new CMapObject(CMapObject.DICTIONARY, dic); }
/** * Reads a dictionary. The tokeniser must be positioned past the {@code "<<"} token. * @return the dictionary * @throws java.io.IOException on error */ public CMapObject readDictionary() throws java.io.IOException { Map<String, CMapObject> dic = new HashMap<>(); while (true) { if (!nextValidToken()) throw new IOException("Unexpected end of file."); if (tokeniser.getTokenType() == TokenType.EndDic) break; if (tokeniser.getTokenType() == TokenType.Other && "def".equals(tokeniser.getStringValue())) continue; if (tokeniser.getTokenType() != TokenType.Name) throw new IOException("Dictionary key {0} is not a name.").setMessageParams(tokeniser.getStringValue()); String name = tokeniser.getStringValue(); CMapObject obj = readObject(); if (obj.isToken()) { if (obj.toString().equals(">>")) { tokeniser.throwError(IOException.UnexpectedGtGt); } if (obj.toString().equals("]")) { tokeniser.throwError(IOException.UnexpectedCloseBracket); } } dic.put(name, obj); } return new CMapObject(CMapObject.DICTIONARY, dic); }
/** * Reads a dictionary. The tokeniser must be positioned past the "<<" token. * @return the dictionary * @throws IOException on error */ public PdfDictionary readDictionary() throws IOException { PdfDictionary dic = new PdfDictionary(); while (true) { if (!nextValidToken()) throw new PdfException(PdfException.UnexpectedEndOfFile); if (tokeniser.getTokenType() == PdfTokenizer.TokenType.EndDic) break; if (tokeniser.getTokenType() != PdfTokenizer.TokenType.Name) tokeniser.throwError(PdfException.DictionaryKey1IsNotAName, tokeniser.getStringValue()); PdfName name = new PdfName(tokeniser.getStringValue()); PdfObject obj = readObject(); dic.put(name, obj); } return dic; }
final PdfTokenizer.TokenType type = getTokeniser().getTokenType(); switch (type) { case StartArray:
/** * Reads a pdf object. * @return the pdf object * @throws IOException on error */ public PdfObject readObject() throws IOException { if (!nextValidToken()) return null; final PdfTokenizer.TokenType type = tokeniser.getTokenType(); switch (type) { case StartDic: { PdfDictionary dic = readDictionary(); return dic; } case StartArray: return readArray(); case String: PdfString str = new PdfString(tokeniser.getDecodedStringContent()).setHexWriting(tokeniser.isHexString()); return str; case Name: return new PdfName(tokeniser.getByteContent()); case Number: //use PdfNumber(byte[]) here, as in this case number parsing won't happen until it's needed. return new PdfNumber(tokeniser.getByteContent()); default: return new PdfLiteral(tokeniser.getByteContent()); } }
if (!ok) break; if (tokens.getTokenType() != PdfTokenizer.TokenType.Number) { ok = false; break; if (!ok) break; if (tokens.getTokenType() != PdfTokenizer.TokenType.Number) { ok = false; break; tokens.nextToken(); PdfObject obj; if (tokens.getTokenType() == PdfTokenizer.TokenType.Number) { obj = new PdfNumber(tokens.getByteContent()); } else {
if (!nextValidToken()) return null; TokenType type = tokeniser.getTokenType(); switch (type) { case StartDic:
if (!nextValidToken()) return null; TokenType type = tokeniser.getTokenType(); switch (type) { case StartDic:
tokens.seek(reference.getOffset()); tokens.nextValidToken(); if (tokens.getTokenType() != PdfTokenizer.TokenType.Obj || tokens.getObjNr() != reference.getObjNumber() || tokens.getGenNr() != reference.getGenNumber()) {
throw new PdfException(PdfException.PdfStartxrefNotFound, tokens); tokens.nextToken(); if (tokens.getTokenType() != PdfTokenizer.TokenType.Number) throw new PdfException(PdfException.PdfStartxrefIsNotFollowedByANumber, tokens); long startxref = tokens.getLongValue();