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

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

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

ByteString.substring介绍

[英]Returns a byte string that is a substring of this byte string, beginning at the specified index until the end of this string. Returns this byte string if beginIndex is 0.
[中]返回一个字节字符串,该字节字符串是该字节字符串的子字符串,从指定的索引开始,直到该字符串的结尾。如果beginIndex为0,则返回此字节字符串。

代码示例

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

@Test public void substringWithInvalidBounds() throws Exception {
 ByteString byteString = factory.encodeUtf8("Hello, World!");
 try {
  byteString.substring(-1);
  fail();
 } catch (IllegalArgumentException expected) {
 }
 try {
  byteString.substring(0, 14);
  fail();
 } catch (IllegalArgumentException expected) {
 }
 try {
  byteString.substring(8, 7);
  fail();
 } catch (IllegalArgumentException expected) {
 }
}

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

@Test public void substring() throws Exception {
 ByteString byteString = factory.encodeUtf8("Hello, World!");
 assertEquals(byteString.substring(0), byteString);
 assertEquals(byteString.substring(0, 5), ByteString.encodeUtf8("Hello"));
 assertEquals(byteString.substring(7), ByteString.encodeUtf8("World!"));
 assertEquals(byteString.substring(6, 6), ByteString.encodeUtf8(""));
}

代码示例来源: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: huxq17/tractor

/**
 * Returns a byte string that is a substring of this byte string, beginning at the specified
 * index until the end of this string. Returns this byte string if {@code beginIndex} is 0.
 */
public ByteString substring(int beginIndex) {
 return substring(beginIndex, data.length);
}

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

@Override public ByteString substring(int beginIndex) {
 return toByteString().substring(beginIndex);
}

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

@Override public ByteString substring(int beginIndex, int endIndex) {
 return toByteString().substring(beginIndex, endIndex);
}

代码示例来源: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);
}

代码示例来源:origin: 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);
}

代码示例来源:origin: org.domeos/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 (err != null) {
            err.write(byteString.toByteArray());
          }
          break;
        default:
          throw new IOException("Unknown stream ID " + streamID);
      }
    }
  } catch (IOException e) {
    throw KubernetesClientException.launderThrowable(e);
  }
}

相关文章