Reader(int headerTableSizeSetting, int maxDynamicTableByteCount, Source source) { this.headerTableSizeSetting = headerTableSizeSetting; this.maxDynamicTableByteCount = maxDynamicTableByteCount; this.source = Okio.buffer(source); }
/** * Returns true if the first bytes of {@link #source} are {@code key} followed by a colon or * a newline. */ private boolean isKey(ByteString key) throws IOException { if (source.rangeEquals(0, key)) { byte nextByte = source.getBuffer().getByte(key.size()); return nextByte == ':' || nextByte == '\r' || nextByte == '\n'; } return false; }
public static String basic(String username, String password, Charset charset) { String usernameAndPassword = username + ":" + password; String encoded = ByteString.encodeString(usernameAndPassword, charset).base64(); return "Basic " + encoded; } }
/** * Sets the delegate of {@code timeout} to {@link Timeout#NONE} and resets its underlying timeout * to the default configuration. Use this to avoid unexpected sharing of timeouts between pooled * connections. */ void detachTimeout(ForwardingTimeout timeout) { Timeout oldDelegate = timeout.delegate(); timeout.setDelegate(Timeout.NONE); oldDelegate.clearDeadline(); oldDelegate.clearTimeout(); }
@Override public boolean onData(int streamId, BufferedSource source, int byteCount, boolean last) throws IOException { source.skip(byteCount); return true; }
/** Waits for an OAuth session for this client to be set. */ public synchronized void awaitAccessToken(Timeout timeout) throws InterruptedIOException { while (session == null) { timeout.waitUntilNotified(this); } }
static void toggleMask(Buffer.UnsafeCursor cursor, byte[] key) { int keyIndex = 0; int keyLength = key.length; do { byte[] buffer = cursor.data; for (int i = cursor.start, end = cursor.end; i < end; i++, keyIndex++) { keyIndex %= keyLength; // Reassign to prevent overflow breaking counter. buffer[i] = (byte) (buffer[i] ^ key[keyIndex]); } } while (cursor.next() != -1); }