Package org.postgresql.largeobject
Class BlobOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.postgresql.largeobject.BlobOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
public class BlobOutputStream extends java.io.OutputStreamThis implements a basic output stream that writes to a LargeObject.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]bufBuffer.private intbufferPositionPosition within the buffer.(package private) static intDEFAULT_MAX_BUFFER_SIZEprivate LargeObjectloThe parent LargeObject.private ResourceLocklockprivate intmaxBufferSizeSize of the buffer (default 1K).
-
Constructor Summary
Constructors Constructor Description BlobOutputStream(LargeObject lo)Create an OutputStream to a large object.BlobOutputStream(LargeObject lo, int bufferSize)Create an OutputStream to a large object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private LargeObjectcheckClosed()voidclose()voidflush()Flushes this output stream and forces any buffered output bytes to be written out.private byte[]growBuffer(int extraBytes)Grows an internal buffer to ensure the extra bytes fit in the buffer.voidwrite(byte[] b, int off, int len)voidwrite(int b)
-
-
-
Field Detail
-
DEFAULT_MAX_BUFFER_SIZE
static final int DEFAULT_MAX_BUFFER_SIZE
- See Also:
- Constant Field Values
-
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 Detail
-
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- LargeObjectbufferSize- The size of the buffer for single-byte writes
-
-
Method Detail
-
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 java.io.IOException- Specified by:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
write
public void write(byte[] b, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.OutputStream- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOExceptionFlushes this output stream and forces any buffered output bytes to be written out. The general contract offlushis 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:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException- if an I/O error occurs.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException
-
checkClosed
private LargeObject checkClosed() throws java.io.IOException
- Throws:
java.io.IOException
-
-