/** * Returns the index of the first appearance of the value {@code target} in {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
private String byteArrayToString(byte[] data) { int length = Bytes.indexOf(data, (byte) 0); return new String(data, 0, length >= 0 ? length : data.length, Charsets.US_ASCII); }
private int[] findIndexes(byte[] array, byte[] target) { if (fields.length <= 1) { return new int[0]; } int[] indexes = new int[fields.length - 1]; Arrays.fill(indexes, -1); indexes[0] = Bytes.indexOf(array, target); if (indexes[0] == -1) { return indexes; } int indexInNewArray = indexes[0]; for (int i = 1; i < indexes.length; i++) { array = Arrays.copyOfRange(array, indexInNewArray + target.length, array.length); indexInNewArray = Bytes.indexOf(array, target); if (indexInNewArray == -1) { break; } indexes[i] = indexInNewArray + indexes[i - 1] + target.length; } return indexes; }
public void testIndexOf() { assertEquals(-1, Bytes.indexOf(EMPTY, (byte) 1)); assertEquals(-1, Bytes.indexOf(ARRAY1, (byte) 2)); assertEquals(-1, Bytes.indexOf(ARRAY234, (byte) 1)); assertEquals(0, Bytes.indexOf(new byte[] {(byte) -1}, (byte) -1)); assertEquals(0, Bytes.indexOf(ARRAY234, (byte) 2)); assertEquals(1, Bytes.indexOf(ARRAY234, (byte) 3)); assertEquals(2, Bytes.indexOf(ARRAY234, (byte) 4)); assertEquals(1, Bytes.indexOf(new byte[] {(byte) 2, (byte) 3, (byte) 2, (byte) 3}, (byte) 3)); }
public void testIndexOf_arrayTarget() { assertEquals(0, Bytes.indexOf(EMPTY, EMPTY)); assertEquals(0, Bytes.indexOf(ARRAY234, EMPTY)); assertEquals(-1, Bytes.indexOf(EMPTY, ARRAY234)); assertEquals(-1, Bytes.indexOf(ARRAY234, ARRAY1)); assertEquals(-1, Bytes.indexOf(ARRAY1, ARRAY234)); assertEquals(0, Bytes.indexOf(ARRAY1, ARRAY1)); assertEquals(0, Bytes.indexOf(ARRAY234, ARRAY234)); assertEquals(0, Bytes.indexOf(ARRAY234, new byte[] {(byte) 2, (byte) 3})); assertEquals(1, Bytes.indexOf(ARRAY234, new byte[] {(byte) 3, (byte) 4})); assertEquals(1, Bytes.indexOf(ARRAY234, new byte[] {(byte) 3})); assertEquals(2, Bytes.indexOf(ARRAY234, new byte[] {(byte) 4})); assertEquals( 1, Bytes.indexOf( new byte[] {(byte) 2, (byte) 3, (byte) 3, (byte) 3, (byte) 3}, new byte[] {(byte) 3})); assertEquals( 2, Bytes.indexOf( new byte[] {(byte) 2, (byte) 3, (byte) 2, (byte) 3, (byte) 4, (byte) 2, (byte) 3}, new byte[] {(byte) 2, (byte) 3, (byte) 4})); assertEquals( 1, Bytes.indexOf( new byte[] {(byte) 2, (byte) 2, (byte) 3, (byte) 4, (byte) 2, (byte) 3, (byte) 4}, new byte[] {(byte) 2, (byte) 3, (byte) 4})); assertEquals( -1, Bytes.indexOf( new byte[] {(byte) 4, (byte) 3, (byte) 2}, new byte[] {(byte) 2, (byte) 3, (byte) 4}));
static List<Advice> mergeInstrumentationAnnotations(List<Advice> advisors, byte[] classBytes, @Nullable ClassLoader loader, String className) { byte[] marker = "Lorg/glowroot/agent/api/Instrumentation$".getBytes(UTF_8); if (Bytes.indexOf(classBytes, marker) == -1) { return advisors;
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or {@code -1} if no * such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
/** * Returns the index of the first appearance of the value {@code target} in * {@code array}. * * @param array an array of {@code byte} values, possibly empty * @param target a primitive {@code byte} value * @return the least index {@code i} for which {@code array[i] == target}, or * {@code -1} if no such index exists. */ public static int indexOf(byte[] array, byte target) { return indexOf(array, target, 0, array.length); }
@Override protected byte[] getStringData() { byte[] data = super.getStringData(); int length = Bytes.indexOf(data, (byte) 0); if (length >= 0) return Arrays.copyOf(data, length); return data; }
@Nonnull private static String decodeString(@Nonnull ByteBuffer buffer, @Nonnegative int len) throws IOException { byte[] bytes = decodeBytes(buffer, len); // find zero-terminator int slen = Bytes.indexOf(bytes, (byte) 0); if (slen < 0) slen = bytes.length; return new String(bytes, 0, slen, Charsets.ISO_8859_1); }
private UnwrappedMessageContent unwrapMessageContent(byte[] json) { int rootIndex = indexOf(json, contentRootField); int metadataIndex = indexOf(json, metadataRootField); try { return new UnwrappedMessageContent(unwrapMesssageMetadata(json, metadataIndex, rootIndex), unwrapContent(json, rootIndex)); } catch (Exception exception) { throw new UnwrappingException("Could not unwrap json message", exception); } }