com.alachisoft.ncache.serialization.standard.io.CompactWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-serialization Show documentation
Show all versions of nc-serialization Show documentation
Internal package of Alachisoft.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.alachisoft.ncache.serialization.standard.io;
import java.io.IOException;
import java.math.BigInteger;
/**
* @author taimoor_haider
*/
public class CompactWriter {
private ObjectOutputStream writer;
///
/// Constructs a compact writer over a object.
///
/// object
public CompactWriter(ObjectOutputStream output) {
writer = output;
}
///
/// Writes to the current stream and advances the stream position.
///
/// Object to write
public void WriteObject(Object graph) throws IOException {
writer.writeObject(graph);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(boolean value) throws IOException {
writer.writeBoolean(value);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(byte value) throws IOException {
writer.writeByte(value);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(char ch) throws IOException {
writer.writeChar(ch);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(short value) throws IOException {
writer.writeShort(value);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(int value) throws IOException, IOException, IOException, IOException {
writer.writeInt(value);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(long value) throws IOException {
writer.writeLong(value);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
//public void Write(decimal value) { writer.Write(value); }
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(float value) throws IOException {
writer.writeFloat(value);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(double value) throws IOException {
writer.writeDouble(value);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(byte[] buffer) throws IOException {
if (buffer != null)
writer.write(buffer, 0, buffer.length);
else
WriteObject(null);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(char[] chars) throws IOException {
if (chars != null) {
for (int i = 0; i < chars.length; i++) {
writer.writeChar(chars[i]);
}
} else {
WriteObject(null);
}
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(String value) throws IOException {
if (value != null) {
writer.writeUTF(value);
} else {
WriteObject(null);
}
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// buffer to write
/// starting position in the buffer
/// number of bytes to write
public void Write(byte[] buffer, int index, int count) throws IOException {
if (buffer != null) {
writer.write(buffer, index, count);
} else {
WriteObject(null);
}
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// buffer to write
/// starting position in the buffer
/// number of bytes to write
public void Write(char[] chars, int index, int count) throws IOException {
if (chars != null) {
for (int i = index; i < count; i++) {
writer.writeChar(chars[i]);
}
} else
WriteObject(null);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
//public void Write(sbyte value) { writer.Write(value); }
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void WriteUint16(int value) throws IOException {
writer.writeUInt16(value);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void WriteUint32(long value) throws IOException {
writer.writeUInt32(value);
}
///
/// Writes to the current stream and advances the stream position.
/// This method writes directly to the underlying stream.
///
/// Object to write
public void Write(BigInteger value) throws IOException {
writer.writeUInt64(value);
}
}