okio.ByteString.getByte()方法的使用及代码示例

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

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

ByteString.getByte介绍

[英]Returns the byte at pos.
[中]返回位置处的字节。

代码示例

代码示例来源:origin: square/okhttp

int encodedLength(ByteString bytes) {
 long len = 0;
 for (int i = 0; i < bytes.size(); i++) {
  int b = bytes.getByte(i) & 0xFF;
  len += CODE_LENGTHS[b];
 }
 return (int) ((len + 7) >> 3);
}

代码示例来源:origin: square/okhttp

/**
  * An HTTP/2 response cannot contain uppercase header characters and must be treated as
  * malformed.
  */
 static ByteString checkLowercase(ByteString name) throws IOException {
  for (int i = 0, length = name.size(); i < length; i++) {
   byte c = name.getByte(i);
   if (c >= 'A' && c <= 'Z') {
    throw new IOException("PROTOCOL_ERROR response malformed: mixed case name: " + name.utf8());
   }
  }
  return name;
 }
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

int encodedLength(ByteString bytes) {
 long len = 0;
 for (int i = 0; i < bytes.size(); i++) {
  int b = bytes.getByte(i) & 0xFF;
  len += CODE_LENGTHS[b];
 }
 return (int) ((len + 7) >> 3);
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

/**
  * An HTTP/2 response cannot contain uppercase header characters and must be treated as
  * malformed.
  */
 static ByteString checkLowercase(ByteString name) throws IOException {
  for (int i = 0, length = name.size(); i < length; i++) {
   byte c = name.getByte(i);
   if (c >= 'A' && c <= 'Z') {
    throw new IOException("PROTOCOL_ERROR response malformed: mixed case name: " + name.utf8());
   }
  }
  return name;
 }
}

代码示例来源:origin: square/okhttp

void encode(ByteString data, BufferedSink sink) throws IOException {
 long current = 0;
 int n = 0;
 for (int i = 0; i < data.size(); i++) {
  int b = data.getByte(i) & 0xFF;
  int code = CODES[b];
  int nbits = CODE_LENGTHS[b];
  current <<= nbits;
  current |= code;
  n += nbits;
  while (n >= 8) {
   n -= 8;
   sink.writeByte(((int) (current >> n)));
  }
 }
 if (n > 0) {
  current <<= (8 - n);
  current |= (0xFF >>> n);
  sink.writeByte((int) current);
 }
}

代码示例来源:origin: square/okio

@Test public void getByte() throws Exception {
 ByteString byteString = factory.decodeHex("ab12");
 assertEquals(-85, byteString.getByte(0));
 assertEquals(18, byteString.getByte(1));
}

代码示例来源:origin: com.squareup.okhttp3/okhttp

void encode(ByteString data, BufferedSink sink) throws IOException {
 long current = 0;
 int n = 0;
 for (int i = 0; i < data.size(); i++) {
  int b = data.getByte(i) & 0xFF;
  int code = CODES[b];
  int nbits = CODE_LENGTHS[b];
  current <<= nbits;
  current |= code;
  n += nbits;
  while (n >= 8) {
   n -= 8;
   sink.writeByte(((int) (current >> n)));
  }
 }
 if (n > 0) {
  current <<= (8 - n);
  current |= (0xFF >>> n);
  sink.writeByte((int) current);
 }
}

代码示例来源:origin: square/okio

@Test public void getByteOutOfBounds() throws Exception {
 ByteString byteString = factory.decodeHex("ab12");
 try {
  byteString.getByte(2);
  fail();
 } catch (IndexOutOfBoundsException expected) {
 }
}

代码示例来源:origin: fabric8io/kubernetes-client

@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
  try {
    byte streamID = bytes.getByte(0);
    ByteString byteString = bytes.substring(1);
    if (byteString.size() > 0) {
      switch (streamID) {
        case 1:
          if (out != null) {
            out.write(byteString.toByteArray());
          }
          break;
        case 2:
          if (err != null) {
            err.write(byteString.toByteArray());
          }
          break;
        case 3:
          if (errChannel != null) {
            errChannel.write(byteString.toByteArray());
          }
          break;
        default:
          throw new IOException("Unknown stream ID " + streamID);
      }
    }
  } catch (IOException e) {
    throw KubernetesClientException.launderThrowable(e);
  }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

int encodedLength(ByteString bytes) {
 long len = 0;
 for (int i = 0; i < bytes.size(); i++) {
  int b = bytes.getByte(i) & 0xFF;
  len += CODE_LENGTHS[b];
 }
 return (int) ((len + 7) >> 3);
}

代码示例来源:origin: huxq17/tractor

