Class DefaultFileContent

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, FileContent

    public final class DefaultFileContent
    extends java.lang.Object
    implements FileContent
    The content of a file.
    • Field Detail

      • EMPTY_CERTIFICATE_ARRAY

        private static final java.security.cert.Certificate[] EMPTY_CERTIFICATE_ARRAY
      • attrs

        private java.util.Map<java.lang.String,​java.lang.Object> attrs
      • roAttrs

        private java.util.Map<java.lang.String,​java.lang.Object> roAttrs
      • resetAttributes

        private boolean resetAttributes
      • openStreams

        private int openStreams
        Counts open streams for this file.
    • Method Detail

      • streamOpened

        void streamOpened()
      • streamClosed

        void streamClosed()
      • getFile

        public FileObject getFile()
        Returns the file that this is the content of.
        Specified by:
        getFile in interface FileContent
        Returns:
        the FileObject.
      • 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.
        Since:
        2.0
      • getAttributes

        public java.util.Map<java.lang.String,​java.lang.Object> 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.
        Since:
        2.0
      • 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.
      • getInputStream

        public java.io.InputStream getInputStream​(int bufferSize)
                                           throws FileSystemException
        Returns an input stream for reading the content.
        Specified by:
        getInputStream in interface FileContent
        Parameters:
        bufferSize - The buffer size to use.
        Returns:
        The InputStream
        Throws:
        FileSystemException - if an error occurs.
        Since:
        2.4
      • 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.
      • getOutputStream

        public java.io.OutputStream getOutputStream​(int bufferSize)
                                             throws FileSystemException
        Returns an output stream for writing the content.
        Specified by:
        getOutputStream in interface FileContent
        Parameters:
        bufferSize - The buffer size to use.
        Returns:
        The OutputStream for the file.
        Throws:
        FileSystemException - if an error occurs.
        Since:
        2.4
      • getOutputStream

        public java.io.OutputStream getOutputStream​(boolean bAppend,
                                                    int bufferSize)
                                             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.
        bufferSize - The buffer size to use.
        Returns:
        The OutputStream for the file.
        Throws:
        FileSystemException - if an error occurs.
        Since:
        2.4
      • close

        public void close()
                   throws FileSystemException
        Closes all resources used by the content, including all streams, readers and writers.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface FileContent
        Throws:
        FileSystemException - if an error occurs.
      • endInput

        private void endInput​(java.io.InputStream instr)
        Handles the end of input stream.
      • endRandomAccess

        private void endRandomAccess​(RandomAccessContent rac)
        Handles the end of random access.
      • endOutput

        private void endOutput()
                        throws java.lang.Exception
        Handles the end of output stream.
        Throws:
        java.lang.Exception
      • isOpen

        public boolean isOpen()
        Checks 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()
        Checks if an input or output stream is open. This checks all threads.
        Returns:
        true if this is the case
      • write

        public long write​(FileContent fileContent)
                   throws java.io.IOException
        Writes this content to another FileContent.
        Specified by:
        write in interface FileContent
        Parameters:
        fileContent - The target FileContent.
        Returns:
        the total number of bytes written
        Throws:
        java.io.IOException - if an error occurs writing the content.
        Since:
        2.1
      • write

        public long write​(FileObject file)
                   throws java.io.IOException
        Writes this content to another FileObject.
        Specified by:
        write in interface FileContent
        Parameters:
        file - The target FileObject.
        Returns:
        the total number of bytes written
        Throws:
        java.io.IOException - if an error occurs writing the content.
        Since:
        2.1
      • write

        public long write​(java.io.OutputStream output)
                   throws java.io.IOException
        Writes this content to an OutputStream.
        Specified by:
        write in interface FileContent
        Parameters:
        output - The target OutputStream.
        Returns:
        the total number of bytes written
        Throws:
        java.io.IOException - if an error occurs writing the content.
        Since:
        2.1
      • write

        public long write​(java.io.OutputStream output,
                          int bufferSize)
                   throws java.io.IOException
        Writes this content to an OutputStream.
        Specified by:
        write in interface FileContent
        Parameters:
        output - The target OutputStream.
        bufferSize - The buffer size to write data chunks.
        Returns:
        the total number of bytes written
        Throws:
        java.io.IOException - if an error occurs writing the file.
        Since:
        2.1