Class MemByteHolder
java.lang.Object
org.apache.derby.impl.store.raw.data.MemByteHolder
- All Implemented Interfaces:
ByteHolder
A ByteHolder that stores all its bytes in memory.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) int
(package private) Vector
<byte[]> (package private) byte[]
(package private) int
(package private) int
(package private) int
(package private) int
(package private) int
(package private) boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
Return the number of bytes that can be read from this ByteHolder without blocking on an IO.void
clear()
Clear the bytes from the ByteHolder and place it in writing mode.Return a byte holder matching existing type and size of current ByteHolder, but don't bother to fill the bytes.private String
dumpBuf
(int bufVEleAt) Create a string representation of an internal buffer of bytes.protected boolean
Get the next buffer for reading bytes.protected void
Get the next buffer for writing bytes.protected void
Do sanity checking when getting the next write bufferprotected void
Initialize a buffer for writingint
Return the number of bytes that have been saved to this byte holder.int
read()
Read a byte from this ByteHolder.int
read
(byte[] b, int off, int len) Read up to 'len' bytes from this ByteHolder and store them in an array at offset 'off'.int
read
(byte[] b, int off, OutputStream out, int len) int
read
(OutputStream out, int len) Read from the ByteHolder.int
shift the remaining unread bytes to the beginning of the byte holderlong
skip
(long count) Skip over the specified number of bytes in a ByteHolder.void
Place a ByteHolder in reading mode.toString()
Produce a string describing the state of this ByteHolder.void
write
(byte[] data, int offset, int len) Write len bytes of data starting at 'offset' to this ByteHolder.void
write
(int b) Write a byte to this ByteHolder.long
write
(InputStream is, long count) Write up to count bytes from an input stream to this ByteHolder.boolean
Return true if this is in writing mode.
-
Field Details
-
bufSize
int bufSize -
writing
boolean writing -
bufV
Vector<byte[]> bufV -
curBufVEleAt
int curBufVEleAt -
curBuf
byte[] curBuf -
curBufPos
int curBufPos -
curBufDataBytes
int curBufDataBytes -
lastBufVEleAt
int lastBufVEleAt -
lastBufDataBytes
int lastBufDataBytes
-
-
Constructor Details
-
MemByteHolder
public MemByteHolder(int bufSize) Create a new MemByteHolder. Store bytes as a list of buffers of size 'bufSize'.
-
-
Method Details
-
write
Description copied from interface:ByteHolder
Write a byte to this ByteHolder.The ByteHolder must be in writing mode to call this.
- Specified by:
write
in interfaceByteHolder
- Throws:
IOException
- Thrown on error- See Also:
-
write
Description copied from interface:ByteHolder
Write len bytes of data starting at 'offset' to this ByteHolder.The ByteHolder must be in writing mode to call this.
- Specified by:
write
in interfaceByteHolder
- Throws:
IOException
- Thrown on error- See Also:
-
write
Description copied from interface:ByteHolder
Write up to count bytes from an input stream to this ByteHolder. This may write fewer bytes if it encounters an end of file on the input stream.- Specified by:
write
in interfaceByteHolder
- Returns:
- the number of bytes written.
- Throws:
IOException
- Thrown on error- See Also:
-
clear
Description copied from interface:ByteHolder
Clear the bytes from the ByteHolder and place it in writing mode. This may not free the memory the ByteHolder uses to store data.- Specified by:
clear
in interfaceByteHolder
- Throws:
IOException
- Thrown on error- See Also:
-
startReading
Description copied from interface:ByteHolder
Place a ByteHolder in reading mode. After this call, reads scan bytes sequentially in the order they were written to the ByteHolder starting from the first byte. When the ByteHolder is already in readmode this simply arranges for reads to start at the beginning of the sequence of saved bytes.- Specified by:
startReading
in interfaceByteHolder
- Throws:
IOException
- See Also:
-
read
Description copied from interface:ByteHolder
Read a byte from this ByteHolder.The ByteHolder must be in reading mode to call this.
- Specified by:
read
in interfaceByteHolder
- Returns:
- The byte or -1 if there are no bytes available.
- Throws:
IOException
- Thrown on error- See Also:
-
read
Description copied from interface:ByteHolder
Read up to 'len' bytes from this ByteHolder and store them in an array at offset 'off'.The ByteHolder must be in reading mode to call this.
- Specified by:
read
in interfaceByteHolder
- Returns:
- the number of bytes read or -1 if the this ByteHolder has no more bytes.
- Throws:
IOException
- Thrown on error- See Also:
-
read
Description copied from interface:ByteHolder
Read from the ByteHolder.Read up to 'len' bytes from this ByteHolder and write them to the OutputStream
The ByteHolder must be in reading mode to call this.
- Specified by:
read
in interfaceByteHolder
- Returns:
- the number of bytes read or -1 if the this ByteHolder has no more bytes.
- Throws:
IOException
- Thrown on error- See Also:
-
read
- Throws:
IOException
- Thrown on error- See Also:
-
shiftToFront
Description copied from interface:ByteHolder
shift the remaining unread bytes to the beginning of the byte holder- Specified by:
shiftToFront
in interfaceByteHolder
- Throws:
IOException
- Thrown on error- See Also:
-
available
public int available()Description copied from interface:ByteHolder
Return the number of bytes that can be read from this ByteHolder without blocking on an IO.- Specified by:
available
in interfaceByteHolder
- See Also:
-
numBytesSaved
public int numBytesSaved()Return the number of bytes that have been saved to this byte holder. This result is different from available() as it is unaffected by the current read position on the ByteHolder.- Specified by:
numBytesSaved
in interfaceByteHolder
- See Also:
-
skip
Description copied from interface:ByteHolder
Skip over the specified number of bytes in a ByteHolder.- Specified by:
skip
in interfaceByteHolder
- Throws:
IOException
- Thrown on error- See Also:
-
writingMode
public boolean writingMode()Description copied from interface:ByteHolder
Return true if this is in writing mode.- Specified by:
writingMode
in interfaceByteHolder
- See Also:
-
cloneEmpty
Description copied from interface:ByteHolder
Return a byte holder matching existing type and size of current ByteHolder, but don't bother to fill the bytes. Normal usage is expected to reset the holding stream to the beginning, so the copy of current state would be wasted.- Specified by:
cloneEmpty
in interfaceByteHolder
- Returns:
- An empty
ByteHolder
. - See Also:
-
getNextBuffer_w
Get the next buffer for writing bytes.- Throws:
IOException
- Thrown on error
-
getNextBuffer_w_Sanity
protected void getNextBuffer_w_Sanity()Do sanity checking when getting the next write buffer -
initBuffer_w
protected void initBuffer_w()Initialize a buffer for writing -
getNextBuffer_r
Get the next buffer for reading bytes.- Returns:
- true if the user has read all the bytes in this ByteHolder.
- Throws:
IOException
- Thrown on error
-
dumpBuf
Create a string representation of an internal buffer of bytes. This is useful during debugging. -
toString
Produce a string describing the state of this ByteHolder. This is mainly for debugging.
-