public NamedRunnable(String format, Object... args) { this.name = Util.format(format, args); }
@Override public String format(LogRecord record) { return Util.format("%s%n", record.getMessage()); } });
static IllegalArgumentException illegalArgument(String message, Object... args) { throw new IllegalArgumentException(format(message, args)); }
static IOException ioException(String message, Object... args) throws IOException { throw new IOException(format(message, args)); }
static void checkValue(String value, String name) { if (value == null) throw new NullPointerException("value for name " + name + " == null"); for (int i = 0, length = value.length(); i < length; i++) { char c = value.charAt(i); if ((c <= '\u001f' && c != '\t') || c >= '\u007f') { throw new IllegalArgumentException(Util.format( "Unexpected char %#04x at %d in %s value: %s", (int) c, i, name, value)); } } }
static void checkName(String name) { if (name == null) throw new NullPointerException("name == null"); if (name.isEmpty()) throw new IllegalArgumentException("name is empty"); for (int i = 0, length = name.length(); i < length; i++) { char c = name.charAt(i); if (c <= '\u0020' || c >= '\u007f') { throw new IllegalArgumentException(Util.format( "Unexpected char %#04x at %d in header name: %s", (int) c, i, name)); } } }
public NamedRunnable(String format, Object... args) { this.name = Util.format(format, args); }
/** * Returns human-readable representation of HTTP/2 frame headers. * * <p>The format is: * * <pre> * direction streamID length type flags * </pre> * * Where direction is {@code <<} for inbound and {@code >>} for outbound. * * <p>For example, the following would indicate a HEAD request sent from the client. * <pre> * {@code * << 0x0000000f 12 HEADERS END_HEADERS|END_STREAM * } * </pre> */ static String frameLog(boolean inbound, int streamId, int length, byte type, byte flags) { String formattedType = type < FRAME_NAMES.length ? FRAME_NAMES[type] : format("0x%02x", type); String formattedFlags = formatFlags(type, flags); return format("%s 0x%08x %5d %-13s %s", inbound ? "<<" : ">>", streamId, length, formattedType, formattedFlags); }
static IOException ioException(String message, Object... args) throws IOException { throw new IOException(format(message, args)); }
static IllegalArgumentException illegalArgument(String message, Object... args) { throw new IllegalArgumentException(format(message, args)); }
static void checkValue(String value, String name) { if (value == null) throw new NullPointerException("value for name " + name + " == null"); for (int i = 0, length = value.length(); i < length; i++) { char c = value.charAt(i); if ((c <= '\u001f' && c != '\t') || c >= '\u007f') { throw new IllegalArgumentException(Util.format( "Unexpected char %#04x at %d in %s value: %s", (int) c, i, name, value)); } } }
static void checkName(String name) { if (name == null) throw new NullPointerException("name == null"); if (name.isEmpty()) throw new IllegalArgumentException("name is empty"); for (int i = 0, length = name.length(); i < length; i++) { char c = name.charAt(i); if (c <= '\u0020' || c >= '\u007f') { throw new IllegalArgumentException(Util.format( "Unexpected char %#04x at %d in header name: %s", (int) c, i, name)); } } }
@Override public String toString() { return Util.format("%s: %s", name.utf8(), value.utf8()); } }
/** * Returns human-readable representation of HTTP/2 frame headers. * * <p>The format is: * * <pre> * direction streamID length type flags * </pre> * * Where direction is {@code <<} for inbound and {@code >>} for outbound. * * <p>For example, the following would indicate a HEAD request sent from the client. * <pre> * {@code * << 0x0000000f 12 HEADERS END_HEADERS|END_STREAM * } * </pre> */ static String frameLog(boolean inbound, int streamId, int length, byte type, byte flags) { String formattedType = type < FRAME_NAMES.length ? FRAME_NAMES[type] : format("0x%02x", type); String formattedFlags = formatFlags(type, flags); return format("%s 0x%08x %5d %-13s %s", inbound ? "<<" : ">>", streamId, length, formattedType, formattedFlags); }
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 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(); }
@Override public String toString() { return Util.format("%s: %s", name.utf8(), value.utf8()); } }
Util.threadFactory(Util.format("OkHttp %s Writer", connectionName), false)); if (builder.pingIntervalMillis != 0) { writerExecutor.scheduleAtFixedRate(new PingRunnable(false, 0, 0), Util.threadFactory(Util.format("OkHttp %s Push Observer", connectionName), true)); peerSettings.set(Settings.INITIAL_WINDOW_SIZE, DEFAULT_INITIAL_WINDOW_SIZE); peerSettings.set(Settings.MAX_FRAME_SIZE, Http2.INITIAL_MAX_FRAME_SIZE);
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()); } } }
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()); } } }