// // Verify that serialization followed by deserialization works properly // for a simple (but not completely trivial) map. // @Test public final void testSerialization0() throws IOException, ClassNotFoundException { ByteBuffer b00_01 = ByteBuffer.wrap("0".getBytes()); ByteBuffer b02_04 = ByteBuffer.wrap("23".getBytes()); ExtentBuffer eb00_01 = new ExtentBuffer(0L, b00_01); ExtentBuffer eb02_04 = new ExtentBuffer(2L, b02_04); ExtentBufferMap m00_04 = new ExtentBufferMap(); m00_04.put(eb00_01); m00_04.put(eb02_04); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(baos); out.writeObject(m00_04); out.flush(); baos.flush(); byte[] serialized = baos.toByteArray(); ByteArrayInputStream bais = new ByteArrayInputStream(serialized); ObjectInputStream in = new ObjectInputStream(bais); ExtentBufferMap n00_04 = (ExtentBufferMap) in.readObject(); out.close(); baos.close(); in.close(); bais.close(); // // Some spot checks: verify that: // - the map contains an extent buffer containing offset 3 // - the byte at that position has value '3' // ExtentBuffer fb02_04 = n00_04.getExtent(3L); assertNotNull("expect an extent including offset 3", fb02_04); int pos = fb02_04.offsetToPosition(3); assertEquals("expect correct contents at offset 3", fb02_04.get(pos), (byte) '3'); }