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

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

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

ByteString.hex介绍

[英]Returns this byte string encoded in hexadecimal.
[中]返回此十六进制编码的字节字符串。

代码示例

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

@Override public void onMessage(WebSocket webSocket, ByteString bytes) {
 System.out.println("MESSAGE: " + bytes.hex());
}

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

public static String key(HttpUrl url) {
 return ByteString.encodeUtf8(url.toString()).md5().hex();
}

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

public synchronized void connectionPreface() throws IOException {
 if (closed) throw new IOException("closed");
 if (!client) return; // Nothing to write; servers don't send connection headers!
 if (logger.isLoggable(FINE)) {
  logger.fine(format(">> CONNECTION %s", CONNECTION_PREFACE.hex()));
 }
 sink.write(CONNECTION_PREFACE.toByteArray());
 sink.flush();
}

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

public void dumpStringData(String s) throws IOException {
 System.out.println("                       " + s);
 System.out.println("        String.length: " + s.length());
 System.out.println("String.codePointCount: " + s.codePointCount(0, s.length()));
 System.out.println("            Utf8.size: " + Utf8.size(s));
 System.out.println("          UTF-8 bytes: " + ByteString.encodeUtf8(s).hex());
 System.out.println();
}

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

private static String getTempFilenameForUri(Uri uri) {
  return ByteString.encodeUtf8(uri.toString()).sha1().hex();
}

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

public static String key(HttpUrl url) {
 return ByteString.encodeUtf8(url.toString()).md5().hex();
}

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

public synchronized void connectionPreface() throws IOException {
 if (closed) throw new IOException("closed");
 if (!client) return; // Nothing to write; servers don't send connection headers!
 if (logger.isLoggable(FINE)) {
  logger.fine(format(">> CONNECTION %s", CONNECTION_PREFACE.hex()));
 }
 sink.write(CONNECTION_PREFACE.toByteArray());
 sink.flush();
}

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

