@Test public void testReadBytes() throws Exception { InputStream in = new ByteArrayInputStream(new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0xff, (byte) 0x00, (byte) 0x00 }); Decoder decoder = new MemcmpDecoder(in); ByteBuffer bytes = decoder.readBytes(null); assertArrayEquals(new byte[] { (byte) 0x01, (byte) 0x00, (byte) 0xff }, bytes.array()); }
@Override public ByteBuffer readBytes(ByteBuffer old) throws IOException { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); while (true) { int byteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (byteRead == 0) { int secondByteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (secondByteRead == 0) { break; } else if (secondByteRead == 1) { bytesOut.write(0); } else { String msg = "Illegal encoding. 0 byte cannot be followed by " + "anything other than 0 or 1. It was followed by " + Integer.toString(byteRead); throw new IOException(msg); } } else { bytesOut.write(byteRead); } } return ByteBuffer.wrap(bytesOut.toByteArray()); }
MemcmpDecoder extends Decoder { @Override public ByteBuffer readBytes(ByteBuffer old) throws IOException { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); while (true) { int byteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (byteRead == 0) { int secondByteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (secondByteRead == 0) { break; } else if (secondByteRead == 1) { bytesOut.write(0); } else { String msg = "Illegal encoding. 0 byte cannot be followed by " + "anything other than 0 or 1. It was followed by " + Integer.toString(byteRead); throw new IOException(msg); } } else { bytesOut.write(byteRead); } } return ByteBuffer.wrap(bytesOut.toByteArray()); } }
MemcmpDecoder extends Decoder { @Override public ByteBuffer readBytes(ByteBuffer old) throws IOException { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); while (true) { int byteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (byteRead == 0) { int secondByteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (secondByteRead == 0) { break; } else if (secondByteRead == 1) { bytesOut.write(0); } else { String msg = "Illegal encoding. 0 byte cannot be followed by " + "anything other than 0 or 1. It was followed by " + Integer.toString(byteRead); throw new IOException(msg); } } else { bytesOut.write(byteRead); } } return ByteBuffer.wrap(bytesOut.toByteArray()); } MemcmpDecoder(InputStream in); }
MemcmpDecoder extends Decoder { @Override public ByteBuffer readBytes(ByteBuffer old) throws IOException { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); while (true) { int byteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (byteRead == 0) { int secondByteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (secondByteRead == 0) { break; } else if (secondByteRead == 1) { bytesOut.write(0); } else { String msg = "Illegal encoding. 0 byte cannot be followed by " + "anything other than 0 or 1. It was followed by " + Integer.toString(byteRead); throw new IOException(msg); } } else { bytesOut.write(byteRead); } } return ByteBuffer.wrap(bytesOut.toByteArray()); } MemcmpDecoder(InputStream in); @Override void readNull(); @Override boolean readBoolean(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override Utf8 readString(Utf8 old); @Override String readString(); @Override void skipString(); @Override ByteBuffer readBytes(ByteBuffer old); void skipBytes(); @Override void readFixed(byte[] bytes, int start, int length); @Override void skipFixed(int length); @Override int readEnum(); @Override long readArrayStart(); @Override long arrayNext(); @Override long skipArray(); @Override long readMapStart(); @Override long mapNext(); @Override long skipMap(); @Override int readIndex(); }
MemcmpDecoder extends Decoder { @Override public ByteBuffer readBytes(ByteBuffer old) throws IOException { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); while (true) { int byteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (byteRead == 0) { int secondByteRead = in.read(); if (byteRead < 0) { throw new EOFException(); } if (secondByteRead == 0) { break; } else if (secondByteRead == 1) { bytesOut.write(0); } else { String msg = "Illegal encoding. 0 byte cannot be followed by " + "anything other than 0 or 1. It was followed by " + Integer.toString(byteRead); throw new IOException(msg); } } else { bytesOut.write(byteRead); } } return ByteBuffer.wrap(bytesOut.toByteArray()); } MemcmpDecoder(InputStream in); @Override void readNull(); @Override boolean readBoolean(); @Override int readInt(); @Override long readLong(); @Override float readFloat(); @Override double readDouble(); @Override Utf8 readString(Utf8 old); @Override String readString(); @Override void skipString(); @Override ByteBuffer readBytes(ByteBuffer old); void skipBytes(); @Override void readFixed(byte[] bytes, int start, int length); @Override void skipFixed(int length); @Override int readEnum(); @Override long readArrayStart(); @Override long arrayNext(); @Override long skipArray(); @Override long readMapStart(); @Override long mapNext(); @Override long skipMap(); @Override int readIndex();  }