Package wt.util

Class TempFileOutputStream

java.lang.Object
java.io.OutputStream
wt.util.TempFileOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class TempFileOutputStream extends OutputStream
This class is designed to be used much like a ByteArrayOutputStream, the primary difference being that output is written to a temporary file as oppose to consuming memory with a byte array.

Note: The dispose method should be called to delete the temporary file and free all related resources when no longer needed.

Supported API: true
Extendable: false

  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a new TempFileOutputStream object.
    TempFileOutputStream(int buffer_size)
    Construct a new TempFileOutputStream object specifying the write buffer size.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Dispose of resources associated with this TempFileOutputStream.
    int
    Get the size of the temporary file.
    static void
    main(String[] args)
    Test driver (main)

    Supported API: true
    int
    Get the size of the temporary file.
    void
    write(byte[] b)
    Writes b.length bytes to this TempFileOutputStream.
    void
    write(byte[] b, int off, int len)
    Write data to this TempFileOutputStream.
    void
    write(int b)
    Write data to this TempFileOutputStream.
    void
    Write temp file data to some OutputStream.

    Methods inherited from class java.io.OutputStream

    close, flush, nullOutputStream

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TempFileOutputStream

      public TempFileOutputStream() throws IOException
      Construct a new TempFileOutputStream object.

      Supported API: true
      Throws:
      IOException - If unable to open the temporary file.
    • TempFileOutputStream

      public TempFileOutputStream(int buffer_size) throws IOException
      Construct a new TempFileOutputStream object specifying the write buffer size.

      Supported API: true
      Parameters:
      buffer_size -
      Throws:
      IOException - If unable to open the temporary file.
  • Method Details

    • size

      public int size()
      Get the size of the temporary file.

      Supported API: true
      Returns:
      the size of the temporary file
    • getLength

      public int getLength()
      Get the size of the temporary file.

      Supported API: true
      Returns:
      the size of the temporary file
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Write data to this TempFileOutputStream.

      Supported API: true
      Overrides:
      write in class OutputStream
      Parameters:
      b - a byte array of data to be written to temporary file
      off - offset into the byte array
      len - amout of data to be written
      Throws:
      IOException - if a write error occurs.
    • write

      public void write(int b) throws IOException
      Write data to this TempFileOutputStream.

      Supported API: true
      Specified by:
      write in class OutputStream
      Parameters:
      b - a byte array of data to be written to temporary file
      off - offset into the byte array
      len - amout of data to be written
      Throws:
      IOException - if a write error occurs.
    • write

      public void write(byte[] b) throws IOException
      Writes b.length bytes to this TempFileOutputStream.

      Supported API: true
      Overrides:
      write in class OutputStream
      Parameters:
      b - a byte array of data to be written to temporary file
      Throws:
      IOException - if a write error occurs.
    • writeTo

      public void writeTo(OutputStream os) throws IOException
      Write temp file data to some OutputStream.

      Supported API: true
      Parameters:
      os - OutputStream which is to recievie the temp files contents
      Throws:
      IOException - if a read or write error errors.
    • dispose

      public void dispose()
      Dispose of resources associated with this TempFileOutputStream. The temporary file is closed and deleted.

      Supported API: true
    • main

      public static void main(String[] args)
      Test driver (main)

      Supported API: true