Class AbstractFileContent

  • All Implemented Interfaces:
    FileContent

    public abstract class AbstractFileContent
    extends java.lang.Object
    implements FileContent
    Abstract base class for FileContent.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] asBytes()
      Return the contents of the file as a new byte array.
      java.io.Reader asReader()
      Return a Reader that can be used to access file contents.
      java.lang.String asString()
      Return the contents of the file as a String.
      java.io.Writer asWriter()
      Return a Writer that can be used to write file contents.
      java.io.Writer asWriter​(boolean append)  
      void copyTo​(java.io.OutputStream outputStream)
      Copy the contents of the file to another stream, closing the stream when complete.
      void copyTo​(java.io.Writer writer)
      Copy the contents of the file to another writer, closing the writer when complete.
      void write​(File file)
      Write the contents of the specified file to this file.
      void write​(java.io.InputStream inputStream)
      Write the contents of the specified output stream to this file, closing the stream when complete.
      void write​(java.io.Reader reader)
      Write the contents of the specified reader to this file, closing the reader when complete.
      void write​(java.lang.String string)
      Write the contents of the specified string to this file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AbstractFileContent

        public AbstractFileContent()
    • Method Detail

      • asReader

        public java.io.Reader asReader()
        Description copied from interface: FileContent
        Return a Reader that can be used to access file contents. This method can be called multiple times if required. The reader should be closed by the caller.
        Specified by:
        asReader in interface FileContent
        Returns:
        the file contents Reader
      • asString

        public java.lang.String asString()
        Description copied from interface: FileContent
        Return the contents of the file as a String. This method should be used with caution if working with large files.
        Specified by:
        asString in interface FileContent
        Returns:
        the contents as a String
      • asBytes

        public byte[] asBytes()
        Description copied from interface: FileContent
        Return the contents of the file as a new byte array. This method should be used with caution if working with large files.
        Specified by:
        asBytes in interface FileContent
        Returns:
        the contents as a new byte array.
      • copyTo

        public void copyTo​(java.io.OutputStream outputStream)
        Description copied from interface: FileContent
        Copy the contents of the file to another stream, closing the stream when complete.
        Specified by:
        copyTo in interface FileContent
      • copyTo

        public void copyTo​(java.io.Writer writer)
        Description copied from interface: FileContent
        Copy the contents of the file to another writer, closing the writer when complete.
        Specified by:
        copyTo in interface FileContent
      • asWriter

        public java.io.Writer asWriter()
        Description copied from interface: FileContent
        Return a Writer that can be used to write file contents. The writer should be closed by the caller. When possible, consider using the FileContent.write(Reader) method instead to ensure that streams are closed.
        Specified by:
        asWriter in interface FileContent
        Returns:
        The writer
      • asWriter

        public java.io.Writer asWriter​(boolean append)
        Specified by:
        asWriter in interface FileContent
        Parameters:
        append - if true, open the file Writer in append mode, otherwise as new file Return a Writer that can be used to write file contents with append mode. The writer should be closed by the caller. When possible, consider using the FileContent.write(Reader) method instead to ensure that streams are closed.
        Returns:
        The writer
      • write

        public void write​(File file)
        Description copied from interface: FileContent
        Write the contents of the specified file to this file.
        Specified by:
        write in interface FileContent
        Parameters:
        file - the file to copy.
      • write

        public void write​(java.io.InputStream inputStream)
        Description copied from interface: FileContent
        Write the contents of the specified output stream to this file, closing the stream when complete.
        Specified by:
        write in interface FileContent
        Parameters:
        inputStream - the input stream to write
      • write

        public void write​(java.io.Reader reader)
        Description copied from interface: FileContent
        Write the contents of the specified reader to this file, closing the reader when complete.
        Specified by:
        write in interface FileContent
        Parameters:
        reader - the reader to write
      • write

        public void write​(java.lang.String string)
        Description copied from interface: FileContent
        Write the contents of the specified string to this file.
        Specified by:
        write in interface FileContent
        Parameters:
        string - the string contents