Class TemporaryFiles

java.lang.Object
net.officefloor.server.http.stream.TemporaryFiles

public class TemporaryFiles extends Object
Provides means to manage temporary FileChannel content.
Author:
Daniel Sagenschneider
  • Constructor Details

    • TemporaryFiles

      public TemporaryFiles(String prefix) throws IOException
      Instantiate and creates the temporary files area.
      Parameters:
      prefix - Prefix for the temporary files area.
      Throws:
      IOException - If fails to setup temporary files.
  • Method Details

    • getDefault

      public static TemporaryFiles getDefault() throws IOException
      Obtains the default TemporaryFiles.
      Returns:
      Default TemporaryFiles.
      Throws:
      IOException - If fails to create the default TemporaryFiles.
    • createTempFile

      public FileChannel createTempFile(String name, InputStream contents) throws IOException
      Creates a FileChannel to the temporary file.
      Parameters:
      name - Name to aid identifying the temporary file on disk. May be null.
      contents - InputStream to contents for the temporary file.
      Returns:
      FileChannel to the temporary file.
      Throws:
      IOException - If fails to create temporary file.
    • createTempFile

      public FileChannel createTempFile(String name, byte[] contents, int offset, int length) throws IOException
      Creates a FileChannel to a temporary file.
      Parameters:
      name - Name to aid identifying the temporary file on disk. May be null.
      contents - Contents for the temporary file.
      offset - Offset into contents.
      length - Length from offset to write to file.
      Returns:
      FileChannel to the temporary file.
      Throws:
      IOException - If fails to create temporary file.
    • createTempFile

      public FileChannel createTempFile(String name, byte[] contents) throws IOException
      Creates a FileChannel to a temporary file.
      Parameters:
      name - Name to aid identifying the temporary file on disk. May be null.
      contents - Contents for the temporary file.
      Returns:
      FileChannel to the temporary file.
      Throws:
      IOException - If fails to create temporary file.
    • createTempFile

      public FileChannel createTempFile(String name, String contents, Charset charset) throws IOException
      Creates a FileChannel to the temporary file.
      Parameters:
      name - Name to aid identifying the temporary file on disk. May be null.
      contents - Contents for the temporary file.
      charset - Charset to write the contents. May be null to use default HTTP entity Charset.
      Returns:
      FileChannel to the temporary file.
      Throws:
      IOException - If fails to create temporary file.
    • createTempFile

      public FileChannel createTempFile(String name, String contents) throws IOException
      Creates a FileChannel to the temporary file using the default HTTP entity Charset.
      Parameters:
      name - Name to aid identifying the temporary file on disk. May be null.
      contents - Contents for the temporary file.
      Returns:
      FileChannel to the temporary file.
      Throws:
      IOException - If fails to create temporary file.