PdfLister.java

1
/*
2
 * $Id: PdfLister.java 3735 2009-02-26 01:44:03Z xlv $
3
 *
4
 * Copyright 2002 Mark Thompson
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
 * This class by Mark Thompson. Copyright (C) 2002 Mark Thompson
23
 *
24
 * Contributor(s): all the names of the contributors are added in the source code
25
 * where applicable.
26
 *
27
 * Alternatively, the contents of this file may be used under the terms of the
28
 * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
29
 * provisions of LGPL are applicable instead of those above.  If you wish to
30
 * allow use of your version of this file only under the terms of the LGPL
31
 * License and not to allow others to use your version of this file under
32
 * the MPL, indicate your decision by deleting the provisions above and
33
 * replace them with the notice and other provisions required by the LGPL.
34
 * If you do not delete the provisions above, a recipient may use your version
35
 * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE.
36
 *
37
 * This library is free software; you can redistribute it and/or modify it
38
 * under the terms of the MPL as stated above or under the terms of the GNU
39
 * Library General Public License as published by the Free Software Foundation;
40
 * either version 2 of the License, or any later version.
41
 *
42
 * This library is distributed in the hope that it will be useful, but WITHOUT
43
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
44
 * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more
45
 * details.
46
 *
47
 * If you didn't download this code from the following link, you should check if
48
 * you aren't using an obsolete version:
49
 * http://www.lowagie.com/iText/
50
 */
51
52
 package com.lowagie.text.pdf;
53
54
import java.io.IOException;
55
import java.io.PrintStream;
56
import java.util.Iterator;
57
/**
58
 * List a PDF file in human-readable form (for debugging reasons mostly)
59
 * @author Mark Thompson
60
 */
61
62
public class PdfLister {
63
64
    /** the printStream you want to write the output to. */
65
    PrintStream out;
66
67
    /**
68
     * Create a new lister object.
69
     * @param out
70
     */
71
    public PdfLister(PrintStream out) {
72
        this.out = out;
73
    }
74
75
    /**
76
     * Visualizes a PDF object.
77
     * @param object    a com.lowagie.text.pdf object
78
     */
79
    public void listAnyObject(PdfObject object)
80
    {
81
        switch (object.type()) {
82
        case PdfObject.ARRAY:
83 1 1. listAnyObject : removed call to com/lowagie/text/pdf/PdfLister::listArray → NO_COVERAGE
            listArray((PdfArray)object);
84
            break;
85
        case PdfObject.DICTIONARY:
86 1 1. listAnyObject : removed call to com/lowagie/text/pdf/PdfLister::listDict → NO_COVERAGE
            listDict((PdfDictionary) object);
87
            break;
88
        case PdfObject.STRING:
89 1 1. listAnyObject : removed call to java/io/PrintStream::println → NO_COVERAGE
            out.println("(" + object.toString() + ")");
90
            break;
91
        default:
92 1 1. listAnyObject : removed call to java/io/PrintStream::println → NO_COVERAGE
            out.println(object.toString());
93
            break;
94
        }
95
    }
96
    /**
97
     * Visualizes a PdfDictionary object.
98
     * @param dictionary    a com.lowagie.text.pdf.PdfDictionary object
99
     */
100
    public void listDict(PdfDictionary dictionary)
101
    {
102 1 1. listDict : removed call to java/io/PrintStream::println → NO_COVERAGE
        out.println("<<");
103
        PdfName key;
104
        PdfObject value;
105
        for (PdfName pdfName : dictionary.getKeys()) {
106
            key = pdfName;
107
            value = dictionary.get(key);
108 1 1. listDict : removed call to java/io/PrintStream::print → NO_COVERAGE
            out.print(key.toString());
109 1 1. listDict : removed call to java/io/PrintStream::print → NO_COVERAGE
            out.print(' ');
110 1 1. listDict : removed call to com/lowagie/text/pdf/PdfLister::listAnyObject → NO_COVERAGE
            listAnyObject(value);
111
        }
112 1 1. listDict : removed call to java/io/PrintStream::println → NO_COVERAGE
        out.println(">>");
113
    }
114
115
    /**
116
     * Visualizes a PdfArray object.
117
     * @param array    a com.lowagie.text.pdf.PdfArray object
118
     */
119
    public void listArray(PdfArray array)
120
    {
121 1 1. listArray : removed call to java/io/PrintStream::println → NO_COVERAGE
        out.println('[');
122 1 1. listArray : negated conditional → NO_COVERAGE
        for (Iterator i = array.listIterator(); i.hasNext(); ) {
123
            PdfObject item = (PdfObject)i.next();
124 1 1. listArray : removed call to com/lowagie/text/pdf/PdfLister::listAnyObject → NO_COVERAGE
            listAnyObject(item);
125
        }
126 1 1. listArray : removed call to java/io/PrintStream::println → NO_COVERAGE
        out.println(']');
127
    }
128
    /**
129
     * Visualizes a Stream.
130
     * @param stream
131
     * @param reader
132
     */
133
    public void listStream(PRStream stream, PdfReaderInstance reader)
134
    {
135
        try {
136 1 1. listStream : removed call to com/lowagie/text/pdf/PdfLister::listDict → NO_COVERAGE
            listDict(stream);
137 1 1. listStream : removed call to java/io/PrintStream::println → NO_COVERAGE
            out.println("startstream");
138
            byte[] b = PdfReader.getStreamBytes(stream);
139
//                  byte buf[] = new byte[Math.min(stream.getLength(), 4096)];
140
//                  int r = 0;
141
//                  stream.openStream(reader);
142
//                  for (;;) {
143
//                      r = stream.readStream(buf, 0, buf.length);
144
//                      if (r == 0) break;
145
//                      out.write(buf, 0, r);
146
//                  }
147
//                  stream.closeStream();
148 1 1. listStream : Replaced integer subtraction with addition → NO_COVERAGE
            int len = b.length - 1;
149 3 1. listStream : changed conditional boundary → NO_COVERAGE
2. listStream : Changed increment from 1 to -1 → NO_COVERAGE
3. listStream : negated conditional → NO_COVERAGE
            for (int k = 0; k < len; ++k) {
150 3 1. listStream : Replaced integer addition with subtraction → NO_COVERAGE
2. listStream : negated conditional → NO_COVERAGE
3. listStream : negated conditional → NO_COVERAGE
                if (b[k] == '\r' && b[k + 1] != '\n')
151
                    b[k] = (byte)'\n';
152
            }
153 1 1. listStream : removed call to java/io/PrintStream::println → NO_COVERAGE
            out.println(new String(b));
154 1 1. listStream : removed call to java/io/PrintStream::println → NO_COVERAGE
            out.println("endstream");
155
        } catch (IOException e) {
156 1 1. listStream : removed call to java/io/PrintStream::println → NO_COVERAGE
            System.err.println("I/O exception: " + e);
157
//          } catch (java.util.zip.DataFormatException e) {
158
//              System.err.println("Data Format Exception: " + e);
159
        }
160
    }
161
    /**
162
     * Visualizes an imported page
163
     * @param iPage
164
     */
165
    public void listPage(PdfImportedPage iPage)
166
    {
167
        int pageNum = iPage.getPageNumber();
168
        PdfReaderInstance readerInst = iPage.getPdfReaderInstance();
169
        PdfReader reader = readerInst.getReader();
170
171
        PdfDictionary page = reader.getPageN(pageNum);
172 1 1. listPage : removed call to com/lowagie/text/pdf/PdfLister::listDict → NO_COVERAGE
        listDict(page);
173
        PdfObject obj = PdfReader.getPdfObject(page.get(PdfName.CONTENTS));
174 1 1. listPage : negated conditional → NO_COVERAGE
        if (obj == null)
175
            return;
176
        switch (obj.type) {
177
        case PdfObject.STREAM:
178 1 1. listPage : removed call to com/lowagie/text/pdf/PdfLister::listStream → NO_COVERAGE
            listStream((PRStream)obj, readerInst);
179
            break;
180
        case PdfObject.ARRAY:
181 1 1. listPage : negated conditional → NO_COVERAGE
            for (Iterator i = ((PdfArray)obj).listIterator(); i.hasNext();) {
182
                PdfObject o = PdfReader.getPdfObject((PdfObject)i.next());
183 1 1. listPage : removed call to com/lowagie/text/pdf/PdfLister::listStream → NO_COVERAGE
                listStream((PRStream)o, readerInst);
184 1 1. listPage : removed call to java/io/PrintStream::println → NO_COVERAGE
                out.println("-----------");
185
            }
186
            break;
187
        }
188
    }
189
}

