"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/PDStream.java" between
pdfbox-2.0.23-src.zip and pdfbox-2.0.24-src.zip

About: Apache PDFBox is a Java PDF library tool that allows creation of new PDF documents, manipulation of existing documents and the ability to extract content from documents.

PDStream.java  (pdfbox-2.0.23-src):PDStream.java  (pdfbox-2.0.24-src)
skipping to change at line 27 skipping to change at line 27
package org.apache.pdfbox.pdmodel.common; package org.apache.pdfbox.pdmodel.common;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.pdfbox.cos.COSArray; import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase; import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary; import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.cos.COSDocument;
import org.apache.pdfbox.cos.COSInputStream; import org.apache.pdfbox.cos.COSInputStream;
import org.apache.pdfbox.cos.COSName; import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSNull; import org.apache.pdfbox.cos.COSNull;
import org.apache.pdfbox.cos.COSStream; import org.apache.pdfbox.cos.COSStream;
import org.apache.pdfbox.filter.DecodeOptions; import org.apache.pdfbox.filter.DecodeOptions;
import org.apache.pdfbox.filter.Filter; import org.apache.pdfbox.filter.Filter;
skipping to change at line 49 skipping to change at line 52
import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification; import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification;
/** /**
* A PDStream represents a stream in a PDF document. Streams are tied to a singl e PDF document. * A PDStream represents a stream in a PDF document. Streams are tied to a singl e PDF document.
* *
* @author Ben Litchfield * @author Ben Litchfield
*/ */
public class PDStream implements COSObjectable public class PDStream implements COSObjectable
{ {
private static final Log LOG = LogFactory.getLog(PDStream.class);
private final COSStream stream; private final COSStream stream;
/** /**
* Creates a new empty PDStream object. * Creates a new empty PDStream object.
* *
* @param document The document that the stream will be part of. * @param document The document that the stream will be part of.
*/ */
public PDStream(PDDocument document) public PDStream(PDDocument document)
{ {
stream = document.getDocument().createCOSStream(); stream = document.getDocument().createCOSStream();
skipping to change at line 141 skipping to change at line 146
stream = doc.getDocument().createCOSStream(); stream = doc.getDocument().createCOSStream();
output = stream.createOutputStream(filters); output = stream.createOutputStream(filters);
IOUtils.copy(input, output); IOUtils.copy(input, output);
} }
finally finally
{ {
if (output != null) if (output != null)
{ {
output.close(); output.close();
} }
if (input != null) input.close();
{
input.close();
}
} }
} }
/** /**
* If there are not compression filters on the current stream then this will * If there are not compression filters on the current stream then this will
* add a compression filter, flate compression for example. * add a compression filter, flate compression for example.
* *
* @deprecated This method is inefficient. To copying an existing InputStrea m, use * @deprecated This method is inefficient. To copying an existing InputStrea m, use
* {@link #PDStream(PDDocument, InputStream, COSName)} instead, with * {@link #PDStream(PDDocument, InputStream, COSName)} instead, with
* COSName.FLATE_DECODE as the final argument. * COSName.FLATE_DECODE as the final argument.
skipping to change at line 270 skipping to change at line 272
for (int i = 0; i < filters.size(); i++) for (int i = 0; i < filters.size(); i++)
{ {
COSName nextFilter = filters.get(i); COSName nextFilter = filters.get(i);
if ((stopFilters != null) && stopFilters.contains(nextFilter.get Name())) if ((stopFilters != null) && stopFilters.contains(nextFilter.get Name()))
{ {
break; break;
} }
else else
{ {
Filter filter = FilterFactory.INSTANCE.getFilter(nextFilter) ; Filter filter = FilterFactory.INSTANCE.getFilter(nextFilter) ;
filter.decode(is, os, stream, i); try
IOUtils.closeQuietly(is); {
filter.decode(is, os, stream, i);
}
finally
{
IOUtils.closeQuietly(is);
}
is = new ByteArrayInputStream(os.toByteArray()); is = new ByteArrayInputStream(os.toByteArray());
os.reset(); os.reset();
} }
} }
} }
return is; return is;
} }
/** /**
* Get the cos stream associated with this object. * Get the cos stream associated with this object.
skipping to change at line 346 skipping to change at line 354
/** /**
* Get the list of decode parameters. Each entry in the list will refer to * Get the list of decode parameters. Each entry in the list will refer to
* an entry in the filters list. * an entry in the filters list.
* *
* @return The list of decode parameters. * @return The list of decode parameters.
* @throws IOException if there is an error retrieving the parameters. * @throws IOException if there is an error retrieving the parameters.
*/ */
public List<Object> getDecodeParms() throws IOException public List<Object> getDecodeParms() throws IOException
{ {
List<Object> retval = null; // See PDF Ref 1.5 implementation note 7, the DP is sometimes used inste
ad.
return internalGetDecodeParams(COSName.DECODE_PARMS, COSName.DP);
}
COSBase dp = stream.getDictionaryObject(COSName.DECODE_PARMS); /**
if (dp == null) * Get the list of decode parameters. Each entry in the list will refer to
{ * an entry in the filters list.
// See PDF Ref 1.5 implementation note 7, the DP is sometimes used *
// instead. * @return The list of decode parameters.
dp = stream.getDictionaryObject(COSName.DP); * @throws IOException if there is an error retrieving the parameters.
} */
public List<Object> getFileDecodeParams() throws IOException
{
return internalGetDecodeParams(COSName.F_DECODE_PARMS, null);
}
private List<Object> internalGetDecodeParams(COSName name1, COSName name2) t
hrows IOException
{
COSBase dp = stream.getDictionaryObject(name1, name2);
if (dp instanceof COSDictionary) if (dp instanceof COSDictionary)
{ {
Map<?, ?> map = COSDictionaryMap Map<?, ?> map = COSDictionaryMap.convertBasicTypesToMap((COSDictiona
.convertBasicTypesToMap((COSDictionary) dp); ry) dp);
retval = new COSArrayList<Object>(map, dp, stream, return new COSArrayList<Object>(map, dp, stream, name1);
COSName.DECODE_PARMS);
} }
else if (dp instanceof COSArray)
if (dp instanceof COSArray)
{ {
COSArray array = (COSArray) dp; COSArray array = (COSArray) dp;
List<Object> actuals = new ArrayList<Object>(array.size()); List<Object> actuals = new ArrayList<Object>(array.size());
for (int i = 0; i < array.size(); i++) for (int i = 0; i < array.size(); i++)
{ {
actuals.add(COSDictionaryMap COSBase base = array.getObject(i);
.convertBasicTypesToMap((COSDictionary) array if (base instanceof COSDictionary)
.getObject(i))); {
actuals.add(COSDictionaryMap.convertBasicTypesToMap((COSDict
ionary) base));
}
else
{
LOG.warn("Expected COSDictionary, got " + base + ", ignored"
);
}
} }
retval = new COSArrayList<Object>(actuals, array); return new COSArrayList<Object>(actuals, array);
} }
return retval; return null;
} }
/** /**
* This will set the list of decode parameterss. * This will set the list of decode parameters.
* *
* @param decodeParams The list of decode parameterss. * @param decodeParams The list of decode parameters.
*/ */
public void setDecodeParms(List<?> decodeParams) public void setDecodeParms(List<?> decodeParams)
{ {
stream.setItem(COSName.DECODE_PARMS, stream.setItem(COSName.DECODE_PARMS,
COSArrayList.converterToCOSArray(decodeParams)); COSArrayList.converterToCOSArray(decodeParams));
} }
/** /**
* This will get the file specification for this stream. This is only * This will get the file specification for this stream. This is only
* required for external files. * required for external files.
skipping to change at line 448 skipping to change at line 471
* *
* @param filters The filters that are part of this stream. * @param filters The filters that are part of this stream.
*/ */
public void setFileFilters(List<String> filters) public void setFileFilters(List<String> filters)
{ {
COSBase obj = COSArrayList.convertStringListToCOSNameCOSArray(filters); COSBase obj = COSArrayList.convertStringListToCOSNameCOSArray(filters);
stream.setItem(COSName.F_FILTER, obj); stream.setItem(COSName.F_FILTER, obj);
} }
/** /**
* Get the list of decode parameters. Each entry in the list will refer to
* an entry in the filters list.
*
* @return The list of decode parameters.
* @throws IOException if there is an error retrieving the parameters.
*/
public List<Object> getFileDecodeParams() throws IOException
{
List<Object> retval = null;
COSBase dp = stream.getDictionaryObject(COSName.F_DECODE_PARMS);
if (dp instanceof COSDictionary)
{
Map<?, ?> map = COSDictionaryMap
.convertBasicTypesToMap((COSDictionary) dp);
retval = new COSArrayList<Object>(map, dp, stream,
COSName.F_DECODE_PARMS);
}
else if (dp instanceof COSArray)
{
COSArray array = (COSArray) dp;
List<Object> actuals = new ArrayList<Object>(array.size());
for (int i = 0; i < array.size(); i++)
{
actuals.add(COSDictionaryMap
.convertBasicTypesToMap((COSDictionary) array
.getObject(i)));
}
retval = new COSArrayList<Object>(actuals, array);
}
return retval;
}
/**
* This will set the list of decode params. * This will set the list of decode params.
* *
* @param decodeParams The list of decode params. * @param decodeParams The list of decode params.
*/ */
public void setFileDecodeParams(List<?> decodeParams) public void setFileDecodeParams(List<?> decodeParams)
{ {
stream.setItem("FDecodeParams", stream.setItem(COSName.F_DECODE_PARMS, COSArrayList.converterToCOSArray(
COSArrayList.converterToCOSArray(decodeParams)); decodeParams));
} }
/** /**
* This will copy the stream into a byte array. * This will copy the stream into a byte array.
* *
* @return The byte array of the filteredStream. * @return The byte array of the filteredStream.
* @throws IOException if an I/O error occurs. * @throws IOException if an I/O error occurs.
*/ */
public byte[] toByteArray() throws IOException public byte[] toByteArray() throws IOException
{ {
ByteArrayOutputStream output = new ByteArrayOutputStream();
InputStream is = null; InputStream is = null;
try try
{ {
is = createInputStream(); is = createInputStream();
IOUtils.copy(is, output); return IOUtils.toByteArray(is);
} }
finally finally
{ {
if (is != null) if (is != null)
{ {
is.close(); is.close();
} }
} }
return output.toByteArray();
} }
/** /**
* Get the metadata that is part of the document catalog. This will return * Get the metadata that is part of the document catalog. This will return
* null if there is no meta data for this object. * null if there is no meta data for this object.
* *
* @return The metadata for this object. * @return The metadata for this object.
* @throws IllegalStateException if the value of the metadata entry is diffe rent from a stream * @throws IllegalStateException if the value of the metadata entry is diffe rent from a stream
* or null * or null
*/ */
 End of changes. 18 change blocks. 
66 lines changed or deleted 57 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)