Class MemByteHolder
- java.lang.Object
-
- org.apache.derby.impl.store.raw.data.MemByteHolder
-
- All Implemented Interfaces:
ByteHolder
public class MemByteHolder extends java.lang.Object implements ByteHolder
A ByteHolder that stores all its bytes in memory.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) intbufSize(package private) java.util.Vector<byte[]>bufV(package private) byte[]curBuf(package private) intcurBufDataBytes(package private) intcurBufPos(package private) intcurBufVEleAt(package private) intlastBufDataBytes(package private) intlastBufVEleAt(package private) booleanwriting
-
Constructor Summary
Constructors Constructor Description MemByteHolder(int bufSize)Create a new MemByteHolder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()Return the number of bytes that can be read from this ByteHolder without blocking on an IO.voidclear()Clear the bytes from the ByteHolder and place it in writing mode.ByteHoldercloneEmpty()Return a byte holder matching existing type and size of current ByteHolder, but don't bother to fill the bytes.private java.lang.StringdumpBuf(int bufVEleAt)Create a string representation of an internal buffer of bytes.protected booleangetNextBuffer_r()Get the next buffer for reading bytes.protected voidgetNextBuffer_w()Get the next buffer for writing bytes.protected voidgetNextBuffer_w_Sanity()Do sanity checking when getting the next write bufferprotected voidinitBuffer_w()Initialize a buffer for writingintnumBytesSaved()Return the number of bytes that have been saved to this byte holder.intread()Read a byte from this ByteHolder.intread(byte[] b, int off, int len)Read up to 'len' bytes from this ByteHolder and store them in an array at offset 'off'.intread(byte[] b, int off, java.io.OutputStream out, int len)intread(java.io.OutputStream out, int len)Read from the ByteHolder.intshiftToFront()shift the remaining unread bytes to the beginning of the byte holderlongskip(long count)Skip over the specified number of bytes in a ByteHolder.voidstartReading()Place a ByteHolder in reading mode.java.lang.StringtoString()Produce a string describing the state of this ByteHolder.voidwrite(byte[] data, int offset, int len)Write len bytes of data starting at 'offset' to this ByteHolder.voidwrite(int b)Write a byte to this ByteHolder.longwrite(java.io.InputStream is, long count)Write up to count bytes from an input stream to this ByteHolder.booleanwritingMode()Return true if this is in writing mode.
-
-
-
Method Detail
-
write
public void write(int b) throws java.io.IOExceptionDescription copied from interface:ByteHolderWrite a byte to this ByteHolder.The ByteHolder must be in writing mode to call this.
- Specified by:
writein interfaceByteHolder- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.write(int)
-
write
public void write(byte[] data, int offset, int len) throws java.io.IOExceptionDescription copied from interface:ByteHolderWrite len bytes of data starting at 'offset' to this ByteHolder.The ByteHolder must be in writing mode to call this.
- Specified by:
writein interfaceByteHolder- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.write(int)
-
write
public long write(java.io.InputStream is, long count) throws java.io.IOExceptionDescription copied from interface:ByteHolderWrite 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:
writein interfaceByteHolder- Returns:
- the number of bytes written.
- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.write(int)
-
clear
public void clear() throws java.io.IOExceptionDescription copied from interface:ByteHolderClear 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:
clearin interfaceByteHolder- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.clear()
-
startReading
public void startReading() throws java.io.IOExceptionDescription copied from interface:ByteHolderPlace 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:
startReadingin interfaceByteHolder- Throws:
java.io.IOException- See Also:
ByteHolder.startReading()
-
read
public int read() throws java.io.IOExceptionDescription copied from interface:ByteHolderRead a byte from this ByteHolder.The ByteHolder must be in reading mode to call this.
- Specified by:
readin interfaceByteHolder- Returns:
- The byte or -1 if there are no bytes available.
- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.read()
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionDescription copied from interface:ByteHolderRead 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:
readin interfaceByteHolder- Returns:
- the number of bytes read or -1 if the this ByteHolder has no more bytes.
- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.read()
-
read
public int read(java.io.OutputStream out, int len) throws java.io.IOExceptionDescription copied from interface:ByteHolderRead 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:
readin interfaceByteHolder- Returns:
- the number of bytes read or -1 if the this ByteHolder has no more bytes.
- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.read()
-
read
public int read(byte[] b, int off, java.io.OutputStream out, int len) throws java.io.IOException- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.read()
-
shiftToFront
public int shiftToFront() throws java.io.IOExceptionDescription copied from interface:ByteHoldershift the remaining unread bytes to the beginning of the byte holder- Specified by:
shiftToFrontin interfaceByteHolder- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.shiftToFront()
-
available
public int available()
Description copied from interface:ByteHolderReturn the number of bytes that can be read from this ByteHolder without blocking on an IO.- Specified by:
availablein interfaceByteHolder- See Also:
ByteHolder.available()
-
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:
numBytesSavedin interfaceByteHolder- See Also:
ByteHolder.numBytesSaved()
-
skip
public long skip(long count) throws java.io.IOExceptionDescription copied from interface:ByteHolderSkip over the specified number of bytes in a ByteHolder.- Specified by:
skipin interfaceByteHolder- Throws:
java.io.IOException- Thrown on error- See Also:
ByteHolder.skip(long)
-
writingMode
public boolean writingMode()
Description copied from interface:ByteHolderReturn true if this is in writing mode.- Specified by:
writingModein interfaceByteHolder- See Also:
ByteHolder.writingMode()
-
cloneEmpty
public ByteHolder cloneEmpty()
Description copied from interface:ByteHolderReturn 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:
cloneEmptyin interfaceByteHolder- Returns:
- An empty
ByteHolder. - See Also:
ByteHolder.cloneEmpty()
-
getNextBuffer_w
protected void getNextBuffer_w() throws java.io.IOExceptionGet the next buffer for writing bytes.- Throws:
java.io.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
protected boolean getNextBuffer_r() throws java.io.IOExceptionGet the next buffer for reading bytes.- Returns:
- true if the user has read all the bytes in this ByteHolder.
- Throws:
java.io.IOException- Thrown on error
-
dumpBuf
private java.lang.String dumpBuf(int bufVEleAt)
Create a string representation of an internal buffer of bytes. This is useful during debugging.
-
toString
public java.lang.String toString()
Produce a string describing the state of this ByteHolder. This is mainly for debugging.- Overrides:
toStringin classjava.lang.Object
-
-