@Test public void test2NullAtFront() throws Exception { assertThat(TextEncodedStringNullTerminated.getNullIndex(writeToBuffer(new byte[]{NULL_BYTE, NULL_BYTE, NULL_BYTE}), false), is(1)); }
@VisibleForTesting static int getNullIndex(final Buffer buffer, final boolean nullIsOneByte) { try { if (nullIsOneByte) { return (int)buffer.indexOf(NULL_BYTE); } long indexSecondByte = -1; long indexFirstByte = getNullEvenIndex(buffer, 0); while (-1 == indexSecondByte && -1 != indexFirstByte) { if (buffer.getByte(indexFirstByte + 1) == NULL_BYTE) { indexSecondByte = indexFirstByte + 1; } else { indexFirstByte = getNullEvenIndex(buffer, indexFirstByte + 2); } } return (int)indexSecondByte; } catch (ArrayIndexOutOfBoundsException e) { return -1; } }
TextEncodedStringNullTerminated extends AbstractString { @VisibleForTesting static int getNullIndex(final Buffer buffer, final boolean nullIsOneByte) { try { if (nullIsOneByte) { return (int)buffer.indexOf(NULL_BYTE); } long indexSecondByte = -1; long indexFirstByte = getNullEvenIndex(buffer, 0); while (-1 == indexSecondByte && -1 != indexFirstByte) { if (buffer.getByte(indexFirstByte + 1) == NULL_BYTE) { indexSecondByte = indexFirstByte + 1; } else { indexFirstByte = getNullEvenIndex(buffer, indexFirstByte + 2); } } return (int)indexSecondByte; } catch (ArrayIndexOutOfBoundsException e) { return -1; } } }
TextEncodedStringNullTerminated extends AbstractString { @VisibleForTesting static int getNullIndex(final Buffer buffer, final boolean nullIsOneByte) { try { if (nullIsOneByte) { return (int)buffer.indexOf(NULL_BYTE); } long indexSecondByte = -1; long indexFirstByte = getNullEvenIndex(buffer, 0); while (-1 == indexSecondByte && -1 != indexFirstByte) { if (buffer.getByte(indexFirstByte + 1) == NULL_BYTE) { indexSecondByte = indexFirstByte + 1; } else { indexFirstByte = getNullEvenIndex(buffer, indexFirstByte + 2); } } return (int)indexSecondByte; } catch (ArrayIndexOutOfBoundsException e) { return -1; } } TextEncodedStringNullTerminated(String identifier, AbstractTagFrameBody frameBody);  TextEncodedStringNullTerminated(String identifier, AbstractTagFrameBody frameBody, String value);  TextEncodedStringNullTerminated(TextEncodedStringNullTerminated object); }
TextEncodedStringNullTerminated extends AbstractString { @VisibleForTesting static int getNullIndex(final Buffer buffer, final boolean nullIsOneByte) { try { if (nullIsOneByte) { return (int)buffer.indexOf(NULL_BYTE); } long indexSecondByte = -1; long indexFirstByte = getNullEvenIndex(buffer, 0); while (-1 == indexSecondByte && -1 != indexFirstByte) { if (buffer.getByte(indexFirstByte + 1) == NULL_BYTE) { indexSecondByte = indexFirstByte + 1; } else { indexFirstByte = getNullEvenIndex(buffer, indexFirstByte + 2); } } return (int)indexSecondByte; } catch (ArrayIndexOutOfBoundsException e) { return -1; } } TextEncodedStringNullTerminated(String identifier, AbstractTagFrameBody frameBody);  TextEncodedStringNullTerminated(String identifier, AbstractTagFrameBody frameBody, String value);  TextEncodedStringNullTerminated(TextEncodedStringNullTerminated object); boolean equals(Object obj); void readByteArray(byte[] arr, int offset); @Override void read(final Buffer buffer, final int size); byte[] writeByteArray(); }
TextEncodedStringNullTerminated extends AbstractString { @VisibleForTesting static int getNullIndex(final Buffer buffer, final boolean nullIsOneByte) { try { if (nullIsOneByte) { return (int)buffer.indexOf(NULL_BYTE); } long indexSecondByte = -1; long indexFirstByte = getNullEvenIndex(buffer, 0); while (-1 == indexSecondByte && -1 != indexFirstByte) { if (buffer.getByte(indexFirstByte + 1) == NULL_BYTE) { indexSecondByte = indexFirstByte + 1; } else { indexFirstByte = getNullEvenIndex(buffer, indexFirstByte + 2); } } return (int)indexSecondByte; } catch (ArrayIndexOutOfBoundsException e) { return -1; } } TextEncodedStringNullTerminated(String identifier, AbstractTagFrameBody frameBody);  TextEncodedStringNullTerminated(String identifier, AbstractTagFrameBody frameBody, String value);  TextEncodedStringNullTerminated(TextEncodedStringNullTerminated object); boolean equals(Object obj); void readByteArray(byte[] arr, int offset); @Override void read(final Buffer buffer, final int size); byte[] writeByteArray();  }