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

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

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

ByteString.base64介绍

[英]Returns this byte string encoded as Base64. In violation of the RFC, the returned string does not wrap lines at 76 columns.
[中]返回编码为Base64的字节字符串。与RFC相反,返回的字符串不在76列处换行。

代码示例

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

@Override public String toString() {
  return hashAlgorithm + hash.base64();
 }
}

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

private void encodeBase64Lines(StringBuilder out, ByteString data) {
 String base64 = data.base64();
 for (int i = 0; i < base64.length(); i += 64) {
  out.append(base64, i, Math.min(i + 64, base64.length())).append('\n');
 }
}

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

@Override public String toString() {
  return hashAlgorithm + hash.base64();
 }
}

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

public static String basic(String username, String password, Charset charset) {
  String usernameAndPassword = username + ":" + password;
  String encoded = ByteString.encodeString(usernameAndPassword, charset).base64();
  return "Basic " + encoded;
 }
}

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

/**
 * Returns the SHA-256 of {@code certificate}'s public key.
 *
 * <p>In OkHttp 3.1.2 and earlier, this returned a SHA-1 hash of the public key. Both types are
 * supported, but SHA-256 is preferred.
 */
public static String pin(Certificate certificate) {
 if (!(certificate instanceof X509Certificate)) {
  throw new IllegalArgumentException("Certificate pinning requires X509 certificates");
 }
 return "sha256/" + sha256((X509Certificate) certificate).base64();
}

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

@Override public void write(JsonWriter out, @Nullable ByteString value) throws IOException {
 if (value == null) {
  out.nullValue();
 } else {
  out.value(value.base64());
 }
}

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

@Override public void toJson(JsonWriter writer, ByteString value) throws IOException {
  String string = value.base64();
  writer.value(string);
 }
}

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

/**
 * Returns the SHA-256 of {@code certificate}'s public key.
 *
 * <p>In OkHttp 3.1.2 and earlier, this returned a SHA-1 hash of the public key. Both types are
 * supported, but SHA-256 is preferred.
 */
public static String pin(Certificate certificate) {
 if (!(certificate instanceof X509Certificate)) {
  throw new IllegalArgumentException("Certificate pinning requires X509 certificates");
 }
 return "sha256/" + sha256((X509Certificate) certificate).base64();
}

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

public static String acceptHeader(String key) {
 return ByteString.encodeUtf8(key + WebSocketProtocol.ACCEPT_MAGIC).sha1().base64();
}

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

public static String basic(String username, String password, Charset charset) {
  String usernameAndPassword = username + ":" + password;
  String encoded = ByteString.encodeString(usernameAndPassword, charset).base64();
  return "Basic " + encoded;
 }
}

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

public RealWebSocket(Request request, WebSocketListener listener, Random random,
  long pingIntervalMillis) {
 if (!"GET".equals(request.method())) {
  throw new IllegalArgumentException("Request must be GET: " + request.method());
 }
 this.originalRequest = request;
 this.listener = listener;
 this.random = random;
 this.pingIntervalMillis = pingIntervalMillis;
 byte[] nonce = new byte[16];
 random.nextBytes(nonce);
 this.key = ByteString.of(nonce).base64();
 this.writerRunnable = () -> {
  try {
   while (writeOneFrame()) {
   }
  } catch (IOException e) {
   failWebSocket(e, null);
  }
 };
}

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

@Override public void toJson(JsonWriter out, ByteString byteString) throws IOException {
 out.value(byteString.base64());
}

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

private void writeCertList(BufferedSink sink, List<Certificate> certificates)
  throws IOException {
 try {
  sink.writeDecimalLong(certificates.size())
    .writeByte('\n');
  for (int i = 0, size = certificates.size(); i < size; i++) {
   byte[] bytes = certificates.get(i).getEncoded();
   String line = ByteString.of(bytes).base64();
   sink.writeUtf8(line)
     .writeByte('\n');
  }
 } catch (CertificateEncodingException e) {
  throw new IOException(e.getMessage());
 }
}

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

