1
0
mirror of https://github.com/square/okhttp.git synced 2025-08-07 12:42:57 +03:00

Run IntelliJ's analysis on OkHttp.

This made a few hundred suggestions, many of which are thoughtful but
I'm deliberately ignoring anyway.

The following fixes are good ideas.
This commit is contained in:
jwilson
2016-06-26 23:55:18 -04:00
parent 988142cfe5
commit a4d3082d2f
25 changed files with 49 additions and 78 deletions

View File

@@ -78,7 +78,7 @@ public final class CacheAdapter implements InternalCache {
// cacheable or the client should be careful about caching it. // cacheable or the client should be careful about caching it.
} }
@Override public void update(Response cached, Response network) throws IOException { @Override public void update(Response cached, Response network) {
// This method is treated as optional and there is no obvious way of implementing it with // This method is treated as optional and there is no obvious way of implementing it with
// ResponseCache. Updating headers is useful if the server changes the metadata for a resource // ResponseCache. Updating headers is useful if the server changes the metadata for a resource
// (e.g. max age) to extend or truncate the life of that resource in the cache. If the metadata // (e.g. max age) to extend or truncate the life of that resource in the cache. If the metadata

View File

@@ -74,7 +74,7 @@ public final class OkApacheClient implements HttpClient {
return builder.build(); return builder.build();
} }
private static HttpResponse transformResponse(Response response) throws IOException { private static HttpResponse transformResponse(Response response) {
int code = response.code(); int code = response.code();
String message = response.message(); String message = response.message();
BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message); BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);

View File

@@ -274,7 +274,7 @@ public final class HttpLoggingInterceptor implements Interceptor {
* Returns true if the body in question probably contains human readable text. Uses a small sample * Returns true if the body in question probably contains human readable text. Uses a small sample
* of code points to detect unicode control characters commonly used in binary file signatures. * of code points to detect unicode control characters commonly used in binary file signatures.
*/ */
static boolean isPlaintext(Buffer buffer) throws EOFException { static boolean isPlaintext(Buffer buffer) {
try { try {
Buffer prefix = new Buffer(); Buffer prefix = new Buffer();
long byteCount = buffer.size() < 64 ? buffer.size() : 64; long byteCount = buffer.size() < 64 ? buffer.size() : 64;

View File

@@ -18,7 +18,6 @@ package okhttp3;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.SocketFactory; import javax.net.SocketFactory;
/** /**
@@ -26,41 +25,35 @@ import javax.net.SocketFactory;
* overriding {@link #configureSocket(java.net.Socket)}. * overriding {@link #configureSocket(java.net.Socket)}.
*/ */
public class DelegatingSocketFactory extends SocketFactory { public class DelegatingSocketFactory extends SocketFactory {
private final SocketFactory delegate; private final SocketFactory delegate;
public DelegatingSocketFactory(SocketFactory delegate) { public DelegatingSocketFactory(SocketFactory delegate) {
this.delegate = delegate; this.delegate = delegate;
} }
@Override @Override public Socket createSocket() throws IOException {
public Socket createSocket() throws IOException {
Socket socket = delegate.createSocket(); Socket socket = delegate.createSocket();
return configureSocket(socket); return configureSocket(socket);
} }
@Override @Override public Socket createSocket(String host, int port) throws IOException {
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
Socket socket = delegate.createSocket(host, port); Socket socket = delegate.createSocket(host, port);
return configureSocket(socket); return configureSocket(socket);
} }
@Override @Override public Socket createSocket(String host, int port, InetAddress localAddress,
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) int localPort) throws IOException {
throws IOException, UnknownHostException {
Socket socket = delegate.createSocket(host, port, localAddress, localPort); Socket socket = delegate.createSocket(host, port, localAddress, localPort);
return configureSocket(socket); return configureSocket(socket);
} }
@Override @Override public Socket createSocket(InetAddress host, int port) throws IOException {
public Socket createSocket(InetAddress host, int port) throws IOException {
Socket socket = delegate.createSocket(host, port); Socket socket = delegate.createSocket(host, port);
return configureSocket(socket); return configureSocket(socket);
} }
@Override @Override public Socket createSocket(InetAddress host, int port, InetAddress localAddress,
public Socket createSocket(InetAddress host, int port, InetAddress localAddress, int localPort) int localPort) throws IOException {
throws IOException {
Socket socket = delegate.createSocket(host, port, localAddress, localPort); Socket socket = delegate.createSocket(host, port, localAddress, localPort);
return configureSocket(socket); return configureSocket(socket);
} }

View File

@@ -49,7 +49,7 @@ public class FallbackTestClientSocketFactory extends DelegatingSSLSocketFactory
} }
@Override public void setEnabledCipherSuites(String[] suites) { @Override public void setEnabledCipherSuites(String[] suites) {
List<String> enabledCipherSuites = new ArrayList<String>(suites.length); List<String> enabledCipherSuites = new ArrayList<>(suites.length);
for (String suite : suites) { for (String suite : suites) {
if (!suite.equals(TLS_FALLBACK_SCSV)) { if (!suite.equals(TLS_FALLBACK_SCSV)) {
enabledCipherSuites.add(suite); enabledCipherSuites.add(suite);

View File

@@ -2094,7 +2094,7 @@ public final class URLConnectionTest {
} }
@Test public void redirectWithProxySelector() throws Exception { @Test public void redirectWithProxySelector() throws Exception {
final List<URI> proxySelectionRequests = new ArrayList<URI>(); final List<URI> proxySelectionRequests = new ArrayList<>();
urlFactory.setClient(urlFactory.client().newBuilder() urlFactory.setClient(urlFactory.client().newBuilder()
.proxySelector(new ProxySelector() { .proxySelector(new ProxySelector() {
@Override public List<Proxy> select(URI uri) { @Override public List<Proxy> select(URI uri) {
@@ -3680,7 +3680,7 @@ public final class URLConnectionTest {
} }
private static class RecordingTrustManager implements X509TrustManager { private static class RecordingTrustManager implements X509TrustManager {
private final List<String> calls = new ArrayList<String>(); private final List<String> calls = new ArrayList<>();
private final X509TrustManager delegate; private final X509TrustManager delegate;
public RecordingTrustManager(X509TrustManager delegate) { public RecordingTrustManager(X509TrustManager delegate) {
@@ -3702,7 +3702,7 @@ public final class URLConnectionTest {
} }
private String certificatesToString(X509Certificate[] certificates) { private String certificatesToString(X509Certificate[] certificates) {
List<String> result = new ArrayList<String>(); List<String> result = new ArrayList<>();
for (X509Certificate certificate : certificates) { for (X509Certificate certificate : certificates) {
result.add(certificate.getSubjectDN() + " " + certificate.getSerialNumber()); result.add(certificate.getSubjectDN() + " " + certificate.getSerialNumber());
} }

View File

@@ -75,32 +75,32 @@ public class OptionalMethodTest {
} }
private final static OptionalMethod<BaseClass> STRING_METHOD_RETURNS_ANY = private final static OptionalMethod<BaseClass> STRING_METHOD_RETURNS_ANY =
new OptionalMethod<BaseClass>(null, "stringMethod"); new OptionalMethod<>(null, "stringMethod");
private final static OptionalMethod<BaseClass> STRING_METHOD_RETURNS_STRING = private final static OptionalMethod<BaseClass> STRING_METHOD_RETURNS_STRING =
new OptionalMethod<BaseClass>(String.class, "stringMethod"); new OptionalMethod<>(String.class, "stringMethod");
private final static OptionalMethod<BaseClass> STRING_METHOD_RETURNS_INT = private final static OptionalMethod<BaseClass> STRING_METHOD_RETURNS_INT =
new OptionalMethod<BaseClass>(Integer.TYPE, "stringMethod"); new OptionalMethod<>(Integer.TYPE, "stringMethod");
private final static OptionalMethod<BaseClass> VOID_METHOD_RETURNS_ANY = private final static OptionalMethod<BaseClass> VOID_METHOD_RETURNS_ANY =
new OptionalMethod<BaseClass>(null, "voidMethod"); new OptionalMethod<>(null, "voidMethod");
private final static OptionalMethod<BaseClass> VOID_METHOD_RETURNS_VOID = private final static OptionalMethod<BaseClass> VOID_METHOD_RETURNS_VOID =
new OptionalMethod<BaseClass>(Void.TYPE, "voidMethod"); new OptionalMethod<>(Void.TYPE, "voidMethod");
private final static OptionalMethod<BaseClass> SUBCLASS_METHOD_RETURNS_ANY = private final static OptionalMethod<BaseClass> SUBCLASS_METHOD_RETURNS_ANY =
new OptionalMethod<BaseClass>(null, "subclassMethod"); new OptionalMethod<>(null, "subclassMethod");
private final static OptionalMethod<BaseClass> SUBCLASS_METHOD_RETURNS_STRING = private final static OptionalMethod<BaseClass> SUBCLASS_METHOD_RETURNS_STRING =
new OptionalMethod<BaseClass>(String.class, "subclassMethod"); new OptionalMethod<>(String.class, "subclassMethod");
private final static OptionalMethod<BaseClass> SUBCLASS_METHOD_RETURNS_INT = private final static OptionalMethod<BaseClass> SUBCLASS_METHOD_RETURNS_INT =
new OptionalMethod<BaseClass>(Integer.TYPE, "subclassMethod"); new OptionalMethod<>(Integer.TYPE, "subclassMethod");
private final static OptionalMethod<BaseClass> METHOD_WITH_ARGS_WRONG_PARAMS = private final static OptionalMethod<BaseClass> METHOD_WITH_ARGS_WRONG_PARAMS =
new OptionalMethod<BaseClass>(null, "methodWithArgs", Integer.class); new OptionalMethod<>(null, "methodWithArgs", Integer.class);
private final static OptionalMethod<BaseClass> METHOD_WITH_ARGS_CORRECT_PARAMS = private final static OptionalMethod<BaseClass> METHOD_WITH_ARGS_CORRECT_PARAMS =
new OptionalMethod<BaseClass>(null, "methodWithArgs", String.class); new OptionalMethod<>(null, "methodWithArgs", String.class);
private final static OptionalMethod<BaseClass> THROWS_EXCEPTION = private final static OptionalMethod<BaseClass> THROWS_EXCEPTION =
new OptionalMethod<BaseClass>(null, "throwsException"); new OptionalMethod<>(null, "throwsException");
private final static OptionalMethod<BaseClass> THROWS_RUNTIME_EXCEPTION = private final static OptionalMethod<BaseClass> THROWS_RUNTIME_EXCEPTION =
new OptionalMethod<BaseClass>(null, "throwsRuntimeException"); new OptionalMethod<>(null, "throwsRuntimeException");
private final static OptionalMethod<BaseClass> NON_PUBLIC = private final static OptionalMethod<BaseClass> NON_PUBLIC =
new OptionalMethod<BaseClass>(null, "nonPublic"); new OptionalMethod<>(null, "nonPublic");
@Test @Test
public void isSupported() throws Exception { public void isSupported() throws Exception {

View File

@@ -593,8 +593,6 @@ public final class OkHttpURLConnection extends HttpURLConnection implements Call
@Override public Response intercept(Chain chain) throws IOException { @Override public Response intercept(Chain chain) throws IOException {
try { try {
return chain.proceed(chain.request()); return chain.proceed(chain.request());
} catch (IOException e) {
throw e;
} catch (Error | RuntimeException e) { } catch (Error | RuntimeException e) {
throw new UnexpectedException(e); throw new UnexpectedException(e);
} }

View File

@@ -137,7 +137,7 @@ public final class URLEncodingTest {
@Override public void remove(Request request) throws IOException { @Override public void remove(Request request) throws IOException {
} }
@Override public void update(Response cached, Response network) throws IOException { @Override public void update(Response cached, Response network) {
} }
@Override public void trackConditionalCacheHit() { @Override public void trackConditionalCacheHit() {

View File

@@ -152,7 +152,7 @@ public final class Cache implements Closeable, Flushable {
Cache.this.remove(request); Cache.this.remove(request);
} }
@Override public void update(Response cached, Response network) throws IOException { @Override public void update(Response cached, Response network) {
Cache.this.update(cached, network); Cache.this.update(cached, network);
} }
@@ -217,7 +217,7 @@ public final class Cache implements Closeable, Flushable {
return response; return response;
} }
private CacheRequest put(Response response) throws IOException { private CacheRequest put(Response response) {
String requestMethod = response.request().method(); String requestMethod = response.request().method();
if (HttpMethod.invalidatesCache(response.request().method())) { if (HttpMethod.invalidatesCache(response.request().method())) {
@@ -432,7 +432,7 @@ public final class Cache implements Closeable, Flushable {
private boolean done; private boolean done;
private Sink body; private Sink body;
public CacheRequestImpl(final DiskLruCache.Editor editor) throws IOException { public CacheRequestImpl(final DiskLruCache.Editor editor) {
this.editor = editor; this.editor = editor;
this.cacheOut = editor.newSink(ENTRY_BODY); this.cacheOut = editor.newSink(ENTRY_BODY);
this.body = new ForwardingSink(cacheOut) { this.body = new ForwardingSink(cacheOut) {

View File

@@ -359,7 +359,6 @@ public final class CipherSuite {
// public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CCM = of("TLS_ECDHE_ECDSA_WITH_AES_256_CCM", 0xc0ad, 7251, MAX_VALUE, MAX_VALUE); // public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CCM = of("TLS_ECDHE_ECDSA_WITH_AES_256_CCM", 0xc0ad, 7251, MAX_VALUE, MAX_VALUE);
// public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = of("TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", 0xc0ae, 7251, MAX_VALUE, MAX_VALUE); // public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 = of("TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8", 0xc0ae, 7251, MAX_VALUE, MAX_VALUE);
// public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 = of("TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8", 0xc0af, 7251, MAX_VALUE, MAX_VALUE); // public static final CipherSuite TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8 = of("TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8", 0xc0af, 7251, MAX_VALUE, MAX_VALUE);
;
final String javaName; final String javaName;

View File

@@ -29,10 +29,8 @@ import java.security.NoSuchAlgorithmException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@@ -244,11 +242,6 @@ public final class Util {
return Collections.unmodifiableList(Arrays.asList(elements.clone())); return Collections.unmodifiableList(Arrays.asList(elements.clone()));
} }
/** Returns an immutable copy of {@code map}. */
public static <K, V> Map<K, V> immutableMap(Map<K, V> map) {
return Collections.unmodifiableMap(new LinkedHashMap<>(map));
}
public static ThreadFactory threadFactory(final String name, final boolean daemon) { public static ThreadFactory threadFactory(final String name, final boolean daemon) {
return new ThreadFactory() { return new ThreadFactory() {
@Override public Thread newThread(Runnable runnable) { @Override public Thread newThread(Runnable runnable) {

View File

@@ -258,7 +258,7 @@ public final class CacheInterceptor implements Interceptor {
} }
/** Combines cached headers with a network headers as defined by RFC 2616, 13.5.3. */ /** Combines cached headers with a network headers as defined by RFC 2616, 13.5.3. */
private static Headers combine(Headers cachedHeaders, Headers networkHeaders) throws IOException { private static Headers combine(Headers cachedHeaders, Headers networkHeaders) {
Headers.Builder result = new Headers.Builder(); Headers.Builder result = new Headers.Builder();
for (int i = 0, size = cachedHeaders.size(); i < size; i++) { for (int i = 0, size = cachedHeaders.size(); i < size; i++) {

View File

@@ -872,7 +872,7 @@ public final class DiskLruCache implements Closeable, Flushable {
* Returns an unbuffered input stream to read the last committed value, or null if no value has * Returns an unbuffered input stream to read the last committed value, or null if no value has
* been committed. * been committed.
*/ */
public Source newSource(int index) throws IOException { public Source newSource(int index) {
synchronized (DiskLruCache.this) { synchronized (DiskLruCache.this) {
if (done) { if (done) {
throw new IllegalStateException(); throw new IllegalStateException();
@@ -893,7 +893,7 @@ public final class DiskLruCache implements Closeable, Flushable {
* output stream encounters errors when writing to the filesystem, this edit will be aborted * output stream encounters errors when writing to the filesystem, this edit will be aborted
* when {@link #commit} is called. The returned output stream does not throw IOExceptions. * when {@link #commit} is called. The returned output stream does not throw IOExceptions.
*/ */
public Sink newSink(int index) throws IOException { public Sink newSink(int index) {
synchronized (DiskLruCache.this) { synchronized (DiskLruCache.this) {
if (done) { if (done) {
throw new IllegalStateException(); throw new IllegalStateException();

View File

@@ -39,7 +39,7 @@ public interface InternalCache {
* {@code network}. The cached response body is not updated. If the stored response has changed * {@code network}. The cached response body is not updated. If the stored response has changed
* since {@code cached} was returned, this does nothing. * since {@code cached} was returned, this does nothing.
*/ */
void update(Response cached, Response network) throws IOException; void update(Response cached, Response network);
/** Track an conditional GET that was satisfied by this cache. */ /** Track an conditional GET that was satisfied by this cache. */
void trackConditionalCacheHit(); void trackConditionalCacheHit();

View File

@@ -145,7 +145,7 @@ public final class RealConnection extends FramedConnection.Listener implements C
throw new ProtocolException("Too many tunnel connections attempted: " + maxAttempts); throw new ProtocolException("Too many tunnel connections attempted: " + maxAttempts);
} }
connectSocket(connectTimeout, readTimeout, writeTimeout, connectionSpecSelector); connectSocket(connectTimeout, readTimeout);
tunnelRequest = createTunnel(readTimeout, writeTimeout, tunnelRequest, url); tunnelRequest = createTunnel(readTimeout, writeTimeout, tunnelRequest, url);
if (tunnelRequest == null) break; // Tunnel successfully created. if (tunnelRequest == null) break; // Tunnel successfully created.
@@ -164,12 +164,11 @@ public final class RealConnection extends FramedConnection.Listener implements C
/** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */ /** Does all the work necessary to build a full HTTP or HTTPS connection on a raw socket. */
private void buildConnection(int connectTimeout, int readTimeout, int writeTimeout, private void buildConnection(int connectTimeout, int readTimeout, int writeTimeout,
ConnectionSpecSelector connectionSpecSelector) throws IOException { ConnectionSpecSelector connectionSpecSelector) throws IOException {
connectSocket(connectTimeout, readTimeout, writeTimeout, connectionSpecSelector); connectSocket(connectTimeout, readTimeout);
establishProtocol(readTimeout, writeTimeout, connectionSpecSelector); establishProtocol(readTimeout, writeTimeout, connectionSpecSelector);
} }
private void connectSocket(int connectTimeout, int readTimeout, int writeTimeout, private void connectSocket(int connectTimeout, int readTimeout) throws IOException {
ConnectionSpecSelector connectionSpecSelector) throws IOException {
Proxy proxy = route.proxy(); Proxy proxy = route.proxy();
Address address = route.address(); Address address = route.address();
@@ -331,7 +330,7 @@ public final class RealConnection extends FramedConnection.Listener implements C
* is sent unencrypted to the proxy server, so tunnels include only the minimum set of headers. * is sent unencrypted to the proxy server, so tunnels include only the minimum set of headers.
* This avoids sending potentially sensitive data like HTTP cookies to the proxy unencrypted. * This avoids sending potentially sensitive data like HTTP cookies to the proxy unencrypted.
*/ */
private Request createTunnelRequest() throws IOException { private Request createTunnelRequest() {
return new Request.Builder() return new Request.Builder()
.url(route.address().url()) .url(route.address().url())
.header("Host", Util.hostHeader(route.address().url(), true)) .header("Host", Util.hostHeader(route.address().url(), true))
@@ -340,11 +339,6 @@ public final class RealConnection extends FramedConnection.Listener implements C
.build(); .build();
} }
/** Returns true if {@link #connect} has been attempted on this connection. */
boolean isConnected() {
return protocol != null;
}
@Override public Route route() { @Override public Route route() {
return route; return route;
} }

View File

@@ -88,8 +88,7 @@ public final class StreamAllocation {
this.routeSelector = new RouteSelector(address, routeDatabase()); this.routeSelector = new RouteSelector(address, routeDatabase());
} }
public HttpStream newStream(OkHttpClient client, boolean doExtensiveHealthChecks) public HttpStream newStream(OkHttpClient client, boolean doExtensiveHealthChecks) {
throws IOException {
int connectTimeout = client.connectTimeoutMillis(); int connectTimeout = client.connectTimeoutMillis();
int readTimeout = client.readTimeoutMillis(); int readTimeout = client.readTimeoutMillis();
int writeTimeout = client.writeTimeoutMillis(); int writeTimeout = client.writeTimeoutMillis();

View File

@@ -62,7 +62,7 @@ public enum ErrorCode {
public final int spdyRstCode; public final int spdyRstCode;
public final int spdyGoAwayCode; public final int spdyGoAwayCode;
private ErrorCode(int httpCode, int spdyRstCode, int spdyGoAwayCode) { ErrorCode(int httpCode, int spdyRstCode, int spdyGoAwayCode) {
this.httpCode = httpCode; this.httpCode = httpCode;
this.spdyRstCode = spdyRstCode; this.spdyRstCode = spdyRstCode;
this.spdyGoAwayCode = spdyGoAwayCode; this.spdyGoAwayCode = spdyGoAwayCode;

View File

@@ -126,7 +126,7 @@ public final class FramedConnection implements Closeable {
// Visible for testing // Visible for testing
final Reader readerRunnable; final Reader readerRunnable;
private FramedConnection(Builder builder) throws IOException { private FramedConnection(Builder builder) {
protocol = builder.protocol; protocol = builder.protocol;
pushObserver = builder.pushObserver; pushObserver = builder.pushObserver;
client = builder.client; client = builder.client;
@@ -529,7 +529,7 @@ public final class FramedConnection implements Closeable {
* @param client true if this peer initiated the connection; false if this peer accepted the * @param client true if this peer initiated the connection; false if this peer accepted the
* connection. * connection.
*/ */
public Builder(boolean client) throws IOException { public Builder(boolean client) {
this.client = client; this.client = client;
} }

View File

@@ -371,8 +371,7 @@ final class Hpack {
private static final int SETTINGS_HEADER_TABLE_SIZE = 4096; private static final int SETTINGS_HEADER_TABLE_SIZE = 4096;
private final Buffer out; private final Buffer out;
private final Map<ByteString, Integer> headerStringToDynamicIndex = private final Map<ByteString, Integer> headerStringToDynamicIndex = new LinkedHashMap<>();
new LinkedHashMap<ByteString, Integer>();
private int headerTableSizeSetting; private int headerTableSizeSetting;
private int maxDynamicTableByteCount; private int maxDynamicTableByteCount;
@@ -494,7 +493,7 @@ final class Hpack {
} }
// http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-12#section-4.1.1 // http://tools.ietf.org/html/draft-ietf-httpbis-header-compression-12#section-4.1.1
void writeInt(int value, int prefixMask, int bits) throws IOException { void writeInt(int value, int prefixMask, int bits) {
// Write the raw value for a single byte value. // Write the raw value for a single byte value.
if (value < prefixMask) { if (value < prefixMask) {
out.writeByte(bits | value); out.writeByte(bits | value);

View File

@@ -124,7 +124,7 @@ class Huffman {
return (int) ((len + 7) >> 3); return (int) ((len + 7) >> 3);
} }
byte[] decode(byte[] buf) throws IOException { byte[] decode(byte[] buf) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
Node node = root; Node node = root;
int current = 0; int current = 0;

View File

@@ -87,7 +87,7 @@ public final class Http1xStream implements HttpStream {
this.sink = sink; this.sink = sink;
} }
@Override public Sink createRequestBody(Request request, long contentLength) throws IOException { @Override public Sink createRequestBody(Request request, long contentLength) {
if ("chunked".equalsIgnoreCase(request.header("Transfer-Encoding"))) { if ("chunked".equalsIgnoreCase(request.header("Transfer-Encoding"))) {
// Stream a request body of unknown length. // Stream a request body of unknown length.
return newChunkedSink(); return newChunkedSink();

View File

@@ -119,7 +119,7 @@ public final class Http2xStream implements HttpStream {
this.framedConnection = framedConnection; this.framedConnection = framedConnection;
} }
@Override public Sink createRequestBody(Request request, long contentLength) throws IOException { @Override public Sink createRequestBody(Request request, long contentLength) {
return stream.getSink(); return stream.getSink();
} }

View File

@@ -38,10 +38,6 @@ public final class HttpHeaders {
private HttpHeaders() { private HttpHeaders() {
} }
public static long contentLength(Request request) {
return contentLength(request.headers());
}
public static long contentLength(Response response) { public static long contentLength(Response response) {
return contentLength(response.headers()); return contentLength(response.headers());
} }

View File

@@ -30,7 +30,7 @@ public interface HttpStream {
int DISCARD_STREAM_TIMEOUT_MILLIS = 100; int DISCARD_STREAM_TIMEOUT_MILLIS = 100;
/** Returns an output stream where the request body can be streamed. */ /** Returns an output stream where the request body can be streamed. */
Sink createRequestBody(Request request, long contentLength) throws IOException; Sink createRequestBody(Request request, long contentLength);
/** This should update the HTTP engine's sentRequestMillis field. */ /** This should update the HTTP engine's sentRequestMillis field. */
void writeRequestHeaders(Request request) throws IOException; void writeRequestHeaders(Request request) throws IOException;