com.google.common.primitives.Bytes.indexOf()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(139)

本文整理了Java中com.google.common.primitives.Bytes.indexOf()方法的一些代码示例,展示了Bytes.indexOf()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.indexOf()方法的具体详情如下:
包路径:com.google.common.primitives.Bytes
类名称:Bytes
方法名:indexOf

Bytes.indexOf介绍

[英]Returns the index of the first appearance of the value target in array.
[中]返回数组中值目标的第一次出现的索引。

代码示例

代码示例来源:origin: google/guava

/**
 * 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);
}

代码示例来源:origin: google/j2objc

/**
 * 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);
}

代码示例来源:origin: wildfly/wildfly

/**
 * 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);
}

代码示例来源:origin: robolectric/robolectric

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);
}

代码示例来源:origin: apache/hive

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;
}

代码示例来源:origin: google/guava

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));
}

代码示例来源:origin: google/guava

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}));

代码示例来源:origin: apache/ignite

boolean notFound = Bytes.indexOf(fileBytes, encValBytes) == -1;
plainBytesFound[0] = plainBytesFound[0] || Bytes.indexOf(fileBytes, plainValBytes) != -1;

代码示例来源:origin: glowroot/glowroot

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;

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

/**
 * 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);
}

代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger

/**
 * 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);
}

代码示例来源:origin: com.atlassian.bundles/guava

/**
 * 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);
}

代码示例来源:origin: com.google.guava/guava-primitives

/**
 * 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);
}

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

/**
 * 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);
}

代码示例来源:origin: Nextdoor/bender

/**
 * 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);
}

代码示例来源:origin: org.sonatype.sisu/sisu-guava

/**
 * 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);
}

代码示例来源:origin: com.diffplug.guava/guava-core

/**
 * 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);
}

代码示例来源:origin: org.anarres.dhcp/dhcp-protocol

@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;
}

代码示例来源:origin: org.anarres.dhcp/dhcp-protocol

@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);
}

代码示例来源:origin: allegro/hermes

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);
  }
}

相关文章