/** See https://api.slack.com/docs/oauth. */
public HttpUrl authorizeUrl(String scopes, HttpUrl redirectUrl, ByteString state, String team) {
 HttpUrl.Builder builder = baseUrl.newBuilder("/oauth/authorize")
   .addQueryParameter("client_id", clientId)
   .addQueryParameter("scope", scopes)
   .addQueryParameter("redirect_uri", redirectUrl.toString())
   .addQueryParameter("state", state.base64());
 if (team != null) {
  builder.addQueryParameter("team", team);
 }
 return builder.build();
}

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

void checkResponse(Response response) throws ProtocolException {
 if (response.code() != 101) {
  throw new ProtocolException("Expected HTTP 101 response but was '"
    + response.code() + " " + response.message() + "'");
 }
 String headerConnection = response.header("Connection");
 if (!"Upgrade".equalsIgnoreCase(headerConnection)) {
  throw new ProtocolException("Expected 'Connection' header value 'Upgrade' but was '"
    + headerConnection + "'");
 }
 String headerUpgrade = response.header("Upgrade");
 if (!"websocket".equalsIgnoreCase(headerUpgrade)) {
  throw new ProtocolException(
    "Expected 'Upgrade' header value 'websocket' but was '" + headerUpgrade + "'");
 }
 String headerAccept = response.header("Sec-WebSocket-Accept");
 String acceptExpected = ByteString.encodeUtf8(key + WebSocketProtocol.ACCEPT_MAGIC)
   .sha1().base64();
 if (!acceptExpected.equals(headerAccept)) {
  throw new ProtocolException("Expected 'Sec-WebSocket-Accept' header value '"
    + acceptExpected + "' but was '" + headerAccept + "'");
 }
}

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

public static String acceptHeader(String key) {
 return ByteString.encodeUtf8(key + WebSocketProtocol.ACCEPT_MAGIC).sha1().base64();
}

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

public void run() throws Exception {
 Point point = new Point(8.0, 15.0);
 ByteString pointBytes = serialize(point);
 System.out.println(pointBytes.base64());
 ByteString goldenBytes = ByteString.decodeBase64("rO0ABXNyAB5va2lvLnNhbXBsZ"
   + "XMuR29sZGVuVmFsdWUkUG9pbnTdUW8rMji1IwIAAkQAAXhEAAF5eHBAIAAAAAAAAEAuA"
   + "AAAAAAA");
 Point decoded = (Point) deserialize(goldenBytes);
 assertEquals(point, decoded);
}

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

@Test public void encodeBase64() {
 assertEquals("", factory.encodeUtf8("").base64());
 assertEquals("AA==", factory.encodeUtf8("\u0000").base64());
 assertEquals("AAA=", factory.encodeUtf8("\u0000\u0000").base64());
 assertEquals("AAAA", factory.encodeUtf8("\u0000\u0000\u0000").base64());
 assertEquals("SG93IG1hbnkgbGluZXMgb2YgY29kZSBhcmUgdGhlcmU/ICdib3V0IDIgbWlsbGlvbi4=",
   factory.encodeUtf8("How many lines of code are there? 'bout 2 million.").base64());
}

代码示例来源:origin: k9mail/k-9

@Test
public void open_authExternal() throws Exception {
  settings.setAuthType(AuthType.EXTERNAL);
  MockImapServer server = new MockImapServer();
  preAuthenticationDialog(server, "AUTH=EXTERNAL");
  server.expect("2 AUTHENTICATE EXTERNAL " + ByteString.encodeUtf8(USERNAME).base64());
  server.output("2 OK Success");
  postAuthenticationDialogRequestingCapabilities(server);
  ImapConnection imapConnection = startServerAndCreateImapConnection(server);
  imapConnection.open();
  server.verifyConnectionStillOpen();
  server.verifyInteractionCompleted();
}

代码示例来源:origin: k9mail/k-9

@Test
public void open_authPlain() throws Exception {
  settings.setAuthType(AuthType.PLAIN);
  MockImapServer server = new MockImapServer();
  preAuthenticationDialog(server, "AUTH=PLAIN");
  server.expect("2 AUTHENTICATE PLAIN");
  server.output("+");
  server.expect(ByteString.encodeUtf8("\000" + USERNAME + "\000" + PASSWORD).base64());
  server.output("2 OK Success");
  postAuthenticationDialogRequestingCapabilities(server);
  ImapConnection imapConnection = startServerAndCreateImapConnection(server);
  imapConnection.open();
  server.verifyConnectionStillOpen();
  server.verifyInteractionCompleted();
}

相关文章