Package org.apache.jackrabbit.value
Class BinaryImpl
- java.lang.Object
-
- org.apache.jackrabbit.value.BinaryImpl
-
-
Constructor Summary
Constructors Constructor Description BinaryImpl(byte[] buffer)Creates a newBinaryImplinstance from abyte[]array.BinaryImpl(java.io.InputStream in)Creates a newBinaryImplinstance from anInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddispose()Releases all resources associated with thisBinaryobject and informs the repository that these resources may now be reclaimed.longgetSize()Returns the size of thisBinaryvalue in bytes.java.io.InputStreamgetStream()Returns anInputStreamrepresentation of this value.intread(byte[] b, long position)Reads successive bytes from the specifiedpositionin thisBinaryinto the passed byte array until either the byte array is full or the end of theBinaryis encountered.
-
-
-
Constructor Detail
-
BinaryImpl
public BinaryImpl(java.io.InputStream in) throws java.io.IOExceptionCreates a newBinaryImplinstance from anInputStream. The contents of the stream is spooled to a temporary file or to a byte buffer if its size is smaller thanMAX_BUFFER_SIZE.- Parameters:
in- stream to be represented as aBLOBFileValueinstance- Throws:
java.io.IOException- if an error occurs while reading from the stream or writing to the temporary file
-
BinaryImpl
public BinaryImpl(byte[] buffer)
Creates a newBinaryImplinstance from abyte[]array.- Parameters:
buffer- byte array to be represented as aBinaryImplinstance
-
-
Method Detail
-
getStream
public java.io.InputStream getStream() throws RepositoryExceptionReturns anInputStreamrepresentation of this value. Each call togetStream()returns a new stream. The API consumer is responsible for callingclose()on the returned stream.If
Binary.dispose()has been called on thisBinaryobject, then this method will throw the runtime exceptionIllegalStateException.- Specified by:
getStreamin interfaceBinary- Returns:
- A stream representation of this value.
- Throws:
RepositoryException- if an error occurs.
-
read
public int read(byte[] b, long position) throws java.io.IOException, RepositoryExceptionReads successive bytes from the specifiedpositionin thisBinaryinto the passed byte array until either the byte array is full or the end of theBinaryis encountered.If
Binary.dispose()has been called on thisBinaryobject, then this method will throw the runtime exceptionIllegalStateException.- Specified by:
readin interfaceBinary- Parameters:
b- the buffer into which the data is read.position- the position in this Binary from which to start reading bytes.- Returns:
- the number of bytes read into the buffer, or -1 if there is no more data because the end of the Binary has been reached.
- Throws:
java.io.IOException- if an I/O error occurs.RepositoryException- if another error occurs.
-
getSize
public long getSize() throws RepositoryExceptionReturns the size of thisBinaryvalue in bytes.If
Binary.dispose()has been called on thisBinaryobject, then this method will throw the runtime exceptionIllegalStateException.- Specified by:
getSizein interfaceBinary- Returns:
- the size of this value in bytes.
- Throws:
RepositoryException- if an error occurs.
-
-