1 | /* | |
2 | * $Id: PRTokeniser.java 4083 2009-10-30 21:25:10Z trumpetinc $ | |
3 | * | |
4 | * Copyright 2001, 2002 by Paulo Soares. | |
5 | * | |
6 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
7 | * (the "License"); you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
9 | * | |
10 | * Software distributed under the License is distributed on an "AS IS" basis, | |
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 | * for the specific language governing rights and limitations under the License. | |
13 | * | |
14 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
15 | * | |
16 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
17 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
18 | * All Rights Reserved. | |
19 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
20 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
21 | * | |
22 | * Contributor(s): all the names of the contributors are added in the source code | |
23 | * where applicable. | |
24 | * | |
25 | * Alternatively, the contents of this file may be used under the terms of the | |
26 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
27 | * provisions of LGPL are applicable instead of those above. If you wish to | |
28 | * allow use of your version of this file only under the terms of the LGPL | |
29 | * License and not to allow others to use your version of this file under | |
30 | * the MPL, indicate your decision by deleting the provisions above and | |
31 | * replace them with the notice and other provisions required by the LGPL. | |
32 | * If you do not delete the provisions above, a recipient may use your version | |
33 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
34 | * | |
35 | * This library is free software; you can redistribute it and/or modify it | |
36 | * under the terms of the MPL as stated above or under the terms of the GNU | |
37 | * Library General Public License as published by the Free Software Foundation; | |
38 | * either version 2 of the License, or any later version. | |
39 | * | |
40 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
41 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
42 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
43 | * details. | |
44 | * | |
45 | * If you didn't download this code from the following link, you should check if | |
46 | * you aren't using an obsolete version: | |
47 | * http://www.lowagie.com/iText/ | |
48 | */ | |
49 | ||
50 | package com.lowagie.text.pdf; | |
51 | ||
52 | import java.io.IOException; | |
53 | import com.lowagie.text.exceptions.InvalidPdfException; | |
54 | import com.lowagie.text.error_messages.MessageLocalization; | |
55 | /** | |
56 | * | |
57 | * @author Paulo Soares (psoares@consiste.pt) | |
58 | */ | |
59 | public class PRTokeniser { | |
60 | | |
61 | public static final int TK_NUMBER = 1; | |
62 | public static final int TK_STRING = 2; | |
63 | public static final int TK_NAME = 3; | |
64 | public static final int TK_COMMENT = 4; | |
65 | public static final int TK_START_ARRAY = 5; | |
66 | public static final int TK_END_ARRAY = 6; | |
67 | public static final int TK_START_DIC = 7; | |
68 | public static final int TK_END_DIC = 8; | |
69 | public static final int TK_REF = 9; | |
70 | public static final int TK_OTHER = 10; | |
71 | public static final int TK_ENDOFFILE = 11; | |
72 | public static final boolean[] delims = { | |
73 | true, true, false, false, false, false, false, false, false, false, | |
74 | true, true, false, true, true, false, false, false, false, false, | |
75 | false, false, false, false, false, false, false, false, false, false, | |
76 | false, false, false, true, false, false, false, false, true, false, | |
77 | false, true, true, false, false, false, false, false, true, false, | |
78 | false, false, false, false, false, false, false, false, false, false, | |
79 | false, true, false, true, false, false, false, false, false, false, | |
80 | false, false, false, false, false, false, false, false, false, false, | |
81 | false, false, false, false, false, false, false, false, false, false, | |
82 | false, false, true, false, true, false, false, false, false, false, | |
83 | false, false, false, false, false, false, false, false, false, false, | |
84 | false, false, false, false, false, false, false, false, false, false, | |
85 | false, false, false, false, false, false, false, false, false, false, | |
86 | false, false, false, false, false, false, false, false, false, false, | |
87 | false, false, false, false, false, false, false, false, false, false, | |
88 | false, false, false, false, false, false, false, false, false, false, | |
89 | false, false, false, false, false, false, false, false, false, false, | |
90 | false, false, false, false, false, false, false, false, false, false, | |
91 | false, false, false, false, false, false, false, false, false, false, | |
92 | false, false, false, false, false, false, false, false, false, false, | |
93 | false, false, false, false, false, false, false, false, false, false, | |
94 | false, false, false, false, false, false, false, false, false, false, | |
95 | false, false, false, false, false, false, false, false, false, false, | |
96 | false, false, false, false, false, false, false, false, false, false, | |
97 | false, false, false, false, false, false, false, false, false, false, | |
98 | false, false, false, false, false, false, false}; | |
99 | | |
100 | static final String EMPTY = ""; | |
101 | ||
102 | | |
103 | protected RandomAccessFileOrArray file; | |
104 | protected int type; | |
105 | protected String stringValue; | |
106 | protected int reference; | |
107 | protected int generation; | |
108 | protected boolean hexString; | |
109 | | |
110 | public PRTokeniser(String filename) throws IOException { | |
111 | file = new RandomAccessFileOrArray(filename); | |
112 | } | |
113 | ||
114 | public PRTokeniser(byte[] pdfIn) { | |
115 | file = new RandomAccessFileOrArray(pdfIn); | |
116 | } | |
117 | | |
118 | public PRTokeniser(RandomAccessFileOrArray file) { | |
119 | this.file = file; | |
120 | } | |
121 | | |
122 | public void seek(int pos) throws IOException { | |
123 | file.seek(pos); | |
124 | } | |
125 | | |
126 | public int getFilePointer() throws IOException { | |
127 | return file.getFilePointer(); | |
128 | } | |
129 | ||
130 | public void close() throws IOException { | |
131 | file.close(); | |
132 | } | |
133 | | |
134 | public int length() throws IOException { | |
135 | return file.length(); | |
136 | } | |
137 | ||
138 | public int read() throws IOException { | |
139 | return file.read(); | |
140 | } | |
141 | | |
142 | public RandomAccessFileOrArray getSafeFile() { | |
143 |
1
1. getSafeFile : mutated return of Object value for com/lowagie/text/pdf/PRTokeniser::getSafeFile to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new RandomAccessFileOrArray(file); |
144 | } | |
145 | | |
146 | public RandomAccessFileOrArray getFile() { | |
147 | return file; | |
148 | } | |
149 | | |
150 | public String readString(int size) throws IOException { | |
151 | StringBuilder buf = new StringBuilder(); | |
152 | int ch; | |
153 |
3
1. readString : changed conditional boundary → NO_COVERAGE 2. readString : Changed increment from -1 to 1 → NO_COVERAGE 3. readString : negated conditional → NO_COVERAGE |
while ((size--) > 0) { |
154 | ch = file.read(); | |
155 |
1
1. readString : negated conditional → NO_COVERAGE |
if (ch == -1) |
156 | break; | |
157 | buf.append((char)ch); | |
158 | } | |
159 |
1
1. readString : mutated return of Object value for com/lowagie/text/pdf/PRTokeniser::readString to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return buf.toString(); |
160 | } | |
161 | ||
162 | public static final boolean isWhitespace(int ch) { | |
163 |
7
1. isWhitespace : negated conditional → NO_COVERAGE 2. isWhitespace : negated conditional → NO_COVERAGE 3. isWhitespace : negated conditional → NO_COVERAGE 4. isWhitespace : negated conditional → NO_COVERAGE 5. isWhitespace : negated conditional → NO_COVERAGE 6. isWhitespace : negated conditional → NO_COVERAGE 7. isWhitespace : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (ch == 0 || ch == 9 || ch == 10 || ch == 12 || ch == 13 || ch == 32); |
164 | } | |
165 | | |
166 | public static final boolean isDelimiter(int ch) { | |
167 |
9
1. isDelimiter : negated conditional → NO_COVERAGE 2. isDelimiter : negated conditional → NO_COVERAGE 3. isDelimiter : negated conditional → NO_COVERAGE 4. isDelimiter : negated conditional → NO_COVERAGE 5. isDelimiter : negated conditional → NO_COVERAGE 6. isDelimiter : negated conditional → NO_COVERAGE 7. isDelimiter : negated conditional → NO_COVERAGE 8. isDelimiter : negated conditional → NO_COVERAGE 9. isDelimiter : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (ch == '(' || ch == ')' || ch == '<' || ch == '>' || ch == '[' || ch == ']' || ch == '/' || ch == '%'); |
168 | } | |
169 | ||
170 | public static final boolean isDelimiterWhitespace(int ch) { | |
171 |
2
1. isDelimiterWhitespace : Replaced integer addition with subtraction → NO_COVERAGE 2. isDelimiterWhitespace : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return delims[ch + 1]; |
172 | } | |
173 | ||
174 | public int getTokenType() { | |
175 | return type; | |
176 | } | |
177 | | |
178 | public String getStringValue() { | |
179 | return stringValue; | |
180 | } | |
181 | | |
182 | public int getReference() { | |
183 | return reference; | |
184 | } | |
185 | | |
186 | public int getGeneration() { | |
187 | return generation; | |
188 | } | |
189 | | |
190 | public void backOnePosition(int ch) { | |
191 |
1
1. backOnePosition : negated conditional → NO_COVERAGE |
if (ch != -1) |
192 |
1
1. backOnePosition : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::pushBack → NO_COVERAGE |
file.pushBack((byte)ch); |
193 | } | |
194 | | |
195 | public void throwError(String error) throws IOException { | |
196 | throw new InvalidPdfException(MessageLocalization.getComposedMessage("1.at.file.pointer.2", error, String.valueOf(file.getFilePointer()))); | |
197 | } | |
198 | | |
199 | public char checkPdfHeader() throws IOException { | |
200 |
1
1. checkPdfHeader : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::setStartOffset → NO_COVERAGE |
file.setStartOffset(0); |
201 | String str = readString(1024); | |
202 | int idx = str.indexOf("%PDF-"); | |
203 |
2
1. checkPdfHeader : changed conditional boundary → NO_COVERAGE 2. checkPdfHeader : negated conditional → NO_COVERAGE |
if (idx < 0) |
204 | throw new InvalidPdfException(MessageLocalization.getComposedMessage("pdf.header.not.found")); | |
205 |
1
1. checkPdfHeader : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::setStartOffset → NO_COVERAGE |
file.setStartOffset(idx); |
206 |
2
1. checkPdfHeader : Replaced integer addition with subtraction → NO_COVERAGE 2. checkPdfHeader : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return str.charAt(idx + 7); |
207 | } | |
208 | | |
209 | public void checkFdfHeader() throws IOException { | |
210 |
1
1. checkFdfHeader : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::setStartOffset → NO_COVERAGE |
file.setStartOffset(0); |
211 | String str = readString(1024); | |
212 | int idx = str.indexOf("%FDF-1.2"); | |
213 |
2
1. checkFdfHeader : changed conditional boundary → NO_COVERAGE 2. checkFdfHeader : negated conditional → NO_COVERAGE |
if (idx < 0) |
214 | throw new InvalidPdfException(MessageLocalization.getComposedMessage("fdf.header.not.found")); | |
215 |
1
1. checkFdfHeader : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::setStartOffset → NO_COVERAGE |
file.setStartOffset(idx); |
216 | } | |
217 | ||
218 | public int getStartxref() throws IOException { | |
219 | int size = Math.min(1024, file.length()); | |
220 |
1
1. getStartxref : Replaced integer subtraction with addition → NO_COVERAGE |
int pos = file.length() - size; |
221 |
1
1. getStartxref : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::seek → NO_COVERAGE |
file.seek(pos); |
222 | String str = readString(1024); | |
223 | int idx = str.lastIndexOf("startxref"); | |
224 |
2
1. getStartxref : changed conditional boundary → NO_COVERAGE 2. getStartxref : negated conditional → NO_COVERAGE |
if (idx < 0) |
225 | throw new InvalidPdfException(MessageLocalization.getComposedMessage("pdf.startxref.not.found")); | |
226 |
2
1. getStartxref : Replaced integer addition with subtraction → NO_COVERAGE 2. getStartxref : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return pos + idx; |
227 | } | |
228 | ||
229 | public static int getHex(int v) { | |
230 |
4
1. getHex : changed conditional boundary → NO_COVERAGE 2. getHex : changed conditional boundary → NO_COVERAGE 3. getHex : negated conditional → NO_COVERAGE 4. getHex : negated conditional → NO_COVERAGE |
if (v >= '0' && v <= '9') |
231 |
2
1. getHex : Replaced integer subtraction with addition → NO_COVERAGE 2. getHex : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return v - '0'; |
232 |
4
1. getHex : changed conditional boundary → NO_COVERAGE 2. getHex : changed conditional boundary → NO_COVERAGE 3. getHex : negated conditional → NO_COVERAGE 4. getHex : negated conditional → NO_COVERAGE |
if (v >= 'A' && v <= 'F') |
233 |
3
1. getHex : Replaced integer subtraction with addition → NO_COVERAGE 2. getHex : Replaced integer addition with subtraction → NO_COVERAGE 3. getHex : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return v - 'A' + 10; |
234 |
4
1. getHex : changed conditional boundary → NO_COVERAGE 2. getHex : changed conditional boundary → NO_COVERAGE 3. getHex : negated conditional → NO_COVERAGE 4. getHex : negated conditional → NO_COVERAGE |
if (v >= 'a' && v <= 'f') |
235 |
3
1. getHex : Replaced integer subtraction with addition → NO_COVERAGE 2. getHex : Replaced integer addition with subtraction → NO_COVERAGE 3. getHex : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return v - 'a' + 10; |
236 |
1
1. getHex : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return -1; |
237 | } | |
238 | | |
239 | public void nextValidToken() throws IOException { | |
240 | int level = 0; | |
241 | String n1 = null; | |
242 | String n2 = null; | |
243 | int ptr = 0; | |
244 |
2
1. nextValidToken : negated conditional → NO_COVERAGE 2. nextValidToken : negated conditional → NO_COVERAGE |
while (nextToken() || level == 2) { |
245 |
1
1. nextValidToken : negated conditional → NO_COVERAGE |
if (type == TK_COMMENT) |
246 | continue; | |
247 | switch (level) { | |
248 | case 0: | |
249 | { | |
250 |
1
1. nextValidToken : negated conditional → NO_COVERAGE |
if (type != TK_NUMBER) |
251 | return; | |
252 | ptr = file.getFilePointer(); | |
253 | n1 = stringValue; | |
254 |
1
1. nextValidToken : Changed increment from 1 to -1 → NO_COVERAGE |
++level; |
255 | break; | |
256 | } | |
257 | case 1: | |
258 | { | |
259 |
1
1. nextValidToken : negated conditional → NO_COVERAGE |
if (type != TK_NUMBER) { |
260 |
1
1. nextValidToken : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::seek → NO_COVERAGE |
file.seek(ptr); |
261 | type = TK_NUMBER; | |
262 | stringValue = n1; | |
263 | return; | |
264 | } | |
265 | n2 = stringValue; | |
266 |
1
1. nextValidToken : Changed increment from 1 to -1 → NO_COVERAGE |
++level; |
267 | break; | |
268 | } | |
269 | default: | |
270 | { | |
271 |
2
1. nextValidToken : negated conditional → NO_COVERAGE 2. nextValidToken : negated conditional → NO_COVERAGE |
if (type != TK_OTHER || !stringValue.equals("R")) { |
272 |
1
1. nextValidToken : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::seek → NO_COVERAGE |
file.seek(ptr); |
273 | type = TK_NUMBER; | |
274 | stringValue = n1; | |
275 | return; | |
276 | } | |
277 | type = TK_REF; | |
278 | reference = Integer.parseInt(n1); | |
279 | generation = Integer.parseInt(n2); | |
280 | return; | |
281 | } | |
282 | } | |
283 | } | |
284 | // http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=687669#20 | |
285 |
2
1. nextValidToken : changed conditional boundary → NO_COVERAGE 2. nextValidToken : negated conditional → NO_COVERAGE |
if (level > 0) { |
286 | type = TK_NUMBER; | |
287 |
1
1. nextValidToken : removed call to com/lowagie/text/pdf/RandomAccessFileOrArray::seek → NO_COVERAGE |
file.seek(ptr); |
288 | stringValue = n1; | |
289 | return; | |
290 | } | |
291 | // if (type == TK_ENDOFFILE && level > 0) | |
292 | // { | |
293 | // file.seek(ptr); | |
294 | // type = TK_NUMBER; | |
295 | // stringValue = n1; | |
296 | // } | |
297 | ||
298 |
1
1. nextValidToken : removed call to com/lowagie/text/pdf/PRTokeniser::throwError → NO_COVERAGE |
throwError("Unexpected end of file"); |
299 | // if we hit here, the file is either corrupt (stream ended unexpectedly), | |
300 | // or the last token ended exactly at the end of a stream. This last | |
301 | // case can occur inside an Object Stream. | |
302 | } | |
303 | | |
304 | public boolean nextToken() throws IOException { | |
305 | int ch = 0; | |
306 | do { | |
307 | ch = file.read(); | |
308 |
2
1. nextToken : negated conditional → NO_COVERAGE 2. nextToken : negated conditional → NO_COVERAGE |
} while (ch != -1 && isWhitespace(ch)); |
309 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (ch == -1){ |
310 | type = TK_ENDOFFILE; | |
311 |
1
1. nextToken : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
312 | } | |
313 | ||
314 | // Note: We have to initialize stringValue here, after we've looked for the end of the stream, | |
315 | // to ensure that we don't lose the value of a token that might end exactly at the end | |
316 | // of the stream | |
317 | StringBuffer outBuf = null; | |
318 | stringValue = EMPTY; | |
319 | ||
320 | switch (ch) { | |
321 | case '[': | |
322 | type = TK_START_ARRAY; | |
323 | break; | |
324 | case ']': | |
325 | type = TK_END_ARRAY; | |
326 | break; | |
327 | case '/': | |
328 | { | |
329 | outBuf = new StringBuffer(); | |
330 | type = TK_NAME; | |
331 | while (true) { | |
332 | ch = file.read(); | |
333 |
2
1. nextToken : Replaced integer addition with subtraction → NO_COVERAGE 2. nextToken : negated conditional → NO_COVERAGE |
if (delims[ch + 1]) |
334 | break; | |
335 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (ch == '#') { |
336 |
2
1. nextToken : Replaced Shift Left with Shift Right → NO_COVERAGE 2. nextToken : Replaced integer addition with subtraction → NO_COVERAGE |
ch = (getHex(file.read()) << 4) + getHex(file.read()); |
337 | } | |
338 | outBuf.append((char)ch); | |
339 | } | |
340 |
1
1. nextToken : removed call to com/lowagie/text/pdf/PRTokeniser::backOnePosition → NO_COVERAGE |
backOnePosition(ch); |
341 | break; | |
342 | } | |
343 | case '>': | |
344 | ch = file.read(); | |
345 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (ch != '>') |
346 |
1
1. nextToken : removed call to com/lowagie/text/pdf/PRTokeniser::throwError → NO_COVERAGE |
throwError(MessageLocalization.getComposedMessage("greaterthan.not.expected")); |
347 | type = TK_END_DIC; | |
348 | break; | |
349 | case '<': | |
350 | { | |
351 | int v1 = file.read(); | |
352 |
1
1. nextToken : negated conditional → NO_COVERAGE |
while (isWhitespace(v1)) { |
353 | v1 = file.read(); | |
354 | } | |
355 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (v1 == '<') { |
356 | type = TK_START_DIC; | |
357 | break; | |
358 | } | |
359 | outBuf = new StringBuffer(); | |
360 | type = TK_STRING; | |
361 | hexString = true; | |
362 | int v2 = 0; | |
363 | while (true) { | |
364 |
1
1. nextToken : negated conditional → NO_COVERAGE |
while (isWhitespace(v1)) |
365 | v1 = file.read(); | |
366 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (v1 == '>') |
367 | break; | |
368 | v1 = getHex(v1); | |
369 |
2
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : negated conditional → NO_COVERAGE |
if (v1 < 0) |
370 | break; | |
371 | v2 = file.read(); | |
372 |
1
1. nextToken : negated conditional → NO_COVERAGE |
while (isWhitespace(v2)) |
373 | v2 = file.read(); | |
374 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (v2 == '>') { |
375 |
1
1. nextToken : Replaced Shift Left with Shift Right → NO_COVERAGE |
ch = v1 << 4; |
376 | outBuf.append((char)ch); | |
377 | break; | |
378 | } | |
379 | v2 = getHex(v2); | |
380 |
2
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : negated conditional → NO_COVERAGE |
if (v2 < 0) |
381 | break; | |
382 |
2
1. nextToken : Replaced Shift Left with Shift Right → NO_COVERAGE 2. nextToken : Replaced integer addition with subtraction → NO_COVERAGE |
ch = (v1 << 4) + v2; |
383 | outBuf.append((char)ch); | |
384 | v1 = file.read(); | |
385 | } | |
386 |
4
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : changed conditional boundary → NO_COVERAGE 3. nextToken : negated conditional → NO_COVERAGE 4. nextToken : negated conditional → NO_COVERAGE |
if (v1 < 0 || v2 < 0) |
387 |
1
1. nextToken : removed call to com/lowagie/text/pdf/PRTokeniser::throwError → NO_COVERAGE |
throwError(MessageLocalization.getComposedMessage("error.reading.string")); |
388 | break; | |
389 | } | |
390 | case '%': | |
391 | type = TK_COMMENT; | |
392 | do { | |
393 | ch = file.read(); | |
394 |
3
1. nextToken : negated conditional → NO_COVERAGE 2. nextToken : negated conditional → NO_COVERAGE 3. nextToken : negated conditional → NO_COVERAGE |
} while (ch != -1 && ch != '\r' && ch != '\n'); |
395 | break; | |
396 | case '(': | |
397 | { | |
398 | outBuf = new StringBuffer(); | |
399 | type = TK_STRING; | |
400 | hexString = false; | |
401 | int nesting = 0; | |
402 | while (true) { | |
403 | ch = file.read(); | |
404 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (ch == -1) |
405 | break; | |
406 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (ch == '(') { |
407 |
1
1. nextToken : Changed increment from 1 to -1 → NO_COVERAGE |
++nesting; |
408 | } | |
409 |
1
1. nextToken : negated conditional → NO_COVERAGE |
else if (ch == ')') { |
410 |
1
1. nextToken : Changed increment from -1 to 1 → NO_COVERAGE |
--nesting; |
411 | } | |
412 |
1
1. nextToken : negated conditional → NO_COVERAGE |
else if (ch == '\\') { |
413 | boolean lineBreak = false; | |
414 | ch = file.read(); | |
415 | switch (ch) { | |
416 | case 'n': | |
417 | ch = '\n'; | |
418 | break; | |
419 | case 'r': | |
420 | ch = '\r'; | |
421 | break; | |
422 | case 't': | |
423 | ch = '\t'; | |
424 | break; | |
425 | case 'b': | |
426 | ch = '\b'; | |
427 | break; | |
428 | case 'f': | |
429 | ch = '\f'; | |
430 | break; | |
431 | case '(': | |
432 | case ')': | |
433 | case '\\': | |
434 | break; | |
435 | case '\r': | |
436 | lineBreak = true; | |
437 | ch = file.read(); | |
438 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (ch != '\n') |
439 |
1
1. nextToken : removed call to com/lowagie/text/pdf/PRTokeniser::backOnePosition → NO_COVERAGE |
backOnePosition(ch); |
440 | break; | |
441 | case '\n': | |
442 | lineBreak = true; | |
443 | break; | |
444 | default: | |
445 | { | |
446 |
4
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : changed conditional boundary → NO_COVERAGE 3. nextToken : negated conditional → NO_COVERAGE 4. nextToken : negated conditional → NO_COVERAGE |
if (ch < '0' || ch > '7') { |
447 | break; | |
448 | } | |
449 |
1
1. nextToken : Replaced integer subtraction with addition → NO_COVERAGE |
int octal = ch - '0'; |
450 | ch = file.read(); | |
451 |
4
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : changed conditional boundary → NO_COVERAGE 3. nextToken : negated conditional → NO_COVERAGE 4. nextToken : negated conditional → NO_COVERAGE |
if (ch < '0' || ch > '7') { |
452 |
1
1. nextToken : removed call to com/lowagie/text/pdf/PRTokeniser::backOnePosition → NO_COVERAGE |
backOnePosition(ch); |
453 | ch = octal; | |
454 | break; | |
455 | } | |
456 |
3
1. nextToken : Replaced Shift Left with Shift Right → NO_COVERAGE 2. nextToken : Replaced integer addition with subtraction → NO_COVERAGE 3. nextToken : Replaced integer subtraction with addition → NO_COVERAGE |
octal = (octal << 3) + ch - '0'; |
457 | ch = file.read(); | |
458 |
4
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : changed conditional boundary → NO_COVERAGE 3. nextToken : negated conditional → NO_COVERAGE 4. nextToken : negated conditional → NO_COVERAGE |
if (ch < '0' || ch > '7') { |
459 |
1
1. nextToken : removed call to com/lowagie/text/pdf/PRTokeniser::backOnePosition → NO_COVERAGE |
backOnePosition(ch); |
460 | ch = octal; | |
461 | break; | |
462 | } | |
463 |
3
1. nextToken : Replaced Shift Left with Shift Right → NO_COVERAGE 2. nextToken : Replaced integer addition with subtraction → NO_COVERAGE 3. nextToken : Replaced integer subtraction with addition → NO_COVERAGE |
octal = (octal << 3) + ch - '0'; |
464 |
1
1. nextToken : Replaced bitwise AND with OR → NO_COVERAGE |
ch = octal & 0xff; |
465 | break; | |
466 | } | |
467 | } | |
468 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (lineBreak) |
469 | continue; | |
470 |
2
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : negated conditional → NO_COVERAGE |
if (ch < 0) |
471 | break; | |
472 | } | |
473 |
1
1. nextToken : negated conditional → NO_COVERAGE |
else if (ch == '\r') { |
474 | ch = file.read(); | |
475 |
2
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : negated conditional → NO_COVERAGE |
if (ch < 0) |
476 | break; | |
477 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (ch != '\n') { |
478 |
1
1. nextToken : removed call to com/lowagie/text/pdf/PRTokeniser::backOnePosition → NO_COVERAGE |
backOnePosition(ch); |
479 | ch = '\n'; | |
480 | } | |
481 | } | |
482 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (nesting == -1) |
483 | break; | |
484 | outBuf.append((char)ch); | |
485 | } | |
486 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (ch == -1) |
487 |
1
1. nextToken : removed call to com/lowagie/text/pdf/PRTokeniser::throwError → NO_COVERAGE |
throwError(MessageLocalization.getComposedMessage("error.reading.string")); |
488 | break; | |
489 | } | |
490 | default: | |
491 | { | |
492 | outBuf = new StringBuffer(); | |
493 |
7
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : changed conditional boundary → NO_COVERAGE 3. nextToken : negated conditional → NO_COVERAGE 4. nextToken : negated conditional → NO_COVERAGE 5. nextToken : negated conditional → NO_COVERAGE 6. nextToken : negated conditional → NO_COVERAGE 7. nextToken : negated conditional → NO_COVERAGE |
if (ch == '-' || ch == '+' || ch == '.' || (ch >= '0' && ch <= '9')) { |
494 | type = TK_NUMBER; | |
495 | do { | |
496 | outBuf.append((char)ch); | |
497 | ch = file.read(); | |
498 |
6
1. nextToken : changed conditional boundary → NO_COVERAGE 2. nextToken : changed conditional boundary → NO_COVERAGE 3. nextToken : negated conditional → NO_COVERAGE 4. nextToken : negated conditional → NO_COVERAGE 5. nextToken : negated conditional → NO_COVERAGE 6. nextToken : negated conditional → NO_COVERAGE |
} while (ch != -1 && ((ch >= '0' && ch <= '9') || ch == '.')); |
499 | } | |
500 | else { | |
501 | type = TK_OTHER; | |
502 | do { | |
503 | outBuf.append((char)ch); | |
504 | ch = file.read(); | |
505 |
2
1. nextToken : Replaced integer addition with subtraction → NO_COVERAGE 2. nextToken : negated conditional → NO_COVERAGE |
} while (!delims[ch + 1]); |
506 | } | |
507 |
1
1. nextToken : removed call to com/lowagie/text/pdf/PRTokeniser::backOnePosition → NO_COVERAGE |
backOnePosition(ch); |
508 | break; | |
509 | } | |
510 | } | |
511 |
1
1. nextToken : negated conditional → NO_COVERAGE |
if (outBuf != null) |
512 | stringValue = outBuf.toString(); | |
513 |
1
1. nextToken : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
514 | } | |
515 | | |
516 | public int intValue() { | |
517 |
1
1. intValue : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return Integer.parseInt(stringValue); |
518 | } | |
519 | | |
520 | public boolean readLineSegment(byte[] input) throws IOException { | |
521 | int c = -1; | |
522 | boolean eol = false; | |
523 | int ptr = 0; | |
524 | int len = input.length; | |
525 | // ssteward, pdftk-1.10, 040922: | |
526 | // skip initial whitespace; added this because PdfReader.rebuildXref() | |
527 | // assumes that line provided by readLineSegment does not have init. whitespace; | |
528 |
2
1. readLineSegment : changed conditional boundary → NO_COVERAGE 2. readLineSegment : negated conditional → NO_COVERAGE |
if ( ptr < len ) { |
529 |
1
1. readLineSegment : negated conditional → NO_COVERAGE |
while ( isWhitespace( (c = read()) ) ); |
530 | } | |
531 |
3
1. readLineSegment : changed conditional boundary → NO_COVERAGE 2. readLineSegment : negated conditional → NO_COVERAGE 3. readLineSegment : negated conditional → NO_COVERAGE |
while ( !eol && ptr < len ) { |
532 | switch (c) { | |
533 | case -1: | |
534 | case '\n': | |
535 | eol = true; | |
536 | break; | |
537 | case '\r': | |
538 | eol = true; | |
539 | int cur = getFilePointer(); | |
540 |
1
1. readLineSegment : negated conditional → NO_COVERAGE |
if ((read()) != '\n') { |
541 |
1
1. readLineSegment : removed call to com/lowagie/text/pdf/PRTokeniser::seek → NO_COVERAGE |
seek(cur); |
542 | } | |
543 | break; | |
544 | default: | |
545 |
1
1. readLineSegment : Changed increment from 1 to -1 → NO_COVERAGE |
input[ptr++] = (byte)c; |
546 | break; | |
547 | } | |
548 | ||
549 | // break loop? do it before we read() again | |
550 |
3
1. readLineSegment : changed conditional boundary → NO_COVERAGE 2. readLineSegment : negated conditional → NO_COVERAGE 3. readLineSegment : negated conditional → NO_COVERAGE |
if( eol || len <= ptr ) { |
551 | break; | |
552 | } | |
553 | else { | |
554 | c = read(); | |
555 | } | |
556 | } | |
557 |
2
1. readLineSegment : changed conditional boundary → NO_COVERAGE 2. readLineSegment : negated conditional → NO_COVERAGE |
if (ptr >= len) { |
558 | eol = false; | |
559 |
1
1. readLineSegment : negated conditional → NO_COVERAGE |
while (!eol) { |
560 | switch (c = read()) { | |
561 | case -1: | |
562 | case '\n': | |
563 | eol = true; | |
564 | break; | |
565 | case '\r': | |
566 | eol = true; | |
567 | int cur = getFilePointer(); | |
568 |
1
1. readLineSegment : negated conditional → NO_COVERAGE |
if ((read()) != '\n') { |
569 |
1
1. readLineSegment : removed call to com/lowagie/text/pdf/PRTokeniser::seek → NO_COVERAGE |
seek(cur); |
570 | } | |
571 | break; | |
572 | } | |
573 | } | |
574 | } | |
575 | | |
576 |
2
1. readLineSegment : negated conditional → NO_COVERAGE 2. readLineSegment : negated conditional → NO_COVERAGE |
if ((c == -1) && (ptr == 0)) { |
577 |
1
1. readLineSegment : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return false; |
578 | } | |
579 |
3
1. readLineSegment : changed conditional boundary → NO_COVERAGE 2. readLineSegment : Replaced integer addition with subtraction → NO_COVERAGE 3. readLineSegment : negated conditional → NO_COVERAGE |
if (ptr + 2 <= len) { |
580 |
1
1. readLineSegment : Changed increment from 1 to -1 → NO_COVERAGE |
input[ptr++] = (byte)' '; |
581 | input[ptr] = (byte)'X'; | |
582 | } | |
583 |
1
1. readLineSegment : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
584 | } | |
585 | | |
586 | public static int[] checkObjectStart(byte[] line) { | |
587 | try { | |
588 | PRTokeniser tk = new PRTokeniser(line); | |
589 | int num = 0; | |
590 | int gen = 0; | |
591 |
2
1. checkObjectStart : negated conditional → NO_COVERAGE 2. checkObjectStart : negated conditional → NO_COVERAGE |
if (!tk.nextToken() || tk.getTokenType() != TK_NUMBER) |
592 |
1
1. checkObjectStart : mutated return of Object value for com/lowagie/text/pdf/PRTokeniser::checkObjectStart to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
593 | num = tk.intValue(); | |
594 |
2
1. checkObjectStart : negated conditional → NO_COVERAGE 2. checkObjectStart : negated conditional → NO_COVERAGE |
if (!tk.nextToken() || tk.getTokenType() != TK_NUMBER) |
595 |
1
1. checkObjectStart : mutated return of Object value for com/lowagie/text/pdf/PRTokeniser::checkObjectStart to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
596 | gen = tk.intValue(); | |
597 |
1
1. checkObjectStart : negated conditional → NO_COVERAGE |
if (!tk.nextToken()) |
598 |
1
1. checkObjectStart : mutated return of Object value for com/lowagie/text/pdf/PRTokeniser::checkObjectStart to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
599 |
1
1. checkObjectStart : negated conditional → NO_COVERAGE |
if (!tk.getStringValue().equals("obj")) |
600 |
1
1. checkObjectStart : mutated return of Object value for com/lowagie/text/pdf/PRTokeniser::checkObjectStart to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
601 |
1
1. checkObjectStart : mutated return of Object value for com/lowagie/text/pdf/PRTokeniser::checkObjectStart to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new int[]{num, gen}; |
602 | } | |
603 | catch (Exception ioe) { | |
604 | // empty on purpose | |
605 | } | |
606 |
1
1. checkObjectStart : mutated return of Object value for com/lowagie/text/pdf/PRTokeniser::checkObjectStart to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
607 | } | |
608 | | |
609 | public boolean isHexString() { | |
610 | return this.hexString; | |
611 | } | |
612 | | |
613 | } | |
Mutations | ||
143 |
1.1 |
|
153 |
1.1 2.2 3.3 |
|
155 |
1.1 |
|
159 |
1.1 |
|
163 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
167 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 |
|
171 |
1.1 2.2 |
|
191 |
1.1 |
|
192 |
1.1 |
|
200 |
1.1 |
|
203 |
1.1 2.2 |
|
205 |
1.1 |
|
206 |
1.1 2.2 |
|
210 |
1.1 |
|
213 |
1.1 2.2 |
|
215 |
1.1 |
|
220 |
1.1 |
|
221 |
1.1 |
|
224 |
1.1 2.2 |
|
226 |
1.1 2.2 |
|
230 |
1.1 2.2 3.3 4.4 |
|
231 |
1.1 2.2 |
|
232 |
1.1 2.2 3.3 4.4 |
|
233 |
1.1 2.2 3.3 |
|
234 |
1.1 2.2 3.3 4.4 |
|
235 |
1.1 2.2 3.3 |
|
236 |
1.1 |
|
244 |
1.1 2.2 |
|
245 |
1.1 |
|
250 |
1.1 |
|
254 |
1.1 |
|
259 |
1.1 |
|
260 |
1.1 |
|
266 |
1.1 |
|
271 |
1.1 2.2 |
|
272 |
1.1 |
|
285 |
1.1 2.2 |
|
287 |
1.1 |
|
298 |
1.1 |
|
308 |
1.1 2.2 |
|
309 |
1.1 |
|
311 |
1.1 |
|
333 |
1.1 2.2 |
|
335 |
1.1 |
|
336 |
1.1 2.2 |
|
340 |
1.1 |
|
345 |
1.1 |
|
346 |
1.1 |
|
352 |
1.1 |
|
355 |
1.1 |
|
364 |
1.1 |
|
366 |
1.1 |
|
369 |
1.1 2.2 |
|
372 |
1.1 |
|
374 |
1.1 |
|
375 |
1.1 |
|
380 |
1.1 2.2 |
|
382 |
1.1 2.2 |
|
386 |
1.1 2.2 3.3 4.4 |
|
387 |
1.1 |
|
394 |
1.1 2.2 3.3 |
|
404 |
1.1 |
|
406 |
1.1 |
|
407 |
1.1 |
|
409 |
1.1 |
|
410 |
1.1 |
|
412 |
1.1 |
|
438 |
1.1 |
|
439 |
1.1 |
|
446 |
1.1 2.2 3.3 4.4 |
|
449 |
1.1 |
|
451 |
1.1 2.2 3.3 4.4 |
|
452 |
1.1 |
|
456 |
1.1 2.2 3.3 |
|
458 |
1.1 2.2 3.3 4.4 |
|
459 |
1.1 |
|
463 |
1.1 2.2 3.3 |
|
464 |
1.1 |
|
468 |
1.1 |
|
470 |
1.1 2.2 |
|
473 |
1.1 |
|
475 |
1.1 2.2 |
|
477 |
1.1 |
|
478 |
1.1 |
|
482 |
1.1 |
|
486 |
1.1 |
|
487 |
1.1 |
|
493 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 |
|
498 |
1.1 2.2 3.3 4.4 5.5 6.6 |
|
505 |
1.1 2.2 |
|
507 |
1.1 |
|
511 |
1.1 |
|
513 |
1.1 |
|
517 |
1.1 |
|
528 |
1.1 2.2 |
|
529 |
1.1 |
|
531 |
1.1 2.2 3.3 |
|
540 |
1.1 |
|
541 |
1.1 |
|
545 |
1.1 |
|
550 |
1.1 2.2 3.3 |
|
557 |
1.1 2.2 |
|
559 |
1.1 |
|
568 |
1.1 |
|
569 |
1.1 |
|
576 |
1.1 2.2 |
|
577 |
1.1 |
|
579 |
1.1 2.2 3.3 |
|
580 |
1.1 |
|
583 |
1.1 |
|
591 |
1.1 2.2 |
|
592 |
1.1 |
|
594 |
1.1 2.2 |
|
595 |
1.1 |
|
597 |
1.1 |
|
598 |
1.1 |
|
599 |
1.1 |
|
600 |
1.1 |
|
601 |
1.1 |
|
606 |
1.1 |