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_buffer
private byte[]
compress_buf
private int
compress_length
private java.util.zip.Deflater
deflater
A Deflater and Inflater used to compress and uncompress the size of data fields put into the store.private static ByteLongObject
EMPTY_BYTE_LONG_OBJECT
A 0 size ByteLongObject object.private java.util.zip.Inflater
inflater
private boolean
is_null
Set to true if null.private short
type
The type of object.private boolean
use_compressed
If 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 int
available()
void
close()
private BigNumber
createBigNumber(byte[] buf, int scale, byte state)
Creates a BigNumber object used to store a numeric value in the database.void
mark(int readAheadLimit)
int
read()
int
read(byte[] b, int off, int len)
boolean
readBoolean()
byte
readByte()
char
readChar()
java.lang.String
readChars(int length)
Reads a string of chars from the input stream up to the given length and returns it as a String object.double
readDouble()
float
readFloat()
private java.lang.Object
readFromCellInput(CellInput din)
Reads an object from the given CellInput.void
readFully(byte[] b)
void
readFully(byte[] b, int off, int len)
int
readInt()
java.lang.String
readLine()
long
readLong()
(package private) java.lang.Object
readSerialization(CellInput din)
Reads input from the given CellInput object.short
readShort()
int
readUnsignedByte()
int
readUnsignedShort()
java.lang.String
readUTF()
(package private) void
setToSerialize(TObject cell)
Sets this up with a TObject to serialize.long
skip(long n)
int
skipBytes(int n)
(package private) int
skipSerialization(CellInput din)
Returns the number of bytes to skip on the stream to go past the next serialization.void
writeBoolean(boolean v)
void
writeByte(int v)
void
writeChar(int v)
void
writeChars(java.lang.String s)
void
writeInt(int v)
void
writeLong(long v)
(package private) void
writeSerialization(java.io.DataOutputStream out)
Writes the current serialized data buffer to the output stream.void
writeShort(int v)
private void
writeToBuffer(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.IOException
Writes 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:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.ByteArrayOutputStream
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws java.io.IOException
- Specified by:
readFully
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
skipBytes
public int skipBytes(int n) throws java.io.IOException
- Specified by:
skipBytes
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readBoolean
public boolean readBoolean() throws java.io.IOException
- Specified by:
readBoolean
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readByte
public byte readByte() throws java.io.IOException
- Specified by:
readByte
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUnsignedByte
public int readUnsignedByte() throws java.io.IOException
- Specified by:
readUnsignedByte
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readShort
public short readShort() throws java.io.IOException
- Specified by:
readShort
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUnsignedShort
public int readUnsignedShort() throws java.io.IOException
- Specified by:
readUnsignedShort
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readChar
public char readChar() throws java.io.IOException
- Specified by:
readChar
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readChars
public java.lang.String readChars(int length) throws java.io.IOException
Description copied from interface:CellInput
Reads 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:
readInt
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readLong
public long readLong() throws java.io.IOException
- Specified by:
readLong
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException
- Specified by:
readFloat
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException
- Specified by:
readDouble
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readLine
public java.lang.String readLine() throws java.io.IOException
- Specified by:
readLine
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
readUTF
public java.lang.String readUTF() throws java.io.IOException
- Specified by:
readUTF
in interfacejava.io.DataInput
- Throws:
java.io.IOException
-
-