com.alachisoft.ncache.serialization.standard.io.CompactReader 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;
/**
* @author taimoor_haider
*/
public class CompactReader {
//private SerializationContext context;
private ObjectInputStream reader;
///
/// Constructs a compact reader over a object.
///
/// object
public CompactReader(ObjectInputStream input) {
reader = input;
}
/// Returns the underlying object.
//internal BinaryReader BaseReader { get { return reader; } }
/// Returns the current object.
//internal SerializationContext Context { get { return context; } }
///
/// Reads an object of type from the current stream
/// and advances the stream position.
///
/// object read from the stream
public Object ReadObject() throws IOException, ClassNotFoundException {
return reader.readObject();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
///
public void SkipObject() throws IOException {
reader.skipObject();
}
/*
public object IfSkip(object readObjectValue, object defaultValue)
{
if (readObjectValue is SkipSerializationSurrogate)
return defaultValue;
else
return readObjectValue;
}
*/
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public boolean ReadBoolean() throws IOException {
return reader.readBoolean();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public byte ReadByte() throws IOException {
return reader.readByte();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// number of bytes read
/// object read from the stream
public byte[] ReadBytes(int count) throws IOException {
byte[] buffer = new byte[count];
reader.read(buffer, 0, count);
return buffer;
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public char ReadChar() throws IOException {
return reader.readChar();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public char[] ReadChars(int count) throws IOException {
char[] characters = new char[count];
for (int i = 0; i < count; i++) {
characters[i] = reader.readChar();
}
return characters;
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
//public decimal ReadDecimal() { return reader.readFloat(); }
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public float ReadSingle() throws IOException {
return reader.readFloat();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public double ReadDouble() throws IOException {
return reader.readDouble();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public short ReadInt16() throws IOException {
return reader.readShort();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public int ReadInt32() throws IOException {
return reader.readInt();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public long ReadInt64() throws IOException {
return reader.readLong();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public String ReadString() throws IOException {
return reader.readUTF();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
//public DateTime ReadDateTime() { return new DateTime(reader.ReadInt64()); }
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
//public override Guid ReadGuid() { return new Guid(reader.ReadBytes(16)); }
///
/// Reads the specifies number of bytes into .
/// This method reads directly from the underlying stream.
///
/// buffer to read into
/// starting position in the buffer
/// number of bytes to write
/// number of buffer read
public int Read(byte[] buffer, int index, int count) throws IOException {
return reader.read(buffer, index, count);
}
///
/// Reads the specifies number of bytes into .
/// This method reads directly from the underlying stream.
///
/// buffer to read into
/// starting position in the buffer
/// number of bytes to write
/// number of chars read
public int Read(char[] buffer, int index, int count) throws IOException {
for (int i = index; i < count; i++) {
buffer[index] = reader.readChar();
}
return count;
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
//public sbyte ReadSByte() { return reader.ReadSByte(); }
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public int ReadUInt16() throws IOException {
return reader.readUInt16();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
public long ReadUInt32() throws IOException {
return reader.readUInt32();
}
///
/// Reads an object of type from the current stream
/// and advances the stream position.
/// This method reads directly from the underlying stream.
///
/// object read from the stream
//public override ulong ReadUInt64() { return reader.ReadUInt64(); }
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipBoolean() throws IOException {
reader.skipBoolean();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipByte() throws IOException {
reader.skipByte();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
/// number of bytes read
public void SkipBytes(int count) throws IOException {
reader.skipBytes(count);
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipChar() throws IOException {
reader.skipChar();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipChars(int count) throws IOException {
for (int i = 0; i < count; i++)
reader.skipChar();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
//public override void SkipDecimal()
//{
// reader.BaseStream.Position = reader.BaseStream.Position + 16;
//}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipSingle() throws IOException {
reader.skipFloat();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipDouble() throws IOException {
reader.skipDouble();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipInt16() throws IOException {
reader.skipShort();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipInt32() throws IOException {
reader.skipInt();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipInt64() throws IOException {
reader.skipLong();
}
/*
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
//public void SkipString()
// {
//Reads String but does not assign value in effect behaves as a string
//Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time.
// reader.ski();
//}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public override void SkipDateTime()
{
this.SkipInt64();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public override void SkipGuid()
{
reader.BaseStream.Position = reader.BaseStream.Position + 16;
}
*/
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipSByte() throws IOException {
reader.skipByte();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipUInt16() throws IOException {
reader.skipUInt16();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipUInt32() throws IOException {
reader.skipUInt32();
}
///
/// Skips an object of type from the current stream
/// and advances the stream position.
/// This method Skips directly from the underlying stream.
///
public void SkipUInt64() throws IOException {
reader.skipLong();
}
}