Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.pdfbox.cos;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.filter.Filter;
import org.apache.pdfbox.filter.FilterManager;
import org.apache.pdfbox.io.IOUtils;
import org.apache.pdfbox.io.RandomAccess;
import org.apache.pdfbox.io.RandomAccessBuffer;
import org.apache.pdfbox.io.RandomAccessFile;
import org.apache.pdfbox.io.RandomAccessFileInputStream;
import org.apache.pdfbox.io.RandomAccessFileOutputStream;
import org.apache.pdfbox.pdfparser.PDFStreamParser;
import org.apache.pdfbox.exceptions.COSVisitorException;
/**
* This class represents a stream object in a PDF document.
*
* @author Ben Litchfield
*
*/
public class COSStream extends COSDictionary implements Closeable
{
/**
* Log instance.
*/
private static final Log LOG = LogFactory.getLog(COSStream.class);
private static final int BUFFER_SIZE=16384;
private RandomAccess file;
/**
* The stream with all of the filters applied.
*/
private RandomAccessFileOutputStream filteredStream;
/**
* The stream with no filters, this contains the useful data.
*/
private RandomAccessFileOutputStream unFilteredStream;
private RandomAccess clone(RandomAccess file)
{
if (file == null)
{
return null;
}
else if (file instanceof RandomAccessFile)
{
return file;
}
else
{
return ((RandomAccessBuffer)file).clone();
}
}
/**
* Constructor. Creates a new stream with an empty dictionary.
*
* @param storage The intermediate storage for the stream.
*/
public COSStream( RandomAccess storage )
{
super();
file = clone(storage);
}
/**
* Constructor.
*
* @param dictionary The dictionary that is associated with this stream.
* @param storage The intermediate storage for the stream.
*/
public COSStream( COSDictionary dictionary, RandomAccess storage )
{
super( dictionary );
file = clone(storage);
}
/**
* This will replace this object with the data from the new object. This
* is used to easily maintain referential integrity when changing references
* to new objects.
*
* @param stream The stream that have the new values in it.
*
* @deprecated will be removed
*/
public void replaceWithStream( COSStream stream )
{
this.clear();
this.addAll( stream );
file = stream.file;
filteredStream = stream.filteredStream;
unFilteredStream = stream.unFilteredStream;
}
/**
* This will get the scratch file associated with this stream.
*
* @return The scratch file where this stream is being stored.
*
* @deprecated the direct access to the scratch file will be removed.
*/
public RandomAccess getScratchFile()
{
return file;
}
/**
* This will get all the tokens in the stream.
*
* @return All of the tokens in the stream.
*
* @throws IOException If there is an error parsing the stream.
*/
public List