Mutations

83

1.1
Location : listAnyObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfLister::listArray → NO_COVERAGE

86

1.1
Location : listAnyObject
Killed by : none
removed call to com/lowagie/text/pdf/PdfLister::listDict → NO_COVERAGE

89

1.1
Location : listAnyObject
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

92

1.1
Location : listAnyObject
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

102

1.1
Location : listDict
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

108

1.1
Location : listDict
Killed by : none
removed call to java/io/PrintStream::print → NO_COVERAGE

109

1.1
Location : listDict
Killed by : none
removed call to java/io/PrintStream::print → NO_COVERAGE

110

1.1
Location : listDict
Killed by : none
removed call to com/lowagie/text/pdf/PdfLister::listAnyObject → NO_COVERAGE

112

1.1
Location : listDict
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

121

1.1
Location : listArray
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

122

1.1
Location : listArray
Killed by : none
negated conditional → NO_COVERAGE

124

1.1
Location : listArray
Killed by : none
removed call to com/lowagie/text/pdf/PdfLister::listAnyObject → NO_COVERAGE

126

1.1
Location : listArray
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

136

1.1
Location : listStream
Killed by : none
removed call to com/lowagie/text/pdf/PdfLister::listDict → NO_COVERAGE

137

1.1
Location : listStream
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

148

1.1
Location : listStream
Killed by : none
Replaced integer subtraction with addition → NO_COVERAGE

149

1.1
Location : listStream
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : listStream
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

3.3
Location : listStream
Killed by : none
negated conditional → NO_COVERAGE

150

1.1
Location : listStream
Killed by : none
Replaced integer addition with subtraction → NO_COVERAGE

2.2
Location : listStream
Killed by : none
negated conditional → NO_COVERAGE

3.3
Location : listStream
Killed by : none
negated conditional → NO_COVERAGE

153

1.1
Location : listStream
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

154

1.1
Location : listStream
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

156

1.1
Location : listStream
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

172

1.1
Location : listPage
Killed by : none
removed call to com/lowagie/text/pdf/PdfLister::listDict → NO_COVERAGE

174

1.1
Location : listPage
Killed by : none
negated conditional → NO_COVERAGE

178

1.1
Location : listPage
Killed by : none
removed call to com/lowagie/text/pdf/PdfLister::listStream → NO_COVERAGE

181

1.1
Location : listPage
Killed by : none
negated conditional → NO_COVERAGE

183

1.1
Location : listPage
Killed by : none
removed call to com/lowagie/text/pdf/PdfLister::listStream → NO_COVERAGE

184

1.1
Location : listPage
Killed by : none
removed call to java/io/PrintStream::println → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.4.2