|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--waba.io.Stream
|
+--extra.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();
| Constructor Summary | |
DataStream(Stream stream)
Constructs a new DataStream which sits upon the given stream using big endian notation for multibyte values. |
|
DataStream(Stream stream,
boolean bigEndian)
Constructs a new DataStream which sits upon the given stream using the given endian notation for multibyte values. |
|
| Method Summary | |
boolean |
close()
Closes the stream. |
boolean |
isBigEndian()
Gets whether this DataStream is reading and writing numbers in big endian format, or little endian format. |
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. |
String |
readCString()
Reads a C-style string from the stream. |
String |
readFixedString(int length)
Reads a fixed length string 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. |
String |
readString()
Reads a string stored in a pascal type format. |
int |
readUnsignedByte()
Reads a single unsigned byte from the stream. |
int |
readUnsignedShort()
Reads an unsigned short from the stream as two bytes. |
void |
setBigEndian(boolean bigEndian)
Sets whether numbers should be read and written in big endian format (most significant byte first) or little endian format (least significant byte first). |
void |
skip(int n)
Skips reading the next n bytes in the stream |
static String |
toLowerCase(String s)
Converts all characters in a string to lower case. |
static String |
toUpperCase(String s)
Converts all characters in a string to upper case. |
void |
writeBoolean(boolean bool)
Writes a boolean to the stream as a byte. |
void |
writeByte(byte by)
Writes a single byte to the stream. |
void |
writeByte(int by)
Writes a single byte to the stream. |
int |
writeBytes(byte[] buf,
int start,
int count)
Writes bytes to the the stream. |
void |
writeCString(String s)
Writes a C-style string to the stream. |
void |
writeFixedString(String s,
int length)
Writes a fixed length string to the stream. |
void |
writeFixedString(String s,
int length,
char pad)
Writes a fixed length string to the stream. |
void |
writeFloat(float f)
Writes a float value to the stream as four bytes in IEEE 754 format |
void |
writeInt(int i)
Writes an integer to the stream as four bytes. |
void |
writeShort(int i)
Writes an short to the stream as two bytes. |
void |
writeString(String s)
Writes a string in a pascal type format. |
| Methods inherited from class java.lang.Object |
equals, hashCode, toString |
| Constructor Detail |
public DataStream(Stream stream)
stream - the base stream
public DataStream(Stream stream,
boolean bigEndian)
stream - the base streambigEndian - true for big endian, false for little endian| Method Detail |
public void setBigEndian(boolean bigEndian)
bigEndian - true for big endian, false for little endianpublic boolean isBigEndian()
public boolean close()
close in class Streampublic int readInt()
public void writeInt(int i)
i - the integer to writepublic short readShort()
public void writeShort(int i)
i - the short to writepublic int readUnsignedShort()
public float readFloat()
public void writeFloat(float f)
f - the float to writepublic String readString()
public void writeString(String s)
s - the string to writepublic String readCString()
public void writeCString(String s)
s - the string to writepublic String readFixedString(int length)
length - the number of characters to read
public void writeFixedString(String s,
int length)
s - the string to writelength - the length of the fixed string
public void writeFixedString(String s,
int length,
char pad)
s - the string to writelength - the length of the fixed stringthe - character to pad if the string is shorter than the lengthpublic boolean readBoolean()
public void writeBoolean(boolean bool)
b - the boolean to writepublic byte readByte()
public void writeByte(byte by)
b - the byte to writepublic void 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 skip
public int readBytes(byte[] buf,
int start,
int count)
readBytes in class Streambuf - the byte array to read data intostart - the start position in the arraycount - the number of bytes to read
public int writeBytes(byte[] buf,
int start,
int count)
writeBytes in class Streambuf - the byte array to write data fromstart - the start position in the byte arraycount - the number of bytes to writepublic static String toUpperCase(String s)
s - the string to convertpublic static String toLowerCase(String s)
s - the string to convert
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||