public Bytes<Underlying> write8bit(@NotNull CharSequence str, int offset, int length)
     throws BufferOverflowException, IllegalArgumentException, IndexOutOfBoundsException,
         IORuntimeException {
   writeStopBit(length);
   write(str, offset, length);
   return this;
 }
Esempio n. 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;
 }
 @NotNull
 public VanillaBytes append(@NotNull CharSequence str, int start, int end)
     throws IndexOutOfBoundsException {
   try {
     if (bytesStore() instanceof NativeBytesStore) {
       if (str instanceof BytesStore) {
         write((BytesStore) str, (long) start, end - start);
         return this;
       }
       if (str instanceof String) {
         write(str, start, end - start);
         return this;
       }
     }
     super.append(str, start, end);
     return this;
   } catch (Exception e) {
     throw new IndexOutOfBoundsException(e.toString());
   }
 }
  @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());
  }