@Override
 public boolean equalBytes(BytesStore bytesStore, long length)
     throws BufferUnderflowException, IORuntimeException {
   if (this.bytesStore instanceof NativeBytesStore
       && bytesStore instanceof VanillaBytes
       && bytesStore.bytesStore() instanceof NativeBytesStore) {
     VanillaBytes b2 = (VanillaBytes) bytesStore;
     NativeBytesStore nbs0 = (NativeBytesStore) this.bytesStore;
     NativeBytesStore nbs2 = (NativeBytesStore) b2.bytesStore();
     long i = 0;
     for (; i < length - 7; i++) {
       long addr0 = nbs0.address + readPosition() - nbs0.start() + i;
       long addr2 = nbs2.address + b2.readPosition() - nbs2.start() + i;
       long l0 = nbs0.memory.readLong(addr0);
       long l2 = nbs2.memory.readLong(addr2);
       if (l0 != l2) return false;
     }
     for (; i < length; i++) {
       long offset2 = readPosition() + i - nbs0.start();
       long offset21 = b2.readPosition() + i - nbs2.start();
       byte b0 = nbs0.memory.readByte(nbs0.address + offset2);
       byte b1 = nbs2.memory.readByte(nbs2.address + offset21);
       if (b0 != b1) return false;
     }
     return true;
   } else {
     return super.equalBytes(bytesStore, length);
   }
 }
Beispiel #2
0
 /**
  * copies the contents of bytes into a direct byte buffer
  *
  * @param bytes the bytes to wrap
  * @return a direct byte buffer contain the {@code bytes}
  */
 static Bytes allocateDirect(@NotNull byte[] bytes) throws IllegalArgumentException {
   VanillaBytes<Void> result = allocateDirect(bytes.length);
   try {
     result.write(bytes);
   } catch (BufferOverflowException | IORuntimeException e) {
     throw new AssertionError(e);
   }
   return result;
 }
  @Test
  public void testParseUTF_SB1() throws Exception {
    VanillaBytes bytes = Bytes.allocateElasticDirect();
    byte[] bytes2 = new byte[128];
    Arrays.fill(bytes2, (byte) '?');
    bytes.write(bytes2);

    StringBuilder sb = new StringBuilder();

    BytesInternal.parseUtf8(bytes, sb, 128);
    assertEquals(128, sb.length());
    assertEquals(new String(bytes2, 0), sb.toString());
  }