@Override public int compareTo(ByteString byteString) {
 int sizeA = size();
 int sizeB = byteString.size();
 for (int i = 0, size = Math.min(sizeA, sizeB); i < size; i++) {
  int byteA = getByte(i) & 0xff;
  int byteB = byteString.getByte(i) & 0xff;
  if (byteA == byteB) continue;
  return byteA < byteB ? -1 : 1;
 }
 if (sizeA == sizeB) return 0;
 return sizeA < sizeB ? -1 : 1;
}

代码示例来源:origin: apache/servicemix-bundles

int encodedLength(ByteString bytes) {
 long len = 0;
 for (int i = 0; i < bytes.size(); i++) {
  int b = bytes.getByte(i) & 0xFF;
  len += CODE_LENGTHS[b];
 }
 return (int) ((len + 7) >> 3);
}

代码示例来源:origin: duzechao/OKHttpUtils

/**
  * An HTTP/2 response cannot contain uppercase header characters and must be treated as
  * malformed.
  */
 private static ByteString checkLowercase(ByteString name) throws IOException {
  for (int i = 0, length = name.size(); i < length; i++) {
   byte c = name.getByte(i);
   if (c >= 'A' && c <= 'Z') {
    throw new IOException("PROTOCOL_ERROR response malformed: mixed case name: " + name.utf8());
   }
  }
  return name;
 }
}

代码示例来源:origin: huxq17/SwipeCardsView

/**
  * An HTTP/2 response cannot contain uppercase header characters and must
  * be treated as malformed.
  */
 private static ByteString checkLowercase(ByteString name) throws IOException {
  for (int i = 0, length = name.size(); i < length; i++) {
   byte c = name.getByte(i);
   if (c >= 'A' && c <= 'Z') {
    throw new IOException("PROTOCOL_ERROR response malformed: mixed case name: " + name.utf8());
   }
  }
  return name;
 }
}

代码示例来源:origin: huxq17/tractor

/**
  * An HTTP/2 response cannot contain uppercase header characters and must
  * be treated as malformed.
  */
 private static ByteString checkLowercase(ByteString name) throws IOException {
  for (int i = 0, length = name.size(); i < length; i++) {
   byte c = name.getByte(i);
   if (c >= 'A' && c <= 'Z') {
    throw new IOException("PROTOCOL_ERROR response malformed: mixed case name: " + name.utf8());
   }
  }
  return name;
 }
}

代码示例来源:origin: com.github.ljun20160606/okhttp

/**
  * An HTTP/2 response cannot contain uppercase header characters and must be treated as
  * malformed.
  */
 static ByteString checkLowercase(ByteString name) throws IOException {
  for (int i = 0, length = name.size(); i < length; i++) {
   byte c = name.getByte(i);
   if (c >= 'A' && c <= 'Z') {
    throw new IOException("PROTOCOL_ERROR response malformed: mixed case name: " + name.utf8());
   }
  }
  return name;
 }
}

代码示例来源:origin: huxq17/tractor

boolean rangeEquals(long offset, ByteString bytes) {
 int byteCount = bytes.size();
 if (size - offset < byteCount) {
  return false;
 }
 for (int i = 0; i < byteCount; i++) {
  if (getByte(offset + i) != bytes.getByte(i)) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: huxq17/tractor

@Override public long indexOf(ByteString bytes, long fromIndex) throws IOException {
 if (bytes.size() == 0) throw new IllegalArgumentException("bytes is empty");
 while (true) {
  fromIndex = indexOf(bytes.getByte(0), fromIndex);
  if (fromIndex == -1) {
   return -1;
  }
  if (rangeEquals(fromIndex, bytes)) {
   return fromIndex;
  }
  fromIndex++;
 }
}

代码示例来源:origin: huxq17/tractor

@Override public long indexOf(ByteString bytes, long fromIndex) throws IOException {
 if (bytes.size() == 0) throw new IllegalArgumentException("bytes is empty");
 while (true) {
  fromIndex = indexOf(bytes.getByte(0), fromIndex);
  if (fromIndex == -1) {
   return -1;
  }
  if (rangeEquals(fromIndex, bytes)) {
   return fromIndex;
  }
  fromIndex++;
 }
}

代码示例来源:origin: com.openshift/openshift-restclient-java

@Override
public void onMessage(WebSocket socket, ByteString message) {
  /**
   * https://godoc.org/k8s.io/kubernetes/pkg/util/wsstream The Websocket
   * subprotocol "channel.k8s.io" prepends each binary message with a byte
   * indicating the channel number (zero indexed) the message was sent on.
   * Messages in both directions should prefix their messages with this channel
   * byte. When used for remote execution, the channel numbers are by convention
   * defined to match the POSIX file-descriptors assigned to STDIN, STDOUT, and
   * STDERR (0, 1, and 2). No other conversion is performed on the raw subprotocol
   * - writes are sent as they are received by the server.
   */
  int channel = message.getByte(0);
  String msg = message.substring(1).utf8();
  deliver(channel, msg);
}

相关文章