|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--waba.io.Stream | +--waba.io.DataStream
DataStream is a wrapper you can place around any Stream such as a SerialPort, Catalog, or BufferStream which lets you read and write standard Waba data types like ints, floats, and Strings in a simple manner. Here's an example
SerialPort port=new SerialPort(9600,0); DataStream ds=new DataStream(port); ds.writeString("Hello"); int status=ds.readUnsignedByte(); if (status==1) { ds.writeString("Pi"); ds.writeFloat(3.14); } port.close();
Field Summary | |
protected byte[] |
b
a four byte array for reading and writing numbers |
protected Stream |
stream
the underlying stream |
Constructor Summary | |
DataStream(Stream stream)
Constructs a new DataStream which sits upon the given stream using big endian notation for multibyte values. |
Method Summary | |
boolean |
close()
closes the stream |
int |
pad(int n)
pads the stream writting n bytes. all bytes will be 0. added by guich |
boolean |
readBoolean()
Reads a boolean from the stream as a byte. |
byte |
readByte()
Reads a single byte from the stream. |
int |
readBytes(byte[] buf,
int start,
int count)
Reads bytes from the stream. |
float |
readFloat()
Reads a float value from the stream as four bytes in IEEE 754 format. |
int |
readInt()
Reads an integer from the stream as four bytes. |
short |
readShort()
Reads a short from the stream as two bytes. |
java.lang.String |
readString()
reads an string. |
java.lang.String[] |
readStringArray()
reads an array of string. |
int |
readUnsignedByte()
Reads a single unsigned byte from the stream. |
int |
readUnsignedShort()
Reads an unsigned short from the stream as two bytes. |
void |
skip(int n)
Skips reading the next n bytes in the stream |
int |
writeBoolean(boolean bool)
Writes a boolean to the stream as a byte. |
int |
writeByte(byte by)
Writes a single byte to the stream. |
int |
writeByte(int by)
Writes a single byte to the stream. |
int |
writeBytes(byte[] buf,
int start,
int count)
Writes bytes to the the stream. |
int |
writeFloat(float f)
Writes a float value to the stream as four bytes in IEEE 754 format |
int |
writeInt(int i)
Writes an integer to the stream as four bytes. |
int |
writeShort(int i)
Writes an short to the stream as two bytes. |
int |
writeString(java.lang.String s)
writes the string into the stream |
int |
writeStringArray(java.lang.String[] v)
writes the string array into the stream |
Methods inherited from class java.lang.Object |
hashCode,
toString |
Field Detail |
protected Stream stream
protected byte[] b
Constructor Detail |
public DataStream(Stream stream)
stream
- the base streamMethod Detail |
public boolean close()
public int readInt()
public int writeInt(int i)
i
- the integer to writepublic short readShort()
public int writeShort(int i)
i
- the short to writepublic int readUnsignedShort()
public float readFloat()
public int writeFloat(float f)
f
- the float to writepublic boolean readBoolean()
public int writeBoolean(boolean bool)
b
- the boolean to writepublic byte readByte()
public int writeByte(byte by)
b
- the byte to writepublic int writeByte(int by)
b
- the byte to write (only least significant byte is written)public int readUnsignedByte()
public void skip(int n)
n
- the number of bytes to skippublic int readBytes(byte[] buf, int start, int count)
buf
- the byte array to read data intostart
- the start position in the arraycount
- the number of bytes to readpublic int writeBytes(byte[] buf, int start, int count)
buf
- the byte array to write data fromstart
- the start position in the byte arraycount
- the number of bytes to writepublic int pad(int n)
public java.lang.String readString()
public java.lang.String[] readStringArray()
public int writeStringArray(java.lang.String[] v)
public int writeString(java.lang.String s)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |