1 31 package org.pdfbox.pdfparser; 32 33 import java.io.IOException ; 34 35 import java.util.ArrayList ; 36 import java.util.List ; 37 38 import org.pdfbox.cos.COSBase; 39 import org.pdfbox.cos.COSDocument; 40 import org.pdfbox.cos.COSInteger; 41 import org.pdfbox.cos.COSObject; 42 import org.pdfbox.cos.COSStream; 43 44 50 public class PDFObjectStreamParser extends BaseParser 51 { 52 private List streamObjects = null; 53 private List objectNumbers = null; 54 private COSStream stream; 55 56 64 public PDFObjectStreamParser( COSStream strm, COSDocument doc ) throws IOException 65 { 66 super( strm.getUnfilteredStream() ); 67 setDocument( doc ); 68 stream = strm; 69 } 70 71 77 public void parse() throws IOException 78 { 79 try 80 { 81 int numberOfObjects = stream.getInt( "N" ); 83 objectNumbers = new ArrayList ( numberOfObjects ); 84 streamObjects = new ArrayList ( numberOfObjects ); 85 for( int i=0; i<numberOfObjects; i++ ) 86 { 87 int objectNumber = readInt(); 88 int offset = readInt(); 89 objectNumbers.add( new Integer ( objectNumber ) ); 90 } 91 COSObject object = null; 92 COSBase cosObject = null; 93 int objectCounter = 0; 94 while( (cosObject = parseDirObject()) != null ) 95 { 96 object = new COSObject(cosObject); 97 object.setGenerationNumber( COSInteger.ZERO ); 98 COSInteger objNum = 99 new COSInteger( ((Integer )objectNumbers.get( objectCounter)).intValue() ); 100 object.setObjectNumber( objNum ); 101 streamObjects.add( object ); 102 objectCounter++; 103 } 104 } 105 finally 106 { 107 pdfSource.close(); 108 } 109 } 110 111 116 public List getObjects() 117 { 118 return streamObjects; 119 } 120 } | Popular Tags |