All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jpedal.io.types.Stream Maven / Gradle / Ivy

/*
 * ===========================================
 * Java Pdf Extraction Decoding Access Library
 * ===========================================
 *
 * Project Info:  http://www.idrsolutions.com
 * Help section for developers at http://www.idrsolutions.com/support/
 *
 * (C) Copyright 1997-2016 IDRsolutions and Contributors.
 *
 * This file is part of JPedal/JPDF2HTML5
 *
     This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


 *
 * ---------------
 * Stream.java
 * ---------------
 */
package org.jpedal.io.types;

import org.jpedal.constants.PDFflags;
import static org.jpedal.io.ObjectDecoder.debugFastCode;
import static org.jpedal.io.ObjectDecoder.padding;
import org.jpedal.io.PdfFileReader;
import org.jpedal.io.PdfFilteredReader;
import org.jpedal.io.security.DecryptionFactory;
import org.jpedal.objects.raw.PdfArrayIterator;
import org.jpedal.objects.raw.PdfDictionary;
import org.jpedal.objects.raw.PdfObject;

/**
 *
 */
public class Stream {

     
    public static void readStreamData(final PdfObject pdfObject, final int i, final byte[] raw, final int length, final PdfFileReader objectReader) {
        
        for(int xx=i;xx> >>
            if(raw[xx]=='>' && raw[xx+1]=='>') {
                break;
            }
            
            if(raw[xx] == 's' && raw[xx + 1] == 't' && raw[xx + 2] == 'r' &&
                    raw[xx + 3] == 'e' && raw[xx + 4] == 'a' &&
                    raw[xx + 5] == 'm'){
                
                if(debugFastCode) {
                    System.out.println(padding + "1. Stream found afterwards");
                }
                
                if(!pdfObject.isCached()) {
                    Stream.readStreamIntoObject(pdfObject, xx, raw, objectReader);
                }
                
                xx=length;
            }
        }
    }
    
    public static void readStreamIntoObject(final PdfObject pdfObject, final int j, final byte[] data, final PdfFileReader objectReader) {
        
        final DecryptionFactory decryption=objectReader.getDecryptionObject();
        
        final int count=data.length;
        
        if(debugFastCode) {
            System.out.println(padding + "Looking for stream");
        }
        
        byte[] stream=null;
        
        /*
         * see if JBIG encoded
         */
        final PdfArrayIterator maskFilters = pdfObject.getMixedArray(PdfDictionary.Filter);
        
        //get type as need different handling
        boolean isJBigEncoded =false;
        int firstMaskValue=PdfDictionary.Unknown;
        if(maskFilters!=null && maskFilters.hasMoreTokens()){
            
            firstMaskValue=maskFilters.getNextValueAsConstant(true);
            
            if(firstMaskValue==PdfFilteredReader.JBIG2Decode) {
                isJBigEncoded = true;
            }
            
            while(maskFilters.hasMoreTokens() && !isJBigEncoded){
                firstMaskValue=maskFilters.getNextValueAsConstant(true);
                if(firstMaskValue==PdfFilteredReader.JBIG2Decode) {
                    isJBigEncoded = true;
                }
            }
        }
        
        
        for(int a=j;a




© 2015 - 2024 Weber Informatics LLC | Privacy Policy