📄 pdstream.java
字号:
return stream;
}
/**
* This will get the length of the filtered/compressed stream. This is readonly in the
* PD Model and will be managed by this class.
*
* @return The length of the filtered stream.
*/
public int getLength()
{
return stream.getInt( "Length", 0 );
}
/**
* This will get the list of filters that are associated with this stream. Or
* null if there are none.
* @return A list of all encoding filters to apply to this stream.
*/
public List getFilters()
{
List retval = null;
COSBase filters = stream.getFilters();
if( filters instanceof COSName )
{
COSName name = (COSName)filters;
retval = new COSArrayList( name.getName(), name, stream, "Filter" );
}
else if( filters instanceof COSArray )
{
retval = COSArrayList.convertCOSNameCOSArrayToList( (COSArray)filters );
}
return retval;
}
/**
* This will set the filters that are part of this stream.
*
* @param filters The filters that are part of this stream.
*/
public void setFilters( List filters )
{
COSBase obj = COSArrayList.convertStringListToCOSNameCOSArray( filters );
stream.setItem( "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 getDecodeParams() throws IOException
{
List retval = null;
COSBase dp = stream.getDictionaryObject( "DecodeParms" );
if( dp == null )
{
//See PDF Ref 1.5 implementation note 7, the DP is sometimes used instead.
dp = stream.getDictionaryObject( "DP" );
}
if( dp instanceof COSDictionary )
{
Map map = COSDictionaryMap.convertBasicTypesToMap( (COSDictionary)dp );
retval = new COSArrayList(map, dp, stream, "DecodeParams" );
}
else if( dp instanceof COSArray )
{
COSArray array = (COSArray)dp;
List actuals = new ArrayList();
for( int i=0; i<array.size(); i++ )
{
actuals.add(
COSDictionaryMap.convertBasicTypesToMap(
(COSDictionary)array.getObject( i ) ) );
}
retval = new COSArrayList(actuals, array);
}
return retval;
}
/**
* This will set the list of decode params.
*
* @param decodeParams The list of decode params.
*/
public void setDecodeParams( List decodeParams )
{
stream.setItem(
"DecodeParams", COSArrayList.converterToCOSArray( decodeParams ) );
}
/**
* This will get the file specification for this stream. This is only
* required for external files.
*
* @return The file specification.
*
* @throws IOException If there is an error creating the file spec.
*/
public PDFileSpecification getFile() throws IOException
{
COSBase f = stream.getDictionaryObject( "F" );
PDFileSpecification retval = PDFileSpecification.createFS( f );
return retval;
}
/**
* Set the file specification.
* @param f The file specification.
*/
public void setFile( PDFileSpecification f )
{
stream.setItem( "F", f );
}
/**
* This will get the list of filters that are associated with this stream. Or
* null if there are none.
* @return A list of all encoding filters to apply to this stream.
*/
public List getFileFilters()
{
List retval = null;
COSBase filters = stream.getDictionaryObject( "FFilter" );
if( filters instanceof COSName )
{
COSName name = (COSName)filters;
retval = new COSArrayList( name.getName(), name, stream, "FFilter" );
}
else if( filters instanceof COSArray )
{
retval = COSArrayList.convertCOSNameCOSArrayToList( (COSArray)filters );
}
return retval;
}
/**
* This will set the filters that are part of this stream.
*
* @param filters The filters that are part of this stream.
*/
public void setFileFilters( List filters )
{
COSBase obj = COSArrayList.convertStringListToCOSNameCOSArray( filters );
stream.setItem( "FFilter", 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 getFileDecodeParams() throws IOException
{
List retval = null;
COSBase dp = stream.getDictionaryObject( "FDecodeParms" );
if( dp instanceof COSDictionary )
{
Map map = COSDictionaryMap.convertBasicTypesToMap( (COSDictionary)dp );
retval = new COSArrayList(map, dp, stream, "FDecodeParams" );
}
else if( dp instanceof COSArray )
{
COSArray array = (COSArray)dp;
List actuals = new ArrayList();
for( int i=0; i<array.size(); i++ )
{
actuals.add(
COSDictionaryMap.convertBasicTypesToMap(
(COSDictionary)array.getObject( i ) ) );
}
retval = new COSArrayList(actuals, array);
}
return retval;
}
/**
* This will set the list of decode params.
*
* @param decodeParams The list of decode params.
*/
public void setFileDecodeParams( List decodeParams )
{
stream.setItem(
"FDecodeParams", COSArrayList.converterToCOSArray( decodeParams ) );
}
/**
* This will copy the stream into a byte array.
*
* @return The byte array of the filteredStream
* @throws IOException When getFilteredStream did not work
*/
public byte[] getByteArray() throws IOException
{
ByteArrayOutputStream output = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
InputStream is = null;
try
{
is = createInputStream();
int amountRead = -1;
while( (amountRead = is.read( buf )) != -1)
{
output.write( buf, 0, amountRead );
}
}
finally
{
if( is != null )
{
is.close();
}
}
return output.toByteArray();
}
/**
* A convenience method to get this stream as a string. Uses
* the default system encoding.
*
* @return a String representation of this (input) stream, with the
* platform default encoding.
*
* @throws IOException if there is an error while converting the stream
* to a string.
*/
public String getInputStreamAsString() throws IOException
{
byte[] bStream = getByteArray();
return new String(bStream);
}
/**
* Get the metadata that is part of the document catalog. This will
* return null if there is no meta data for this object.
*
* @return The metadata for this object.
*/
public PDMetadata getMetadata()
{
PDMetadata retval = null;
COSStream mdStream = (COSStream)stream.getDictionaryObject( "Metadata" );
if( mdStream != null )
{
retval = new PDMetadata( mdStream );
}
return retval;
}
/**
* Set the metadata for this object. This can be null.
*
* @param meta The meta data for this object.
*/
public void setMetadata( PDMetadata meta )
{
stream.setItem( "Metadata", meta );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -