@Override public void onMessage(WebSocket webSocket, ByteString bytes) { System.out.println("MESSAGE: " + bytes.hex()); }
public static String key(HttpUrl url) { return ByteString.encodeUtf8(url.toString()).md5().hex(); }
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(); }
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(); }
private static String getTempFilenameForUri(Uri uri) { return ByteString.encodeUtf8(uri.toString()).sha1().hex(); }
public static String key(HttpUrl url) { return ByteString.encodeUtf8(url.toString()).md5().hex(); }
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(); }
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();
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()); } } }
@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(); } }
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()); }
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); } }
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()); } } }
@Test public void encodeHex() throws Exception { assertEquals("000102", ByteString.of((byte) 0x0, (byte) 0x1, (byte) 0x2).hex()); }
@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"); }
@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(); }
/** 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); } }
@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(); }
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(); } }
@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); }