Class BlobOutputStream

java.lang.Object
java.io.OutputStream
org.postgresql.largeobject.BlobOutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class BlobOutputStream extends OutputStream
This implements a basic output stream that writes to a LargeObject.
  • Field Details

    • DEFAULT_MAX_BUFFER_SIZE

      static final int DEFAULT_MAX_BUFFER_SIZE
      See Also:
    • lo

      private LargeObject lo
      The parent LargeObject.
    • lock

      private final ResourceLock lock
    • buf

      private byte[] buf
      Buffer.
    • maxBufferSize

      private final int maxBufferSize
      Size of the buffer (default 1K).
    • bufferPosition

      private int bufferPosition
      Position within the buffer.
  • Constructor Details

    • BlobOutputStream

      public BlobOutputStream(LargeObject lo)
      Create an OutputStream to a large object.
      Parameters:
      lo - LargeObject
    • BlobOutputStream

      public BlobOutputStream(LargeObject lo, int bufferSize)
      Create an OutputStream to a large object.
      Parameters:
      lo - LargeObject
      bufferSize - The size of the buffer for single-byte writes
  • Method Details

    • growBuffer

      private byte[] growBuffer(int extraBytes)
      Grows an internal buffer to ensure the extra bytes fit in the buffer.
      Parameters:
      extraBytes - the number of extra bytes that should fit in the buffer
      Returns:
      new buffer
    • write

      public void write(int b) throws IOException
      Specified by:
      write in class OutputStream
      Throws:
      IOException
    • write

      public void write(byte[] b, int off, int len) throws IOException
      Overrides:
      write in class OutputStream
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.
      Specified by:
      flush in interface Flushable
      Overrides:
      flush in class OutputStream
      Throws:
      IOException - if an I/O error occurs.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class OutputStream
      Throws:
      IOException
    • checkClosed

      private LargeObject checkClosed() throws IOException
      Throws:
      IOException