+ bcb.time = System.currentTimeMillis();
+ callbacks.add(bcb);
+ }
+
+ public static abstract class ByteCallback {
+ public int result;
+ public long time;
+ public abstract void call(byte b) throws Exception;
+ }
+
+ public synchronized int readCount() {
+ try {
+ ByteCallback bc = new ByteCallback() {
+ public synchronized void call(byte b) throws Exception {
+ result =
+ ((b & 0xff) << 24) |
+ ((in.read() & 0xff) << 16) |
+ ((in.read() & 0xff) << 8) |
+ ((in.read() & 0xff) << 0);
+ timer =
+ ((in.read() & 0xff) << 24) |
+ ((in.read() & 0xff) << 16) |
+ ((in.read() & 0xff) << 8) |
+ ((in.read() & 0xff) << 0);
+ //System.out.println("timer => " + Integer.toString(timer, 16));
+ this.notify();
+ }
+ };
+ synchronized(bc) {
+ enqueue(bc);
+ out.writeByte(3);
+ out.flush();
+ bc.wait();
+ }
+ return bc.result;
+ } catch (Exception e) { throw new RuntimeException(e); }