Package org.postgresql.largeobject
Class BlobInputStream
java.lang.Object
java.io.InputStream
org.postgresql.largeobject.BlobInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
This is an implementation of an InputStream from a large object.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate long
The absolute position.private byte[]
Buffer used to improve performance.private int
Position within buffer.(package private) static final int
(package private) static final int
private int
The amount of bytes to read on the next read.private final long
The limit.private LargeObject
The parent LargeObject.private final ResourceLock
private long
The mark position.private final int
The buffer size. -
Constructor Summary
ConstructorsConstructorDescriptionBlobInputStream
(LargeObject lo, int bsize) BlobInputStream
(LargeObject lo, int bsize, long limit) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this input stream and releases any system resources associated with the stream.private LargeObject
getLo()
private int
getNextBufferSize
(int len) Computes the next buffer size to use for reading data from the large object.void
mark
(int readlimit) Marks the current position in this input stream.boolean
Tests if this input stream supports themark
andreset
methods.int
read()
The minimum required to implement input stream.int
read
(byte[] dest, int off, int len) void
reset()
Repositions this stream to the position at the time themark
method was last called on this input stream.Methods inherited from class java.io.InputStream
available, nullInputStream, read, readAllBytes, readNBytes, readNBytes, skip, skipNBytes, transferTo
-
Field Details
-
DEFAULT_MAX_BUFFER_SIZE
static final int DEFAULT_MAX_BUFFER_SIZE- See Also:
-
INITIAL_BUFFER_SIZE
static final int INITIAL_BUFFER_SIZE- See Also:
-
lo
The parent LargeObject. -
lock
-
absolutePosition
private long absolutePositionThe absolute position. -
buffer
private byte[] bufferBuffer used to improve performance. -
bufferPosition
private int bufferPositionPosition within buffer. -
lastBufferSize
private int lastBufferSizeThe amount of bytes to read on the next read. Currently, we nullifybuffer
, so we can't usebuffer.length
. -
maxBufferSize
private final int maxBufferSizeThe buffer size. -
markPosition
private long markPositionThe mark position. -
limit
private final long limitThe limit.
-
-
Constructor Details
-
BlobInputStream
- Parameters:
lo
- LargeObject to read from
-
BlobInputStream
- Parameters:
lo
- LargeObject to read frombsize
- buffer size
-
BlobInputStream
- Parameters:
lo
- LargeObject to read frombsize
- buffer sizelimit
- max number of bytes to read
-
-
Method Details
-
read
The minimum required to implement input stream.- Specified by:
read
in classInputStream
- Throws:
IOException
-
getNextBufferSize
private int getNextBufferSize(int len) Computes the next buffer size to use for reading data from the large object. The idea is to avoid allocating too much memory, especially if the user will use just a few bytes of the data.- Parameters:
len
- estimated read request- Returns:
- next buffer size or
maxBufferSize
if the buffer should not be increased
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
close
Closes this input stream and releases any system resources associated with the stream.The
close
method ofInputStream
does nothing.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
- if an I/O error occurs.
-
mark
public void mark(int readlimit) Marks the current position in this input stream. A subsequent call to thereset
method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.The
readlimit
arguments tells this input stream to allow that many bytes to be read before the mark position gets invalidated.The general contract of
mark
is that, if the methodmarkSupported
returnstrue
, the stream somehow remembers all the bytes read after the call tomark
and stands ready to supply those same bytes again if and whenever the methodreset
is called. However, the stream is not required to remember any data at all if more thanreadlimit
bytes are read from the stream beforereset
is called.Marking a closed stream should not have any effect on the stream.
- Overrides:
mark
in classInputStream
- Parameters:
readlimit
- the maximum limit of bytes that can be read before the mark position becomes invalid.- See Also:
-
reset
Repositions this stream to the position at the time themark
method was last called on this input stream. NB: If mark is not called we move to the beginning.- Overrides:
reset
in classInputStream
- Throws:
IOException
- See Also:
-
markSupported
public boolean markSupported()Tests if this input stream supports themark
andreset
methods. ThemarkSupported
method ofInputStream
returnsfalse
.- Overrides:
markSupported
in classInputStream
- Returns:
true
if this true type supports the mark and reset method;false
otherwise.- See Also:
-
getLo
- Throws:
IOException
-