|
|||||||||
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 SuperWaba 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 static byte[] |
bytes
|
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 |
boolean |
isOpen()
Returns true if this Stream is open and false otherwise |
int |
pad(int n)
pads the stream writting n bytes. all bytes will be 0. |
boolean |
readBoolean()
Reads a boolean from the stream as a byte. |
byte |
readByte()
Reads a single byte from the stream. |
int |
readBytes(byte[] buf)
Reads bytes from the stream. |
int |
readBytes(byte[] buf,
int start,
int count)
Reads bytes from the stream. |
char[] |
readChars()
Reads an array of chars, where its length is stored in the first two bytes as an unsigned short |
String |
readCString()
Reads a C-style string from the stream. |
double |
readDouble()
Reads a double. |
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. |
int |
readIntLE()
Reads an integer using little endian from the stream as four bytes. |
long |
readLong()
Reads a long. |
short |
readShort()
Reads a short from the stream as two bytes. |
short |
readShortLE()
Reads a short from the stream as two bytes in the little endian format. |
String |
readString()
reads a string, converting from palm to java format. |
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 (only forward!) |
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)
Writes bytes to the stream. |
int |
writeBytes(byte[] buf,
int start,
int count)
Writes bytes to the stream. |
int |
writeChars(char[] chars,
int start,
int len)
Writes an array of chars, placing its length in the first two bytes, as an unsigned short. |
int |
writeCString(String s)
Writes a C-style string to the stream. |
int |
writeDouble(double d)
writes a double. |
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 |
writeIntLE(int i)
Writes an integer to the stream as four bytes. |
int |
writeLong(long l)
writes a long. |
int |
writeShort(int i)
Writes an short to the stream as two bytes. |
int |
writeShortLE(int i)
Writes a short to the stream as two bytes. |
int |
writeString(String s)
writes the string into the stream, converting it from international format to palm format |
int |
writeStringArray(String[] v)
writes the string array into the stream |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
toString,
wait,
wait |
Field Detail |
protected Stream stream
protected byte[] b
protected static byte[] bytes
Constructor Detail |
public DataStream(Stream stream)
stream
- the base streamMethod Detail |
public boolean close()
public final int pad(int n)
public final void skip(int n)
n
- the number of bytes to skip, must be > 0public final boolean readBoolean()
public final byte readByte()
public final 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 final int readBytes(byte[] buf)
buf
- the byte array to read data intopublic final float readFloat()
public final int readIntLE()
public final short readShortLE()
public final int readInt()
public final short readShort()
public final double readDouble()
public final long readLong()
public final int readUnsignedByte()
public final int readUnsignedShort()
public final int writeIntLE(int i)
i
- the integer to writepublic final int writeShortLE(int i)
i
- the short to writepublic final int writeBoolean(boolean bool)
b
- the boolean to writepublic final int writeByte(byte by)
b
- the byte to writepublic final int writeByte(int by)
b
- the byte to write (only least significant byte is written)public final 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 final int writeBytes(byte[] buf)
buf
- the byte array to write data frompublic final int writeFloat(float f)
f
- the float to writepublic final int writeInt(int i)
i
- the integer to writepublic final int writeShort(int i)
i
- the short to writepublic final String readString()
public final String[] readStringArray()
public final int writeString(String s)
public final int writeStringArray(String[] v)
public final int writeDouble(double d)
public final int writeLong(long l)
public String readCString()
public final int writeCString(String s)
s
- the string to writepublic boolean isOpen()
public final char[] readChars()
public final int writeChars(char[] chars, int start, int len)
len
- the length to be written or -1 if it is to write the whole char arraychars
- the char array to be written.start
- the starting index (in most cases: 0).
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |