Code example for ByteArrayOutputStream

Methods: toByteArray

0
    public void testSerialization() throws IOException { 
        WeightedWritable<Text> a = new WeightedWritable<Text>(11, new Text("faunus"));
        assertEquals(a.get().toString(), "faunus");
        assertEquals(a.getWeight(), 11l);
 
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        a.write(new DataOutputStream(bytes));
        WeightedWritable<Text> a2 = new WeightedWritable<Text>(new DataInputStream(new ByteArrayInputStream(bytes.toByteArray())));
 
        assertEquals(a, a2);
        assertEquals(a2.get().toString(), "faunus");
        assertEquals(a2.getWeight(), 11l);
 
        assertEquals(a.compareTo(a2), 0);
    } 
} 
Stop searching for code, let great code find you!  Add Codota to your java IDE