Fields Summary |
---|
public static final String | ENCODINGKeeps encoding for messages. |
public static final byte | ERRORResponce code that identifies a failure. |
public static final byte | REGISTER_DEVICEDevice registration request code. |
public static final byte | REGISTEREDSuccessfull registration response. |
public static final byte | DONENotification that client does not require server any more. |
public static final byte | SPECIFIC_MESSAGECode for specific messages that are only recognized by specific
handlers at server side. |
public static final byte | REGISTER_SERVICECode for starting advertising service in the ether. |
public static final byte | UNREGISTER_SERVICECode for unregistering service. |
public static final byte | CONNECT_TO_SERVICERequest for service connection. |
public static final byte | SERVICE_ATRespond that provides service connection details. |
public static final byte | START_INQUIRYRequest for inquiry start. |
public static final byte | INQUIRY_COMPLETEDRespond on inquiry completion. |
public static final byte | UPDATE_DEVICE_STATECommand to update device state that includes discoverable mode and
device class. |
private byte | codeKeeps code value retrieved by last receive() invocation. |
private byte[] | bytesKeeps bytes retrieved by last receive() invocation. |
Methods Summary |
---|
public byte[] | getBytes()Provides bytes read by the last receive() invocation.
return bytes;
|
public byte | getCode()Provides code read by the last receive() invocation.
return code;
|
public int | getInt()Retrieves integer represented by bytes read by the last
receive() invocation. Throws IllegalArgument exception
if those bytes do not represent an integer.
if (bytes == null || bytes.length != 4) {
throw new EmulationException();
}
int res = 0;
for (int i = 3; i >= 0; i--) {
res = (res << 8) | (bytes[i] & 0xff);
}
return res;
|
public java.lang.String | getMessage()Provides message read by the last receive() invocation.
try {
return new String(bytes, 0, bytes.length, ENCODING);
} catch (UnsupportedEncodingException e) {
throw new EmulationException();
}
|
public void | receive(java.io.InputStream in)Receives a packet from input stream given saving retrieved data in
code and message .
code = -1;
bytes = null;
if (in == null) {
throw new IllegalArgumentException();
}
synchronized (in) {
code = (byte) in.read();
int length = in.read();
if (length == -1) {
throw new IOException();
}
bytes = new byte[length];
if (length != in.read(bytes)) {
throw new IOException();
}
}
|
public void | send(java.io.OutputStream out, byte code, java.lang.String message)Forms a packet with given code and message and sends it to given output
stream.
if (out == null) {
throw new IllegalArgumentException();
}
if (message == null) {
message = "";
}
byte[] messageBytes = message.getBytes(ENCODING);
sendBytes(out, code, messageBytes);
|
public void | sendBytes(java.io.OutputStream out, byte code, byte[] info)Forms a packet with given code and bytes to send and sends it to
given output stream.
if (info.length > Byte.MAX_VALUE) {
throw new IllegalArgumentException();
}
synchronized (out) {
out.write(code);
out.write((byte)info.length);
out.write(info);
out.flush();
}
|
public void | sendInt(java.io.OutputStream out, byte code, int value)Forms a packet with given code and bytes that represent given integer,
then sends it to given output stream.
byte[] intBytes = new byte[4];
for (int i = 0; i < 4; i++) {
intBytes[i] = (byte) (value & 0xff);
value >>= 8;
}
sendBytes(out, code, intBytes);
|