Code example for ByteArrayOutputStream

Methods: toByteArray

0
    Assert.assertEquals(-1, comparator.compare(thingie1Bytes, 0, thingie1Bytes.length, thingie2Bytes, 0, thingie2Bytes.length));
  } 
 
  private byte[] getByteArrayBytes(SortableBytes thingie1) throws IOException
  { 
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(baos);
    thingie1.toBytesWritable().write(out);
    out.flush();
    return baos.toByteArray();
  } 
 
  private byte[] toBytes(String string)
  { 
    return string.getBytes(Charsets.UTF_8);
  } 
 
  private String fromBytes(byte[] bytes)
  { 
    return new String(bytes, Charsets.UTF_8);