public static <T extends Object> T objectFromStream(DataInput in, ClassLoader loader) throws Exception { if(in == null) return null; byte b=in.readByte(); return (T)tmp.readObject(); case TYPE_BOOLEAN: return (T)(Boolean)in.readBoolean(); case TYPE_BYTE: return (T)(Byte)in.readByte(); case TYPE_CHAR: return (T)(Character)in.readChar(); case TYPE_DOUBLE: return (T)(Double)in.readDouble(); case TYPE_FLOAT: return (T)(Float)in.readFloat(); case TYPE_INT: return (T)(Integer)in.readInt(); case TYPE_LONG: return (T)(Long)in.readLong(); case TYPE_SHORT: return (T)(Short)in.readShort(); case TYPE_STRING: int str_len=in.readInt(); if(str_len == 0) return (T)""; byte[] tmp=new byte[str_len]; for(int i=0; i < str_len; i++) { tmp[i]=in.readByte(); return (T)in.readUTF(); case TYPE_BYTEARRAY: int len=in.readInt(); byte[] tmpbuf=new byte[len]; in.readFully(tmpbuf,0,tmpbuf.length); return (T)tmpbuf; default:
protected ByteSequence looseUnmarshalByteSequence(DataInput dataIn) throws IOException { ByteSequence rc = null; if (dataIn.readBoolean()) { int size = dataIn.readInt(); byte[] t = new byte[size]; dataIn.readFully(t); rc = new ByteSequence(t, 0, size); } return rc; } }
protected byte[] looseUnmarshalByteArray(DataInput dataIn) throws IOException { byte rc[] = null; if (dataIn.readBoolean()) { int size = dataIn.readInt(); rc = new byte[size]; dataIn.readFully(rc); } return rc; }
protected ByteSequence tightUnmarshalByteSequence(DataInput dataIn, BooleanStream bs) throws IOException { ByteSequence rc = null; if (bs.readBoolean()) { int size = dataIn.readInt(); byte[] t = new byte[size]; dataIn.readFully(t); return new ByteSequence(t, 0, size); } return rc; }
protected byte[] tightUnmarshalByteArray(DataInput dataIn, BooleanStream bs) throws IOException { byte rc[] = null; if (bs.readBoolean()) { int size = dataIn.readInt(); rc = new byte[size]; dataIn.readFully(rc); } return rc; }
@SuppressWarnings("deprecation") protected String tightUnmarshalString(DataInput dataIn, BooleanStream bs) throws IOException { if (bs.readBoolean()) { if (bs.readBoolean()) { int size = dataIn.readShort(); byte data[] = new byte[size]; dataIn.readFully(data); // Yes deprecated, but we know what we are doing. // This allows us to create a String from a ASCII byte array. (no UTF-8 decoding) return new String(data, 0); } else { return dataIn.readUTF(); } } else { return null; } }
@Override public final void put(DataInput in, int offset, int length) throws IOException { if (address <= addressLimit) { if (heapMemory != null) { in.readFully(heapMemory, offset, length); } else { while (length >= 8) { putLongBigEndian(offset, in.readLong()); offset += 8; length -= 8; } while (length > 0) { put(offset, in.readByte()); offset++; length--; } } } else { throw new IllegalStateException("segment has been freed"); } }
public static List<Message> readMessageList(DataInput in, short transport_id) throws Exception { List<Message> list=new LinkedList<>(); Address dest=Util.readAddress(in); Address src=Util.readAddress(in); // AsciiString cluster_name=Bits.readAsciiString(in); // not used here short length=in.readShort(); byte[] cluster_name=length >= 0? new byte[length] : null; if(cluster_name != null) in.readFully(cluster_name, 0, cluster_name.length); int len=in.readInt(); for(int i=0; i < len; i++) { Message msg=new Message(false); msg.readFrom(in); msg.setDest(dest); if(msg.getSrc() == null) msg.setSrc(src); // Now add a TpHeader back on, was not marshalled. Every message references the *same* TpHeader, saving memory ! msg.putHeader(transport_id, new TpHeader(cluster_name)); list.add(msg); } return list; }
public void unmarshal(DataInput dataIn) throws IOException { arrayLimit = (short)(dataIn.readByte() & 0xFF); if (arrayLimit == 0xC0) { arrayLimit = (short)(dataIn.readByte() & 0xFF); } else if (arrayLimit == 0x80) { arrayLimit = dataIn.readShort(); } if (data.length < arrayLimit) { data = new byte[arrayLimit]; } dataIn.readFully(data, 0, arrayLimit); clear(); }
public void testSkipBytes() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); /* Write out various test values NORMALLY */ out.write(new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); // 10 bytes of junk to skip initializeData(out); byte[] data = baos.toByteArray(); DataInput in = new LittleEndianDataInputStream(new ByteArrayInputStream(data)); int bytesSkipped = 0; while (bytesSkipped < 10) { bytesSkipped += in.skipBytes(10 - bytesSkipped); } /* Read in various values in LITTLE ENDIAN FORMAT */ byte[] b = new byte[2]; in.readFully(b); assertEquals(-100, b[0]); assertEquals(100, b[1]); assertTrue(in.readBoolean()); assertFalse(in.readBoolean()); } }
@Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { this.managerPid = in.readInt(); this.managerStatus = in.readInt(); this.port = in.readInt(); byte len = in.readByte(); if (len > 0) { byte[] addr = new byte[len]; in.readFully(addr); this.bindAddress = InetAddress.getByAddress(addr); } } }
protected void readFrom(DataInput in, boolean read_type) throws Exception { if(read_type) type=GossipType.values()[in.readByte()]; group=Bits.readString(in); addr=Util.readAddress(in); sender=Util.readAddress(in); if(type != GossipType.MESSAGE) { logical_name=Bits.readString(in); short len=in.readShort(); if(len > 0) { ping_data=new ArrayList<>(len); for(int i=0; i < len; i++) { PingData data=new PingData(); data.readFrom(in); ping_data.add(data); } } physical_addr=(PhysicalAddress)Util.readAddress(in); } length=in.readInt(); if(length > 0) { buffer=new byte[length]; in.readFully(buffer, offset=0, length); } }
protected ByteSequence looseUnmarshalByteSequence(DataInput dataIn) throws IOException { ByteSequence rc = null; if (dataIn.readBoolean()) { int size = dataIn.readInt(); byte[] t = new byte[size]; dataIn.readFully(t); rc = new ByteSequence(t, 0, size); } return rc; } }
protected byte[] looseUnmarshalByteArray(DataInput dataIn) throws IOException { byte rc[] = null; if (dataIn.readBoolean()) { int size = dataIn.readInt(); rc = new byte[size]; dataIn.readFully(rc); } return rc; }
protected ByteSequence tightUnmarshalByteSequence(DataInput dataIn, BooleanStream bs) throws IOException { ByteSequence rc = null; if (bs.readBoolean()) { int size = dataIn.readInt(); byte[] t = new byte[size]; dataIn.readFully(t); return new ByteSequence(t, 0, size); } return rc; }
protected byte[] tightUnmarshalByteArray(DataInput dataIn, BooleanStream bs) throws IOException { byte rc[] = null; if (bs.readBoolean()) { int size = dataIn.readInt(); rc = new byte[size]; dataIn.readFully(rc); } return rc; }