public void encodeAndOwn(byte[] value, OutputStream outStream, Context context)
      throws IOException, CoderException {
    if (!context.isWholeStream) {
      VarInt.encode(value.length, outStream);
      outStream.write(value);
    } else {
      if (outStream instanceof ExposedByteArrayOutputStream) {
        ((ExposedByteArrayOutputStream) outStream).writeAndOwn(value);
      } else {
        outStream.write(value);
      }
    }
  }
@Test
  public void testEncodeAndOwn() throws Exception {
    for (byte[] value : TEST_VALUES) {
      byte[] encodedSlow = CoderUtils.encodeToByteArray(TEST_CODER, value);
      byte[] encodedFast = encodeToByteArrayAndOwn(TEST_CODER, value);
      assertThat(encodedSlow, equalTo(encodedFast));
    }
  }