Package org.postgresql.largeobject
Class BlobOutputStream
java.lang.Object
java.io.OutputStream
org.postgresql.largeobject.BlobOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
This implements a basic output stream that writes to a LargeObject.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate byte[]
Buffer.private int
Position within the buffer.(package private) static final int
private LargeObject
The parent LargeObject.private final ResourceLock
private final int
Size of the buffer (default 1K). -
Constructor Summary
ConstructorsConstructorDescriptionCreate an OutputStream to a large object.BlobOutputStream
(LargeObject lo, int bufferSize) Create an OutputStream to a large object. -
Method Summary
Modifier and TypeMethodDescriptionprivate LargeObject
void
close()
void
flush()
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.void
write
(byte[] b, int off, int len) void
write
(int b) Methods inherited from class java.io.OutputStream
nullOutputStream, write
-
Field Details
-
DEFAULT_MAX_BUFFER_SIZE
static final int DEFAULT_MAX_BUFFER_SIZE- See Also:
-
lo
The parent LargeObject. -
lock
-
buf
private byte[] bufBuffer. -
maxBufferSize
private final int maxBufferSizeSize of the buffer (default 1K). -
bufferPosition
private int bufferPositionPosition within the buffer.
-
-
Constructor Details
-
BlobOutputStream
Create an OutputStream to a large object.- Parameters:
lo
- LargeObject
-
BlobOutputStream
Create an OutputStream to a large object.- Parameters:
lo
- LargeObjectbufferSize
- 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
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
Flushes this output stream and forces any buffered output bytes to be written out. The general contract offlush
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 interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
- if an I/O error occurs.
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
checkClosed
- Throws:
IOException
-