org.apache.commons.vfs.provider
Class DefaultFileContent

java.lang.Object
  extended by org.apache.commons.vfs.provider.DefaultFileContent
All Implemented Interfaces:
FileContent

public final class DefaultFileContent
extends java.lang.Object
implements FileContent

The content of a file.

Version:
$Revision: 804273 $ $Date: 2009-08-14 17:56:52 +0200 (Fr, 14. Aug 2009) $
Author:
Adam Murdoch

Constructor Summary
DefaultFileContent(AbstractFileObject file, FileContentInfoFactory fileContentInfoFactory)
           
 
Method Summary
 void close()
          Closes all resources used by the content, including all streams, readers and writers.
 java.lang.Object getAttribute(java.lang.String attrName)
          Gets the value of an attribute.
 java.lang.String[] getAttributeNames()
          Lists the attributes of this file.
 java.util.Map getAttributes()
          Returns a read-only map of this file's attributes.
 java.security.cert.Certificate[] getCertificates()
          Returns the certificates used to sign this file.
 FileContentInfo getContentInfo()
          get the content info.
 FileObject getFile()
          Returns the file that this is the content of.
 java.io.InputStream getInputStream()
          Returns an input stream for reading the content.
 long getLastModifiedTime()
          Returns the last-modified timestamp.
 java.io.OutputStream getOutputStream()
          Returns an output stream for writing the content.
 java.io.OutputStream getOutputStream(boolean bAppend)
          Returns an output stream for writing the content in append mode.
 RandomAccessContent getRandomAccessContent(RandomAccessMode mode)
          Returns an input/output stream to use to read and write the content of the file in an random manner.
 long getSize()
          Returns the size of the content (in bytes).
 boolean hasAttribute(java.lang.String attrName)
          Checks if an attribute exists.
 boolean isOpen()
          check if a input and/or output stream is open.
This checks only the scope of the current thread.
 boolean isOpenGlobal()
          check if a input and/or output stream is open.
This checks all threads.
 void removeAttribute(java.lang.String attrName)
          Removes an attribute.
 void resetAttributes()
          Used internally to flag situations where the file attributes should be reretrieved.
 void setAttribute(java.lang.String attrName, java.lang.Object value)
          Sets the value of an attribute.
 void setLastModifiedTime(long modTime)
          Sets the last-modified timestamp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultFileContent

public DefaultFileContent(AbstractFileObject file,
                          FileContentInfoFactory fileContentInfoFactory)
Method Detail

getFile

public FileObject getFile()
Returns the file that this is the content of.

Specified by:
getFile in interface FileContent
Returns:
the FileObject.

getSize

public long getSize()
             throws FileSystemException
Returns the size of the content (in bytes).

Specified by:
getSize in interface FileContent
Returns:
The size of the content (in bytes).
Throws:
FileSystemException - if an error occurs.

getLastModifiedTime

public long getLastModifiedTime()
                         throws FileSystemException
Returns the last-modified timestamp.

Specified by:
getLastModifiedTime in interface FileContent
Returns:
The last modified timestamp.
Throws:
FileSystemException - if an error occurs.

setLastModifiedTime

public void setLastModifiedTime(long modTime)
                         throws FileSystemException
Sets the last-modified timestamp.

Specified by:
setLastModifiedTime in interface FileContent
Parameters:
modTime - The last modified timestamp.
Throws:
FileSystemException - if an error occurs.

hasAttribute

public boolean hasAttribute(java.lang.String attrName)
                     throws FileSystemException
Checks if an attribute exists.

Specified by:
hasAttribute in interface FileContent
Parameters:
attrName - The name of the attribute to check.
Returns:
true if the attribute is associated with the file.
Throws:
FileSystemException - if an error occurs.

getAttributes

public java.util.Map getAttributes()
                            throws FileSystemException
Returns a read-only map of this file's attributes.

Specified by:
getAttributes in interface FileContent
Returns:
a Map of the file's attributes.
Throws:
FileSystemException - if an error occurs.

resetAttributes

public void resetAttributes()
Used internally to flag situations where the file attributes should be reretrieved.


getAttributeNames

public java.lang.String[] getAttributeNames()
                                     throws FileSystemException
Lists the attributes of this file.

Specified by:
getAttributeNames in interface FileContent
Returns:
An array of attribute names.
Throws:
FileSystemException - if an error occurs.

getAttribute

public java.lang.Object getAttribute(java.lang.String attrName)
                              throws FileSystemException
Gets the value of an attribute.

Specified by:
getAttribute in interface FileContent
Parameters:
attrName - The attribute name.
Returns:
The value of the attribute or null.
Throws:
FileSystemException - if an error occurs.

setAttribute

public void setAttribute(java.lang.String attrName,
                         java.lang.Object value)
                  throws FileSystemException
Sets the value of an attribute.

Specified by:
setAttribute in interface FileContent
Parameters:
attrName - The name of the attribute to add.
value - The value of the attribute.
Throws:
FileSystemException - if an error occurs.

removeAttribute

public void removeAttribute(java.lang.String attrName)
                     throws FileSystemException
Removes an attribute.

Specified by:
removeAttribute in interface FileContent
Parameters:
attrName - The name of the attribute to remove.
Throws:
FileSystemException - if an error occurs.

getCertificates

public java.security.cert.Certificate[] getCertificates()
                                                 throws FileSystemException
Returns the certificates used to sign this file.

Specified by:
getCertificates in interface FileContent
Returns:
An array of Certificates.
Throws:
FileSystemException - if an error occurs.

getInputStream

public java.io.InputStream getInputStream()
                                   throws FileSystemException
Returns an input stream for reading the content.

Specified by:
getInputStream in interface FileContent
Returns:
The InputStream
Throws:
FileSystemException - if an error occurs.

getRandomAccessContent

public RandomAccessContent getRandomAccessContent(RandomAccessMode mode)
                                           throws FileSystemException
Returns an input/output stream to use to read and write the content of the file in an random manner.

Specified by:
getRandomAccessContent in interface FileContent
Parameters:
mode - The RandomAccessMode.
Returns:
A RandomAccessContent object to access the file.
Throws:
FileSystemException - if an error occurs.

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws FileSystemException
Returns an output stream for writing the content.

Specified by:
getOutputStream in interface FileContent
Returns:
The OutputStream for the file.
Throws:
FileSystemException - if an error occurs.

getOutputStream

public java.io.OutputStream getOutputStream(boolean bAppend)
                                     throws FileSystemException
Returns an output stream for writing the content in append mode.

Specified by:
getOutputStream in interface FileContent
Parameters:
bAppend - true if the data written should be appended.
Returns:
The OutputStream for the file.
Throws:
FileSystemException - if an error occurs.

close

public void close()
           throws FileSystemException
Closes all resources used by the content, including all streams, readers and writers.

Specified by:
close in interface FileContent
Throws:
FileSystemException - if an error occurs.

isOpen

public boolean isOpen()
check if a input and/or output stream is open.
This checks only the scope of the current thread.

Specified by:
isOpen in interface FileContent
Returns:
true if this is the case

isOpenGlobal

public boolean isOpenGlobal()
check if a input and/or output stream is open.
This checks all threads.

Returns:
true if this is the case

getContentInfo

public FileContentInfo getContentInfo()
                               throws FileSystemException
get the content info. e.g. content-type, content-encoding

Specified by:
getContentInfo in interface FileContent
Returns:
The FileContentInfo.
Throws:
FileSystemException - if an error occurs.


Copyright © 2002-2011 Apache Software Foundation. All Rights Reserved.