System.out.println("       md5: " + byteString.md5().hex());
System.out.println("      sha1: " + byteString.sha1().hex());
System.out.println("    sha256: " + byteString.sha256().hex());
System.out.println("    sha512: " + byteString.sha512().hex());
System.out.println();
System.out.println("       md5: " + buffer.md5().hex());
System.out.println("      sha1: " + buffer.sha1().hex());
System.out.println("    sha256: " + buffer.sha256().hex());
System.out.println("    sha512: " + buffer.sha512().hex());
System.out.println();
   BufferedSource source = Okio.buffer(hashingSource)) {
 source.readAll(Okio.blackhole());
 System.out.println("    sha256: " + hashingSource.hash().hex());
 sink.writeAll(source);
 System.out.println("    sha256: " + hashingSink.hash().hex());
System.out.println("hmacSha256: " + byteString.hmacSha256(secret).hex());
System.out.println();

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

public void readConnectionPreface(Handler handler) throws IOException {
 if (client) {
  // The client reads the initial SETTINGS frame.
  if (!nextFrame(true, handler)) {
   throw ioException("Required SETTINGS preface not received");
  }
 } else {
  // The server reads the CONNECTION_PREFACE byte string.
  ByteString connectionPreface = source.readByteString(CONNECTION_PREFACE.size());
  if (logger.isLoggable(FINE)) logger.fine(format("<< CONNECTION %s", connectionPreface.hex()));
  if (!CONNECTION_PREFACE.equals(connectionPreface)) {
   throw ioException("Expected a connection header but was %s", connectionPreface.utf8());
  }
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Subscribe(threadMode =ThreadMode.ASYNC)
 public void onWorkResult(WorkService.Result result) {
  workIndices.add(result.workIndex);
  if (result.e!=null) {
   WorkTests.this.e=result.e;
  }
  else  {
   String hash=result.hash.hex();
   if (!EXPECTED_HASH_HEX.equals(hash)) {
    WorkTests.this.e=
     new IllegalStateException(String.format("Expected hash of %s, received %s",
      EXPECTED_HASH_HEX, hash));
   }
  }
  latch.countDown();
 }
}

代码示例来源:origin: apollographql/apollo-android

Call httpCall(Operation operation, CacheHeaders cacheHeaders, boolean writeQueryDocument) throws IOException {
 RequestBody requestBody = RequestBody.create(MEDIA_TYPE, httpRequestBody(operation, scalarTypeAdapters,
   writeQueryDocument));
 Request.Builder requestBuilder = new Request.Builder()
   .url(serverUrl)
   .post(requestBody)
   .header(HEADER_ACCEPT_TYPE, ACCEPT_TYPE)
   .header(HEADER_CONTENT_TYPE, CONTENT_TYPE)
   .header(HEADER_APOLLO_OPERATION_ID, operation.operationId())
   .header(HEADER_APOLLO_OPERATION_NAME, operation.name().name())
   .tag(operation.operationId());
 if (cachePolicy.isPresent()) {
  HttpCachePolicy.Policy cachePolicy = this.cachePolicy.get();
  boolean skipCacheHttpResponse = "true".equalsIgnoreCase(cacheHeaders.headerValue(
    ApolloCacheHeaders.DO_NOT_STORE));
  String cacheKey = httpRequestBody(operation, scalarTypeAdapters, true).md5().hex();
  requestBuilder = requestBuilder
    .header(HttpCache.CACHE_KEY_HEADER, cacheKey)
    .header(HttpCache.CACHE_FETCH_STRATEGY_HEADER, cachePolicy.fetchStrategy.name())
    .header(HttpCache.CACHE_EXPIRE_TIMEOUT_HEADER, String.valueOf(cachePolicy.expireTimeoutMs()))
    .header(HttpCache.CACHE_EXPIRE_AFTER_READ_HEADER, Boolean.toString(cachePolicy.expireAfterRead))
    .header(HttpCache.CACHE_PREFETCH_HEADER, Boolean.toString(prefetch))
    .header(HttpCache.CACHE_DO_NOT_STORE, Boolean.toString(skipCacheHttpResponse));
 }
 return httpCallFactory.newCall(requestBuilder.build());
}

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

private void assertUtf8(String string, String expectedHex) throws IOException {
  Buffer buffer = new Buffer();
  ProtoWriter writer = new ProtoWriter(buffer);
  writer.writeString(string);
  assertThat(buffer.readByteString().hex()).isEqualTo(expectedHex);
  assertThat(Utf8.size(string)).isEqualTo(expectedHex.length() / 2);
 }
}

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

public void readConnectionPreface(Handler handler) throws IOException {
 if (client) {
  // The client reads the initial SETTINGS frame.
  if (!nextFrame(true, handler)) {
   throw ioException("Required SETTINGS preface not received");
  }
 } else {
  // The server reads the CONNECTION_PREFACE byte string.
  ByteString connectionPreface = source.readByteString(CONNECTION_PREFACE.size());
  if (logger.isLoggable(FINE)) logger.fine(format("<< CONNECTION %s", connectionPreface.hex()));
  if (!CONNECTION_PREFACE.equals(connectionPreface)) {
   throw ioException("Expected a connection header but was %s", connectionPreface.utf8());
  }
 }
}

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

@Test public void encodeHex() throws Exception {
 assertEquals("000102", ByteString.of((byte) 0x0, (byte) 0x1, (byte) 0x2).hex());
}

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

@Test public void removingElementZeroesData() throws IOException {
 QueueFile queueFile = newQueueFile(true);
 queueFile.add(values[4]);
 queueFile.remove();
 queueFile.close();
 BufferedSource source = Okio.buffer(Okio.source(file));
 source.skip(headerLength);
 source.skip(Element.HEADER_LENGTH);
 assertThat(source.readByteString(4).hex()).isEqualTo("00000000");
}

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

@Test public void removingElementDoesNotZeroData() throws IOException {
 QueueFile queueFile = newQueueFile(false);
 queueFile.add(values[4]);
 queueFile.remove();
 queueFile.close();
 BufferedSource source = Okio.buffer(Okio.source(file));
 source.skip(headerLength);
 source.skip(Element.HEADER_LENGTH);
 assertThat(source.readByteString(4).hex()).isEqualTo("04030201");
 source.close();
}

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

/** Returns a 32 character string containing an MD5 hash of {@code s}. */
public static String md5Hex(String s) {
 try {
  MessageDigest messageDigest = MessageDigest.getInstance("MD5");
  byte[] md5bytes = messageDigest.digest(s.getBytes("UTF-8"));
  return ByteString.of(md5bytes).hex();
 } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
  throw new AssertionError(e);
 }
}

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

@Override public synchronized void connectionPreface() throws IOException {
 if (closed) throw new IOException("closed");
 if (!client) return; // Nothing to write; servers don't send connection headers!
 if (logger.isLoggable(FINE)) {
  logger.fine(format(">> CONNECTION %s", CONNECTION_PREFACE.hex()));
 }
 sink.write(CONNECTION_PREFACE.toByteArray());
 sink.flush();
}

代码示例来源:origin: com.amazonaws/aws-android-sdk-appsync-runtime

public static String cacheKey(RequestBody requestBody) {
  Buffer hashBuffer = new Buffer();
  try {
   requestBody.writeTo(hashBuffer);
  } catch (IOException e) {
   // should never happen
   throw new RuntimeException(e);
  }
  return hashBuffer.readByteString().md5().hex();
 }
}

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

@Override public String readUtf8LineStrict() throws IOException {
 long newline = indexOf((byte) '\n');
 if (newline == -1L) {
  Buffer data = new Buffer();
  buffer.copyTo(data, 0, Math.min(32, buffer.size()));
  throw new EOFException("\\n not found: size=" + buffer.size()
    + " content=" + data.readByteString().hex() + "...");
 }
 return buffer.readUtf8Line(newline);
}

相关文章