public static TestSignable deserialize(byte[] bytes) throws IOException { DataInputBuffer db = new DataInputBuffer(); db.reset(bytes, bytes.length); int keyId = db.readInt(); byte b = db.readByte(); db.close(); return new TestSignable(keyId, b); }
@Override public Object bytesToObject(DataByteArray dataByteArray) throws IOException { byte[] bytes = dataByteArray.get(); // test leading 4 bytes encode run length of rest of data in.reset(bytes, bytes.length); int length = in.readInt(); if (length != bytes.length - 4) { throw new IOException(String.format( "Int value '%d' of leading four bytes does not match run length of data '%d'", length, bytes.length - 4)); } return new DataByteArray(bytes, 4, bytes.length); }
@Override public TMessageSet deserialize(byte[] payload) { DataInputBuffer inBuffer = new DataInputBuffer(); inBuffer.reset(payload, payload.length); try { String app = inBuffer.readUTF(); int numMessages = inBuffer.readInt(); byte compression = inBuffer.readByte(); long crc = inBuffer.readLong(); byte[] messages = new byte[inBuffer.readInt()]; inBuffer.read(messages); return new TMessageSet( app, numMessages, compression, crc, ByteBuffer.wrap(messages) ); } catch (Exception e) { throw new RuntimeException("Failed to de-serialize payload into TMessageSet: "+e.getMessage(), e); } finally { Closeables.closeQuietly(inBuffer); } }
i.getClass().getName(), className); int length = in.readInt(); assertEquals("The int[] written by ObjectWritable as a non-compact array " + "was not expected length", i.length, length);
public void testVersion() { ChunkBuilder cb = new ChunkBuilder(); cb.addRecord("foo".getBytes()); cb.addRecord("bar".getBytes()); cb.addRecord("baz".getBytes()); Chunk c = cb.getChunk(); DataOutputBuffer ob = new DataOutputBuffer(c.getSerializedSizeEstimate()); try { c.write(ob); DataInputBuffer ib = new DataInputBuffer(); ib.reset(ob.getData(), c.getSerializedSizeEstimate()); int version = ib.readInt(); ib.close(); assertEquals(version, ChunkImpl.PROTOCOL_VERSION); } catch (IOException e) { e.printStackTrace(); fail("Should nor raise any exception"); } }
i.getClass().getName(), className); int length = in.readInt(); assertEquals("The int[] written by ObjectWritable as a non-compact array " + "was not expected length", i.length, length);
i.getClass().getName(), className); int length = in.readInt(); assertEquals("The int[] written by ObjectWritable as a non-compact array " + "was not expected length", i.length, length);