|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.iperg.part.core.IpIoStream
public class IpIoStream
The IpIoStream class can be used to create io streams
that support encoding and decoding of data to and from a byte
stream. The stream use an byte array to store encoded data.
The reason why we don't use a native Java io stream is that we need to control the way in which data is encoded since we can't assume that all PART processes are Java processes.
If a stream has been created via the empty constructor and data has been encoded via the
write
methods, the same stream can then be used to read the data using theread
methods. For example:
IpIoStream s = new IpIoStream();
s.writeInt(5);
s.writeString("hello");
// Now read the data encoded into the stream
int i = s.readInt();
String str = s.readString();
Note that it is not recomennded to mix several writes and reads. Ideally, all writes should be completed before the reads commence.
A stream that has been created using already encoded data can not be used to encode additional data. This will cause an
RuntimeException
to be thrown:IpIoStream s = new IpIoStream(data); s.writeInt(5); <= will throw an exception
| Constructor Summary | |
|---|---|
IpIoStream()
Create an empty io stream instance that can be used for encoding data. |
|
IpIoStream(byte[] data)
Create a io stream that can be used for decoding data and set its content to the given byte array. |
|
| Method Summary | |
|---|---|
int |
available()
Returns the number of bytes that can be read from this input stream. |
static int |
decodeInt(byte[] buf)
Convert an array of four bytes into an integer |
static void |
encodeInt(int val,
byte[] buf)
Convert an integer into an array of four bytes and write bytes into given buffer |
byte[] |
getEncodedData()
Get the stream "content" (encoded data) as an array of bytes |
boolean |
readBoolean()
Reads a boolean. |
byte |
readByte()
Reads a byte. |
byte[] |
readBytes()
Reads a byte array |
char |
readChar()
Reads a 16 bits char. |
double |
readDouble()
Reads a double. |
float |
readFloat()
Reads a float. |
int |
readInt()
Reads an int. |
long |
readLong()
Reads a long. |
java.lang.Object |
readObject()
Reads an object |
void |
readObject(java.lang.Object obj)
Read serialised object data into an existing object. |
short |
readShort()
Reads a short. |
java.lang.String |
readString()
Reads a string |
void |
writeBoolean(boolean b)
Writes a boolean. |
void |
writeByte(byte b)
Writes a byte. |
void |
writeBytes(byte[] data)
Writes a byte array |
void |
writeChar(char c)
Writes a 16 bits char. |
void |
writeDouble(double d)
Writes a double. |
void |
writeFloat(float f)
Writes a float. |
void |
writeInt(int i)
Writes an int. |
void |
writeLong(long l)
Writes a long. |
void |
writeObject(java.lang.Object obj)
Writes an object |
void |
writeShort(short s)
Writes a short. |
void |
writeString(java.lang.String s)
Writes a string |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public IpIoStream()
public IpIoStream(byte[] data)
data - The byte array that will be used as the content of
the stream| Method Detail |
|---|
public void writeByte(byte b)
writeByte in interface IpOutputStreamb - a byte;public void writeChar(char c)
writeChar in interface IpOutputStreamc - a char;public void writeBoolean(boolean b)
writeBoolean in interface IpOutputStreamb - a boolean;public void writeShort(short s)
writeShort in interface IpOutputStreams - a short;
public static void encodeInt(int val,
byte[] buf)
public static int decodeInt(byte[] buf)
public void writeInt(int i)
writeInt in interface IpOutputStreami - an int;public void writeLong(long l)
writeLong in interface IpOutputStreaml - a long;public void writeFloat(float f)
writeFloat in interface IpOutputStreamf - a float;public void writeDouble(double d)
writeDouble in interface IpOutputStreamd - a double;public void writeString(java.lang.String s)
writeString in interface IpOutputStreams - a string;public void writeBytes(byte[] data)
writeBytes in interface IpOutputStreamdata - The byte array
public void writeObject(java.lang.Object obj)
throws java.io.IOException
writeObject in interface IpOutputStreamobj - The object
java.io.IOException - if an io exception occurs while writing
the object to the streampublic byte[] getEncodedData()
public byte readByte()
readByte in interface IpInputStreampublic boolean readBoolean()
readBoolean in interface IpInputStreampublic char readChar()
readChar in interface IpInputStreampublic short readShort()
readShort in interface IpInputStreampublic int readInt()
readInt in interface IpInputStreampublic long readLong()
readLong in interface IpInputStreampublic float readFloat()
readFloat in interface IpInputStreampublic double readDouble()
readDouble in interface IpInputStreampublic java.lang.String readString()
readString in interface IpInputStreampublic byte[] readBytes()
readBytes in interface IpInputStream
public java.lang.Object readObject()
throws java.io.IOException
readObject in interface IpInputStreamjava.io.IOException
public void readObject(java.lang.Object obj)
throws java.io.IOException
obj - The object
java.io.IOExceptionpublic int available()
available in interface IpInputStream
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||