Class ContentOutputStream

java.lang.Object
java.io.OutputStream
org.apache.commons.io.output.ThresholdingOutputStream
org.apache.commons.io.output.DeferredFileOutputStream
org.codelibs.curl.io.ContentOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ContentOutputStream extends org.apache.commons.io.output.DeferredFileOutputStream
ContentOutputStream is a custom output stream that extends DeferredFileOutputStream. It writes data to a temporary file once the data size exceeds a specified threshold.

This class ensures that the temporary file is deleted if it is not needed. It uses a logger to log warnings if there are issues deleting the temporary file.

Fields:

  • logger - Logger instance for logging warnings.
  • PREFIX - Prefix for the temporary file name.
  • SUFFIX - Suffix for the temporary file name.
  • done - Flag indicating whether the file has been retrieved.

Constructors:

  • ContentOutputStream(int threshold, File tmpDir) - Constructs a ContentOutputStream with a specified threshold and temporary directory.

Methods:

  • getFile() - Marks the file as retrieved and returns the file.
  • close() - Closes the stream and deletes the temporary file if it is not needed.
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.apache.commons.io.output.DeferredFileOutputStream

    org.apache.commons.io.output.DeferredFileOutputStream.Builder
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
    protected static final Logger
     
    protected static final String
     
    protected static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    ContentOutputStream(int threshold, File tmpDir)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
     

    Methods inherited from class org.apache.commons.io.output.DeferredFileOutputStream

    builder, getData, getPath, getStream, isInMemory, thresholdReached, toInputStream, writeTo

    Methods inherited from class org.apache.commons.io.output.ThresholdingOutputStream

    checkThreshold, flush, getByteCount, getOutputStream, getThreshold, isThresholdExceeded, resetByteCount, setByteCount, write, write, write

    Methods inherited from class java.io.OutputStream

    nullOutputStream

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ContentOutputStream

      public ContentOutputStream(int threshold, File tmpDir)
  • Method Details

    • getFile

      public File getFile()
      Overrides:
      getFile in class org.apache.commons.io.output.DeferredFileOutputStream
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class org.apache.commons.io.output.DeferredFileOutputStream
      Throws:
      IOException