Interface FileContent

  • All Known Implementing Classes:
    AbstractFileContent

    public interface FileContent
    Provides access to File content in a variety of ways.
    See Also:
    File
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      byte[] asBytes()
      Return the contents of the file as a new byte array.
      java.io.InputStream asInputStream()
      Return an InputStream that can be used to access file contents.
      java.io.OutputStream asOutputStream()
      Return an OutputStream that can be used to write file contents.
      java.io.OutputStream asOutputStream​(boolean append)  
      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.
    • Method Detail

      • asInputStream

        java.io.InputStream asInputStream()
        Return an InputStream that can be used to access file contents. This method can be called multiple times if required. The stream should be closed by the caller.
        Returns:
        The file contents InputStream
      • asReader

        java.io.Reader asReader()
        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.
        Returns:
        the file contents Reader
      • asString

        java.lang.String asString()
        Return the contents of the file as a String. This method should be used with caution if working with large files.
        Returns:
        the contents as a String
      • asBytes

        byte[] asBytes()
        Return the contents of the file as a new byte array. This method should be used with caution if working with large files.
        Returns:
        the contents as a new byte array.
      • copyTo

        void copyTo​(java.io.OutputStream outputStream)
        Copy the contents of the file to another stream, closing the stream when complete.
      • copyTo

        void copyTo​(java.io.Writer writer)
        Copy the contents of the file to another writer, closing the writer when complete.
      • asOutputStream

        java.io.OutputStream asOutputStream()
        Return an OutputStream that can be used to write file contents. The output stream should be closed by the caller. When possible, consider using the write(InputStream) method instead to ensure that streams are closed.
        Returns:
        The output stream
      • asOutputStream

        java.io.OutputStream asOutputStream​(boolean append)
        Parameters:
        append - if true, open the file OutputStream in append mode, otherwise as new file Return an OutputStream that can be used to write file contents. The output stream should be closed by the caller. When possible, consider using the write(InputStream) method instead to ensure that streams are closed.
        Returns:
        The output stream
      • asWriter

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

        java.io.Writer asWriter​(boolean append)
        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 write(Reader) method instead to ensure that streams are closed.
        Returns:
        The writer
      • write

        void write​(File file)
        Write the contents of the specified file to this file.
        Parameters:
        file - the file to copy.
      • write

        void write​(java.io.InputStream inputStream)
        Write the contents of the specified output stream to this file, closing the stream when complete.
        Parameters:
        inputStream - the input stream to write
      • write

        void write​(java.io.Reader reader)
        Write the contents of the specified reader to this file, closing the reader when complete.
        Parameters:
        reader - the reader to write
      • write

        void write​(java.lang.String string)
        Write the contents of the specified string to this file.
        Parameters:
        string - the string contents