Top Description Fields Constructors Methods
org.postgresql.largeobject

public Class BlobInputStream

extends InputStream
Class Inheritance
Imports
org.postgresql.jdbc.ResourceLock, org.postgresql.util.GT, org.checkerframework.checker.nullness.qual.Nullable, java.io.IOException, .InputStream, java.sql.SQLException

This is an implementation of an InputStream from a large object.

Field Summary

Modifier and TypeField and Description
private long
absolutePosition

The absolute position.

private @Nullable byte[]
buffer

Buffer used to improve performance.

private int
bufferPosition

Position within buffer.

pack-priv static final int
pack-priv static final int
private int
lastBufferSize

The amount of bytes to read on the next read.

private final long
limit

The limit.

private @Nullable LargeObject
lo

The parent LargeObject.

private final ResourceLock
private long
markPosition

The mark position.

private final int
maxBufferSize

The buffer size.

Constructor Summary

AccessConstructor and Description
public
BlobInputStream(LargeObject
LargeObject to read from
lo
)

public
BlobInputStream(LargeObject
LargeObject to read from
lo
,
int
buffer size
bsize
)

public
BlobInputStream(LargeObject
LargeObject to read from
lo
,
int
buffer size
bsize
,
long
max number of bytes to read
limit
)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

private LargeObject
private int

Returns:

next buffer size or maxBufferSize if the buffer should not be increased
getNextBufferSize
(int
estimated read request
len
)

Computes the next buffer size to use for reading data from the large object.

public void
mark(int
the maximum limit of bytes that can be read before the mark position becomes invalid.
readlimit
)

Overrides java.io.InputStream.mark.

Marks the current position in this input stream.

public boolean

Returns:

true if this true type supports the mark and reset method; false otherwise.
markSupported
()

Overrides java.io.InputStream.markSupported.

Tests if this input stream supports the mark and reset methods.

public int
read()

Implements abstract java.io.InputStream.read.

The minimum required to implement input stream.

public int
read(byte[]
the buffer into which the data is read.
dest
,
int
the start offset in array b at which the data is written.
off
,
int
the maximum number of bytes to read.
len
)

Overrides java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes.

public void
reset()

Overrides java.io.InputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.

Inherited from java.io.InputStream:
availablenullInputStreamreadreadAllBytesreadNBytesreadNBytesskipskipNBytestransferTo

Field Detail

absolutePositionback to summary
private long absolutePosition

The absolute position.

bufferback to summary
private @Nullable byte[] buffer

Buffer used to improve performance.

bufferPositionback to summary
private int bufferPosition

Position within buffer.

DEFAULT_MAX_BUFFER_SIZEback to summary
pack-priv static final int DEFAULT_MAX_BUFFER_SIZE
INITIAL_BUFFER_SIZEback to summary
pack-priv static final int INITIAL_BUFFER_SIZE
lastBufferSizeback to summary
private int lastBufferSize

The amount of bytes to read on the next read. Currently, we nullify buffer, so we can't use buffer.length.

limitback to summary
private final long limit

The limit.

loback to summary
private @Nullable LargeObject lo

The parent LargeObject.

lockback to summary
private final ResourceLock lock
markPositionback to summary
private long markPosition

The mark position.

maxBufferSizeback to summary
private final int maxBufferSize

The buffer size.

Constructor Detail

BlobInputStreamback to summary
public BlobInputStream(LargeObject lo)
Parameters
lo:LargeObject

LargeObject to read from

BlobInputStreamback to summary
public BlobInputStream(LargeObject lo, int bsize)
Parameters
lo:LargeObject

LargeObject to read from

bsize:int

buffer size

BlobInputStreamback to summary
public BlobInputStream(LargeObject lo, int bsize, long limit)
Parameters
lo:LargeObject

LargeObject to read from

bsize:int

buffer size

limit:long

max number of bytes to read

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.InputStream.close.

Implements java.io.Closeable.close.

Closes this input stream and releases any system resources associated with the stream.

The close method of InputStream does nothing.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
getLoback to summary
private LargeObject getLo() throws IOException
getNextBufferSizeback to summary
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:int

estimated read request

Returns:int

next buffer size or maxBufferSize if the buffer should not be increased

markback to summary
public void mark(int readlimit)

Overrides java.io.InputStream.mark.

Marks the current position in this input stream. A subsequent call to the reset 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 method markSupported returns true, the stream somehow remembers all the bytes read after the call to mark and stands ready to supply those same bytes again if and whenever the method reset is called. However, the stream is not required to remember any data at all if more than readlimit bytes are read from the stream before reset is called.

Marking a closed stream should not have any effect on the stream.

Parameters
readlimit:int

the maximum limit of bytes that can be read before the mark position becomes invalid.

Annotations
@Override
See Also
java.io.InputStream#reset()
markSupportedback to summary
public boolean markSupported()

Overrides java.io.InputStream.markSupported.

Tests if this input stream supports the mark and reset methods. The markSupported method of InputStream returns false.

Returns:boolean

true if this true type supports the mark and reset method; false otherwise.

Annotations
@Override
See Also
java.io.InputStream#mark(int), java.io.InputStream#reset()
readback to summary
public int read() throws IOException

Implements abstract java.io.InputStream.read.

The minimum required to implement input stream.

Returns:int

Doc from java.io.InputStream.read.

the next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.InputStream.read.

if an I/O error occurs.

readback to summary
public int read(byte[] dest, int off, int len) throws IOException

Overrides java.io.InputStream.read.

Doc from java.io.InputStream.read.

Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read. The number of bytes actually read is returned as an integer.

This method blocks until input data is available, end of file is detected, or an exception is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off-1] and elements b[off+len] through b[b.length-1] are unaffected.

Parameters
dest:byte[]

the buffer into which the data is read.

off:int

the start offset in array b at which the data is written.

len:int

the maximum number of bytes to read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
If the first byte cannot be read for any reason other than end of file, or if the input stream has been closed, or if some other I/O error occurs.
resetback to summary
public void reset() throws IOException

Overrides java.io.InputStream.reset.

Repositions this stream to the position at the time the mark method was last called on this input stream.

Note

If mark is not called we move to the beginning.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.InputStream.reset.

if this stream has not been marked or if the mark has been invalidated.

See Also
java.io.InputStream#mark(int), java.io.IOException