/** * Reads a a float from an input stream. * @param in the input stream * @return the float read from the input stream */ public static float readFloat(DataInput in) throws IOException { return Float.intBitsToFloat(readInt(in)); }
/** * Reads a a float from a buffer. * @param buf the buffer * @return the float read from the buffer */ public static float readFloat(ByteBuffer buf) { return Float.intBitsToFloat(readInt(buf)); }
@Override public void receive(Address sender, byte[] buf, int offset, int length) { int len=Bits.readInt(buf, offset); String msg=new String(buf, offset+Global.INT_SIZE, len); System.out.printf("-- %s\n", msg); }
public static float readFloat(byte[] buf, int offset) { return Float.intBitsToFloat(readInt(buf, offset)); }
@Override public void receive(Address sender, ByteBuffer buf) { byte[] buffer=buf.array(); int len=Bits.readInt(buffer, buf.arrayOffset()); String msg=new String(buffer, buf.arrayOffset()+Global.INT_SIZE, len); System.out.printf("-- %s\n", msg); }
public static <T extends Streamable> T[] read(Class<T> clazz, DataInput in) throws Exception { int size=Bits.readInt(in); if(size == 0) return null; T[] retval=(T[])Array.newInstance(clazz, size); for(int i=0; i < retval.length; i++) { retval[i]=clazz.newInstance(); retval[i].readFrom(in); } return retval; }
public void receive(Address sender, byte[] buf, int offset, int length) { if(receiver != null) { int len=Bits.readInt(buf, offset); receiver.receive(sender, buf, offset+ Global.INT_SIZE, len); } }
public void readFrom(DataInput in) throws Exception { super.readFrom(in); flags=Bits.readInt(in); }
/** * Reads a string from buf. The length is read first, followed by the chars. Each char is a single byte * @param buf the buffer * @return the string read from buf */ public static String readString(ByteBuffer buf) { if(buf.get() == 0) return null; int len=readInt(buf); if(buf.isDirect()) { byte[] bytes=new byte[len]; buf.get(bytes); return new String(bytes); } else { byte[] bytes=buf.array(); return new String(bytes, buf.arrayOffset() + buf.position(), len); } }
public void readFrom(DataInput in) throws Exception { type=in.readByte(); switch(type) { case DATA: seqno=Bits.readLong(in); conn_id=in.readShort(); first=in.readBoolean(); break; case ACK: seqno=Bits.readLong(in); conn_id=in.readShort(); timestamp=Bits.readInt(in); break; case SEND_FIRST_SEQNO: timestamp=Bits.readInt(in); break; case XMIT_REQ: break; case CLOSE: conn_id=in.readShort(); break; } } }
String method_name=Bits.readString(in); String filename=Bits.readString(in); int line_number=Bits.readInt(in); StackTraceElement trace=new StackTraceElement(class_name, method_name, filename, line_number); stack_trace[i]=trace;
case TYPE_DOUBLE: return (T)(Double)Bits.readDouble(buffer, offset); case TYPE_FLOAT: return (T)(Float)Bits.readFloat(buffer, offset); case TYPE_INT: return (T)(Integer)Bits.readInt(buffer, offset); case TYPE_LONG: return (T)(Long)Bits.readLong(buffer, offset); case TYPE_SHORT: return (T)(Short)Bits.readShort(buffer, offset);
@Override public void receive(Address sender, byte[] buf, int offset, int length) { int len=Bits.readInt(buf, offset); String msg=new String(buf, offset+Global.INT_SIZE, len); System.out.printf("-- %s\n", msg); }
@Override public void receive(Address sender, ByteBuffer buf) { byte[] buffer=buf.array(); int len=Bits.readInt(buffer, buf.arrayOffset()); String msg=new String(buffer, buf.arrayOffset()+Global.INT_SIZE, len); System.out.printf("-- %s\n", msg); }
public static <T extends Streamable> T[] read(Class<T> clazz, DataInput in) throws Exception { int size=Bits.readInt(in); if(size == 0) return null; T[] retval=(T[])Array.newInstance(clazz, size); for(int i=0; i < retval.length; i++) { retval[i]=clazz.newInstance(); retval[i].readFrom(in); } return retval; }
public void readFrom(DataInput in) throws Exception { super.readFrom(in); flags=Bits.readInt(in); }
public void receive(Address sender, byte[] buf, int offset, int length) { if(receiver != null) { int len=Bits.readInt(buf, offset); receiver.receive(sender, buf, offset+ Global.INT_SIZE, len); } }