Class VarlenaWrapper.Input.Stream
- java.lang.Object
-
- java.io.InputStream
-
- org.postgresql.pljava.internal.ByteBufferInputStream
-
- org.postgresql.pljava.internal.VarlenaWrapper.Input.Stream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,VarlenaWrapper
- Enclosing class:
- VarlenaWrapper.Input
public class VarlenaWrapper.Input.Stream extends ByteBufferInputStream implements VarlenaWrapper
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.postgresql.pljava.internal.VarlenaWrapper
VarlenaWrapper.Input, VarlenaWrapper.Output, VarlenaWrapper.Verifier
-
-
Field Summary
-
Fields inherited from class org.postgresql.pljava.internal.ByteBufferInputStream
m_lock, m_open
-
-
Constructor Summary
Constructors Constructor Description Stream()
-
Method Summary
Modifier and Type Method Description long
adopt(DualState.Key cookie)
Return the varlena address to native code and dissociate the varlena from Java.protected ByteBuffer
buffer()
Return theByteBuffer
being wrapped, or throw an exception if the memory windowed by the buffer should no longer be accessed.void
close()
protected void
pin()
Pin resources if necessary during a reading operation.String
toString(Object o)
Return a string describing this object in a way useful for debugging, prefixed with the name (abbreviated for comfort) of the class of the object passed in (the normal JavatoString()
method should passthis
).protected void
unpin()
Unpin resources if necessary after a reading operation.void
verify(VarlenaWrapper.Verifier v)
Apply aVerifier
to the input data.-
Methods inherited from class org.postgresql.pljava.internal.ByteBufferInputStream
available, mark, markSupported, read, read, reset, skip
-
Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
-
-
-
Method Detail
-
pin
protected void pin() throws IOException
Description copied from class:ByteBufferInputStream
Pin resources if necessary during a reading operation.This default implementation does nothing. A subclass should override it if (in addition to synchronizing on
m_lock
), some pinning of a resource is needed during access operations.- Overrides:
pin
in classByteBufferInputStream
- Throws:
IOException
-
unpin
protected void unpin()
Description copied from class:ByteBufferInputStream
Unpin resources if necessary after a reading operation.This default implementation does nothing.
- Overrides:
unpin
in classByteBufferInputStream
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classByteBufferInputStream
- Throws:
IOException
-
toString
public String toString(Object o)
Description copied from interface:VarlenaWrapper
Return a string describing this object in a way useful for debugging, prefixed with the name (abbreviated for comfort) of the class of the object passed in (the normal JavatoString()
method should passthis
).Subclasses or consumers are encouraged to call this method and append further details specific to the subclass or consumer. The convention should be that the recursion will stop at some class that will actually construct the abbreviated class name of
o
and use it to prefix the returned value.- Specified by:
toString
in interfaceVarlenaWrapper
- Parameters:
o
- An object whose class name (possibly abbreviated) should be used to prefix the returned string.- Returns:
- Description of this object.
-
verify
public void verify(VarlenaWrapper.Verifier v) throws SQLException
Apply aVerifier
to the input data.This should only be necessary if the input wrapper is being used directly as an output item, and needs verification that it conforms to the format of the target type.
The current position must be at the beginning of the stream. The verifier must leave it at the end to confirm the entire stream was examined. There should be no need to reset the position here, as the only anticipated use is during an
adopt
, and the native code will only care about the varlena's address.- Throws:
SQLException
-
buffer
protected ByteBuffer buffer() throws IOException
Description copied from class:ByteBufferInputStream
Return theByteBuffer
being wrapped, or throw an exception if the memory windowed by the buffer should no longer be accessed.The monitor on
ByteBufferInputStream.m_lock
is held when this method is called.This method also should throw an exception if
ByteBufferInputStream.m_open
is false. It is called everywhere that should happen, so it is the perfect place for the test, and allows the implementing class to use a customized message in the exception.All uses of the buffer in this class are preceded by
pin()
and followed byunpin()
(whose default implementations in this class do nothing). If a subclass overridespin
with a version that throws the appropriate exception in either case or both, it is then redundant and unnecessary forbuffer
to check the same conditions.- Specified by:
buffer
in classByteBufferInputStream
- Throws:
IOException
-
adopt
public long adopt(DualState.Key cookie) throws SQLException
Description copied from interface:VarlenaWrapper
Return the varlena address to native code and dissociate the varlena from Java.- Specified by:
adopt
in interfaceVarlenaWrapper
- Parameters:
cookie
- Capability held by native code.- Throws:
SQLException
-
-