public static void testWriteAddress() throws Exception { Address a1 = Util.createRandomAddress(); Address a2 = Util.createRandomAddress(); Address a4 = Util.createRandomAddress(); ByteArrayOutputStream outstream = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(outstream); Util.writeAddress(a1, dos); Util.writeAddress(a2, dos); Util.writeAddress(a4, dos); dos.close(); byte[] buf = outstream.toByteArray(); ByteArrayInputStream instream = new ByteArrayInputStream(buf); DataInputStream dis = new DataInputStream(instream); Assert.assertEquals(a1, Util.readAddress(dis)); Assert.assertEquals(a2, Util.readAddress(dis)); Assert.assertEquals(a4, Util.readAddress(dis)); }
public static void testWriteNullAddress() throws Exception { Address a1 = null; ByteArrayOutputStream outstream = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(outstream); Util.writeAddress(a1, dos); dos.close(); byte[] buf = outstream.toByteArray(); ByteArrayInputStream instream = new ByteArrayInputStream(buf); DataInputStream dis = new DataInputStream(instream); assert Util.readAddress(dis) == null; }
public void readFrom(DataInput in) throws Exception { type = in.readByte(); boolean isMergeView = in.readBoolean(); if (isMergeView) view = (View) Util.readStreamable(MergeView.class, in); else view = (View) Util.readStreamable(View.class, in); mbr = Util.readAddress(in); mbrs = Util.readAddresses(in, ArrayList.class); join_rsp = (JoinRsp) Util.readStreamable(JoinRsp.class, in); my_digest = (Digest) Util.readStreamable(Digest.class, in); merge_id = (MergeId) Util.readStreamable(MergeId.class, in); merge_rejected = in.readBoolean(); useFlushIfPresent = in.readBoolean(); }
public void readFrom(DataInputStream in) throws IOException, IllegalAccessException, InstantiationException { // 1. read the leading byte first byte leading = in.readByte(); // 2. the flags flags = in.readByte(); // 3. dest_addr if (Util.isFlagSet(leading, DEST_SET)) dest_addr = Util.readAddress(in); // 4. src_addr if (Util.isFlagSet(leading, SRC_SET)) src_addr = Util.readAddress(in); // 5. buf if (Util.isFlagSet(leading, BUF_SET)) { int len = in.readInt(); buf = new byte[len]; in.readFully(buf, 0, len); length = len; } // 6. headers int len = in.readShort(); headers = createHeaders(len); short[] ids = headers.getRawIDs(); Header[] hdrs = headers.getRawHeaders(); for (int i = 0; i < len; i++) { short id = in.readShort(); Header hdr = readHeader(in); ids[i] = id; hdrs[i] = hdr; } }