예제 #1
0
 @Test
 public void testBytes() {
   Wire wire = createWire();
   byte[] allBytes = new byte[256];
   for (int i = 0; i < 256; i++) allBytes[i] = (byte) i;
   wire.write()
       .bytes(NoBytesStore.NO_BYTES)
       .write()
       .bytes(Bytes.wrap("Hello".getBytes()))
       .write()
       .bytes(Bytes.wrap("quotable, text".getBytes()))
       .write()
       .bytes(allBytes);
   System.out.println(bytes.toDebugString());
   NativeBytes allBytes2 = nativeBytes();
   wire.read()
       .bytes(wi -> assertEquals(0, wi.bytes().readRemaining()))
       .read()
       .bytes(wi -> assertEquals("Hello", wi.bytes().toString()))
       .read()
       .bytes(wi -> assertEquals("quotable, text", wi.bytes().toString()))
       .read()
       .bytes(allBytes2);
   assertEquals(Bytes.wrap(allBytes), allBytes2);
 }
 @NotNull
 @Override
 public B writeByte(long offset, byte i8) throws AssertionError {
   try {
     byte i8a = underlyingBytesStore.readByte(offset);
     if (i8a != i8) {
       try {
         Bytes<Underlying> bytes = underlyingBytesStore.bytesForRead();
         bytes.readPosition(offset);
         throw new AssertionError(
             bytes.toDebugString() + "\nExpected: " + i8a + "\nActual: " + i8);
       } catch (IllegalStateException e) {
         throw new AssertionError(e);
       }
     }
     return (B) this;
   } catch (BufferUnderflowException | IORuntimeException e) {
     throw new AssertionError(e);
   }
 }