org.faceless.pdf2
Class EmbeddedFile

java.lang.Object
  extended by org.faceless.pdf2.EmbeddedFile
All Implemented Interfaces:
Cloneable

public final class EmbeddedFile
extends Object

This class represents a file which may be embedded into a PDF document, either by using the AnnotationFile class or through the PDF.getEmbeddedFiles() map.

Since:
2.6

Constructor Summary
EmbeddedFile(File file)
          Create a new EmbeddedFile object to embed the specified file.
EmbeddedFile(InputStream in, String name)
          Set the content of this Embeddedfile to the specified InputStream.
EmbeddedFile(PDF pdf, String name)
          Set the content of this EmbeddedFile to the specified PDF.
 
Method Summary
 Date getCreationDate()
          Return the Creation Date of this file, or null if not specified.
 InputStream getData()
          Return the attached file as an InputStream, or null if the file is not attached and is referenced by name only.
 String getDescription()
          Return the description for this file as set by setDescription(java.lang.String), or null if not set.
 Date getModDate()
          Return the Last-modified Date of this file, or null if not specified.
 String getName()
          Return the Filename of the file
 int getSize()
          Return the size of the attached file, or -1 if not specified (note the file always has a size of course, but that size isn't always stored in the PDF.
 String getType()
          Return the MIME type of this file attachment if specified, or null if not specified.
 boolean isValid()
           Returns true if the file matches the stored checksum or if no checksum is specified.
 void setCreationDate(Date date)
          Set the Creation Date of this file.
 void setDescription(String desc)
          Set the optional description for this file.
 void setModDate(Date date)
          Set the Last-modified Date of this file.
 void setType(String mimetype)
          Set the MIME type for this file attachment.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EmbeddedFile

public EmbeddedFile(File file)
             throws IOException
Create a new EmbeddedFile object to embed the specified file.

Parameters:
file - the file to embed
Throws:
IOException

EmbeddedFile

public EmbeddedFile(InputStream in,
                    String name)
             throws IOException
Set the content of this Embeddedfile to the specified InputStream. The InputStream is read completely but not closed.

Parameters:
in - the InputStream to read from - must not be null
name - the filename - must not be null
Throws:
IOException

EmbeddedFile

public EmbeddedFile(PDF pdf,
                    String name)
             throws IOException
Set the content of this EmbeddedFile to the specified PDF. The PDF is rendered to a stream, and from there treated as an ordinary file. The MIME-type, creation and modification date are all set with this constructor.

Parameters:
pdf - the PDF to store as an embedded file.
name - the "filename" of the PDF to use when storing it internally.
Throws:
IOException
Since:
2.7.8
Method Detail

getName

public String getName()
Return the Filename of the file


setType

public void setType(String mimetype)
Set the MIME type for this file attachment. This is optional but recommended, as it is not set automatically.

Parameters:
mimetype - the MIME type of the file

getType

public String getType()
Return the MIME type of this file attachment if specified, or null if not specified.


setDescription

public void setDescription(String desc)
Set the optional description for this file.

Parameters:
desc - the description to use

getDescription

public String getDescription()
Return the description for this file as set by setDescription(java.lang.String), or null if not set.


setCreationDate

public void setCreationDate(Date date)
Set the Creation Date of this file. Java has no way to detemine the creation date of a file (many operating systems don't have this concept), so this attribute is not set automatically.

Parameters:
date - the Last-modified Date of this file

getCreationDate

public Date getCreationDate()
Return the Creation Date of this file, or null if not specified.


setModDate

public void setModDate(Date date)
Set the Last-modified Date of this file. When creating an EmbeddedFile from the EmbeddedFile(File) constructor, this value is initialised to the correct date.

Parameters:
date - the Last-modified Date of this file

getModDate

public Date getModDate()
Return the Last-modified Date of this file, or null if not specified.


getSize

public int getSize()
Return the size of the attached file, or -1 if not specified (note the file always has a size of course, but that size isn't always stored in the PDF. If this method returns -1 there is no way to determine the size of the file without reading it).


getData

public InputStream getData()
Return the attached file as an InputStream, or null if the file is not attached and is referenced by name only.


isValid

public boolean isValid()

Returns true if the file matches the stored checksum or if no checksum is specified. Note most files are stored compressed using the Flate algorithm, which is self-checksumming, so this method is a little redundant. However the MD5 checksum optionally stored with embedded files is much stronger, so we provide this method for completeness.

Note that if no checksum is stored this method returns true, so although a false definitely indicates a corrupt file, a true doesn't guarantee that it isn't corrupt.

As this method calls the getData() method internally, the InputStream returned from that method must not be open prior to this call, otherwise the checksum will almost certainly fail.


toString

public String toString()


Copyright © 2001-2013 Big Faceless Organization