Package com.mckoi.database
Class DataCellSerialization
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.ByteArrayOutputStream
-
- com.mckoi.database.DataCellSerialization
-
- All Implemented Interfaces:
CellInput,java.io.Closeable,java.io.DataInput,java.io.Flushable,java.lang.AutoCloseable
final class DataCellSerialization extends java.io.ByteArrayOutputStream implements CellInput
An object that manages the serialization and deserialization of objects to the database file system. This object maintains a buffer that stores intermediate serialization information as objects are written.
-
-
Field Summary
Fields Modifier and Type Field Description private char[]char_bufferprivate byte[]compress_bufprivate intcompress_lengthprivate java.util.zip.DeflaterdeflaterA Deflater and Inflater used to compress and uncompress the size of data fields put into the store.private static ByteLongObjectEMPTY_BYTE_LONG_OBJECTA 0 size ByteLongObject object.private java.util.zip.Inflaterinflaterprivate booleanis_nullSet to true if null.private shorttypeThe type of object.private booleanuse_compressedIf true, when writing out use the compressed form.
-
Constructor Summary
Constructors Constructor Description DataCellSerialization()Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()private BigNumbercreateBigNumber(byte[] buf, int scale, byte state)Creates a BigNumber object used to store a numeric value in the database.voidmark(int readAheadLimit)intread()intread(byte[] b, int off, int len)booleanreadBoolean()bytereadByte()charreadChar()java.lang.StringreadChars(int length)Reads a string of chars from the input stream up to the given length and returns it as a String object.doublereadDouble()floatreadFloat()private java.lang.ObjectreadFromCellInput(CellInput din)Reads an object from the given CellInput.voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)intreadInt()java.lang.StringreadLine()longreadLong()(package private) java.lang.ObjectreadSerialization(CellInput din)Reads input from the given CellInput object.shortreadShort()intreadUnsignedByte()intreadUnsignedShort()java.lang.StringreadUTF()(package private) voidsetToSerialize(TObject cell)Sets this up with a TObject to serialize.longskip(long n)intskipBytes(int n)(package private) intskipSerialization(CellInput din)Returns the number of bytes to skip on the stream to go past the next serialization.voidwriteBoolean(boolean v)voidwriteByte(int v)voidwriteChar(int v)voidwriteChars(java.lang.String s)voidwriteInt(int v)voidwriteLong(long v)(package private) voidwriteSerialization(java.io.DataOutputStream out)Writes the current serialized data buffer to the output stream.voidwriteShort(int v)private voidwriteToBuffer(TObject cell)Writes the TObject to the data buffer in this object.
-
-
-
Field Detail
-
deflater
private java.util.zip.Deflater deflater
A Deflater and Inflater used to compress and uncompress the size of data fields put into the store.
-
inflater
private java.util.zip.Inflater inflater
-
compress_buf
private byte[] compress_buf
-
compress_length
private int compress_length
-
use_compressed
private boolean use_compressed
If true, when writing out use the compressed form.
-
type
private short type
The type of object.
-
is_null
private boolean is_null
Set to true if null.
-
char_buffer
private char[] char_buffer
-
EMPTY_BYTE_LONG_OBJECT
private static final ByteLongObject EMPTY_BYTE_LONG_OBJECT
A 0 size ByteLongObject object.
-
-
Method Detail
-
skipSerialization
int skipSerialization(CellInput din) throws java.io.IOException
Returns the number of bytes to skip on the stream to go past the next serialization.- Throws:
java.io.IOException
-
readSerialization
java.lang.Object readSerialization(CellInput din) throws java.io.IOException
Reads input from the given CellInput object.- Throws:
java.io.IOException
-
createBigNumber
private BigNumber createBigNumber(byte[] buf, int scale, byte state)
Creates a BigNumber object used to store a numeric value in the database.
-
readFromCellInput
private java.lang.Object readFromCellInput(CellInput din) throws java.io.IOException
Reads an object from the given CellInput. No type information is included with the returned object so it must be wrapped in a TObject. Returns null if the object stored was null.- Throws:
java.io.IOException
-
writeSerialization
void writeSerialization(java.io.DataOutputStream out) throws java.io.IOExceptionWrites the current serialized data buffer to the output stream.- Throws:
java.io.IOException
-
setToSerialize
void setToSerialize(TObject cell) throws java.io.IOException
Sets this up with a TObject to serialize.- Throws:
java.io.IOException
-
writeToBuffer
private void writeToBuffer(TObject cell) throws java.io.IOException
Writes the TObject to the data buffer in this object.- Throws:
java.io.IOException
-
writeBoolean
public final void writeBoolean(boolean v) throws java.io.IOException- Throws:
java.io.IOException
-
writeByte
public final void writeByte(int v) throws java.io.IOException- Throws:
java.io.IOException
-
writeShort
public final void writeShort(int v) throws java.io.IOException- Throws:
java.io.IOException
-
writeChar
public final void writeChar(int v) throws java.io.IOException- Throws:
java.io.IOException
-
writeInt
public final void writeInt(int v) throws java.io.IOException- Throws:
java.io.IOException
-
writeLong
public final void writeLong(long v) throws java.io.IOException- Throws:
java.io.IOException
-
writeChars
public final void writeChars(java.lang.String s) throws java.io.IOException- Throws:
java.io.IOException
-
read
public int read() throws java.io.IOException- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException- Throws:
java.io.IOException
-
mark
public void mark(int readAheadLimit) throws java.io.IOException- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.ByteArrayOutputStream- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b) throws java.io.IOException- Specified by:
readFullyin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws java.io.IOException- Specified by:
readFullyin interfacejava.io.DataInput- Throws:
java.io.IOException
-
skipBytes
public int skipBytes(int n) throws java.io.IOException- Specified by:
skipBytesin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readBoolean
public boolean readBoolean() throws java.io.IOException- Specified by:
readBooleanin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readByte
public byte readByte() throws java.io.IOException- Specified by:
readBytein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOException- Specified by:
readUnsignedBytein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readShort
public short readShort() throws java.io.IOException- Specified by:
readShortin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUnsignedShort
public int readUnsignedShort() throws java.io.IOException- Specified by:
readUnsignedShortin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readChar
public char readChar() throws java.io.IOException- Specified by:
readCharin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readChars
public java.lang.String readChars(int length) throws java.io.IOExceptionDescription copied from interface:CellInputReads a string of chars from the input stream up to the given length and returns it as a String object.
-
readInt
public int readInt() throws java.io.IOException- Specified by:
readIntin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException- Specified by:
readLongin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException- Specified by:
readFloatin interfacejava.io.DataInput- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException- Specified by:
readDoublein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine() throws java.io.IOException- Specified by:
readLinein interfacejava.io.DataInput- Throws:
java.io.IOException
-
readUTF
public java.lang.String readUTF() throws java.io.IOException- Specified by:
readUTFin interfacejava.io.DataInput- Throws:
java.io.IOException
-
-