mirror of
https://github.com/square/okhttp.git
synced 2026-01-27 04:22:07 +03:00
Flatten internal packages and utility classes.
The previous structure had hierarchy that was useful for libcore but overkill for OkHttp.
This commit is contained in:
@@ -17,12 +17,12 @@
|
||||
package com.squareup.okhttp;
|
||||
|
||||
import com.squareup.okhttp.internal.Platform;
|
||||
import com.squareup.okhttp.internal.net.http.HttpAuthenticator;
|
||||
import com.squareup.okhttp.internal.net.http.HttpEngine;
|
||||
import com.squareup.okhttp.internal.net.http.HttpTransport;
|
||||
import com.squareup.okhttp.internal.net.http.RawHeaders;
|
||||
import com.squareup.okhttp.internal.net.http.SpdyTransport;
|
||||
import com.squareup.okhttp.internal.net.spdy.SpdyConnection;
|
||||
import com.squareup.okhttp.internal.http.HttpAuthenticator;
|
||||
import com.squareup.okhttp.internal.http.HttpEngine;
|
||||
import com.squareup.okhttp.internal.http.HttpTransport;
|
||||
import com.squareup.okhttp.internal.http.RawHeaders;
|
||||
import com.squareup.okhttp.internal.http.SpdyTransport;
|
||||
import com.squareup.okhttp.internal.spdy.SpdyConnection;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package com.squareup.okhttp;
|
||||
|
||||
import com.squareup.okhttp.internal.Platform;
|
||||
import com.squareup.okhttp.internal.io.IoUtils;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import java.net.SocketException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -88,7 +88,7 @@ public final class ConnectionPool {
|
||||
connections = null;
|
||||
}
|
||||
if (!connection.isEligibleForRecycling()) {
|
||||
IoUtils.closeQuietly(connection);
|
||||
Util.closeQuietly(connection);
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
@@ -96,7 +96,7 @@ public final class ConnectionPool {
|
||||
} catch (SocketException e) {
|
||||
// When unable to tag, skip recycling and close
|
||||
Platform.get().logW("Unable to tagSocket(): " + e);
|
||||
IoUtils.closeQuietly(connection);
|
||||
Util.closeQuietly(connection);
|
||||
continue;
|
||||
}
|
||||
return connection;
|
||||
@@ -121,7 +121,7 @@ public final class ConnectionPool {
|
||||
} catch (SocketException e) {
|
||||
// When unable to remove tagging, skip recycling and close
|
||||
Platform.get().logW("Unable to untagSocket(): " + e);
|
||||
IoUtils.closeQuietly(connection);
|
||||
Util.closeQuietly(connection);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ public final class ConnectionPool {
|
||||
}
|
||||
|
||||
// don't close streams while holding a lock!
|
||||
IoUtils.closeQuietly(connection);
|
||||
Util.closeQuietly(connection);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
*/
|
||||
package com.squareup.okhttp;
|
||||
|
||||
import com.squareup.okhttp.internal.net.http.HttpURLConnectionImpl;
|
||||
import com.squareup.okhttp.internal.net.http.HttpsURLConnectionImpl;
|
||||
import com.squareup.okhttp.internal.http.HttpURLConnectionImpl;
|
||||
import com.squareup.okhttp.internal.http.HttpsURLConnectionImpl;
|
||||
import java.net.CookieHandler;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.Proxy;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package com.squareup.okhttp;
|
||||
|
||||
import static com.squareup.okhttp.internal.Util.getDefaultPort;
|
||||
import com.squareup.okhttp.internal.net.http.RawHeaders;
|
||||
import com.squareup.okhttp.internal.http.RawHeaders;
|
||||
|
||||
/**
|
||||
* Routing and authentication information sent to an HTTP proxy to create a
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
* @author Alexander Y. Kleymenov
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.io;
|
||||
package com.squareup.okhttp.internal;
|
||||
|
||||
import static com.squareup.okhttp.internal.Util.EMPTY_BYTE_ARRAY;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -14,10 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.io;
|
||||
package com.squareup.okhttp.internal;
|
||||
|
||||
import com.squareup.okhttp.internal.Platform;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import static com.squareup.okhttp.internal.Util.UTF_8;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.Closeable;
|
||||
@@ -253,7 +251,7 @@ public final class DiskLruCache implements Closeable {
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
IoUtils.closeQuietly(reader);
|
||||
Util.closeQuietly(reader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -599,7 +597,7 @@ public final class DiskLruCache implements Closeable {
|
||||
*/
|
||||
public void delete() throws IOException {
|
||||
close();
|
||||
IoUtils.deleteContents(directory);
|
||||
Util.deleteContents(directory);
|
||||
}
|
||||
|
||||
private void validateKey(String key) {
|
||||
@@ -610,7 +608,7 @@ public final class DiskLruCache implements Closeable {
|
||||
}
|
||||
|
||||
private static String inputStreamToString(InputStream in) throws IOException {
|
||||
return Streams.readFully(new InputStreamReader(in, UTF_8));
|
||||
return Util.readFully(new InputStreamReader(in, UTF_8));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -652,7 +650,7 @@ public final class DiskLruCache implements Closeable {
|
||||
|
||||
@Override public void close() {
|
||||
for (InputStream in : ins) {
|
||||
IoUtils.closeQuietly(in);
|
||||
Util.closeQuietly(in);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -723,7 +721,7 @@ public final class DiskLruCache implements Closeable {
|
||||
writer = new OutputStreamWriter(newOutputStream(index), UTF_8);
|
||||
writer.write(value);
|
||||
} finally {
|
||||
IoUtils.closeQuietly(writer);
|
||||
Util.closeQuietly(writer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.net;
|
||||
package com.squareup.okhttp.internal;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.io;
|
||||
package com.squareup.okhttp.internal;
|
||||
|
||||
import static com.squareup.okhttp.internal.Util.ISO_8859_1;
|
||||
import static com.squareup.okhttp.internal.Util.US_ASCII;
|
||||
@@ -16,10 +16,19 @@
|
||||
|
||||
package com.squareup.okhttp.internal;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.EOFException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
/**
|
||||
* Junk drawer of utility methods.
|
||||
@@ -35,6 +44,7 @@ public final class Util {
|
||||
|
||||
/** A cheap and type-safe constant for the UTF-8 Charset. */
|
||||
public static final Charset UTF_8 = Charset.forName("UTF-8");
|
||||
private static AtomicReference<byte[]> skipBuffer = new AtomicReference<byte[]>();
|
||||
|
||||
private Util() {
|
||||
}
|
||||
@@ -89,4 +99,218 @@ public final class Util {
|
||||
public static boolean equal(Object a, Object b) {
|
||||
return a == b || (a != null && a.equals(b));
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes 'closeable', ignoring any checked exceptions. Does nothing if 'closeable' is null.
|
||||
*/
|
||||
public static void closeQuietly(Closeable closeable) {
|
||||
if (closeable != null) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (RuntimeException rethrown) {
|
||||
throw rethrown;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes {@code a} and {@code b}. If either close fails, this completes
|
||||
* the other close and rethrows the first encountered exception.
|
||||
*/
|
||||
public static void closeAll(Closeable a, Closeable b) throws IOException {
|
||||
Throwable thrown = null;
|
||||
try {
|
||||
a.close();
|
||||
} catch (Throwable e) {
|
||||
thrown = e;
|
||||
}
|
||||
try {
|
||||
b.close();
|
||||
} catch (Throwable e) {
|
||||
if (thrown == null) thrown = e;
|
||||
}
|
||||
if (thrown == null) return;
|
||||
if (thrown instanceof IOException) throw (IOException) thrown;
|
||||
if (thrown instanceof RuntimeException) throw (RuntimeException) thrown;
|
||||
if (thrown instanceof Error) throw (Error) thrown;
|
||||
throw new AssertionError(thrown);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively delete everything in {@code dir}.
|
||||
*/
|
||||
// TODO: this should specify paths as Strings rather than as Files
|
||||
public static void deleteContents(File dir) throws IOException {
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) {
|
||||
throw new IllegalArgumentException("not a directory: " + dir);
|
||||
}
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
deleteContents(file);
|
||||
}
|
||||
if (!file.delete()) {
|
||||
throw new IOException("failed to delete file: " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements InputStream.read(int) in terms of InputStream.read(byte[], int, int).
|
||||
* InputStream assumes that you implement InputStream.read(int) and provides default
|
||||
* implementations of the others, but often the opposite is more efficient.
|
||||
*/
|
||||
public static int readSingleByte(InputStream in) throws IOException {
|
||||
byte[] buffer = new byte[1];
|
||||
int result = in.read(buffer, 0, 1);
|
||||
return (result != -1) ? buffer[0] & 0xff : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements OutputStream.write(int) in terms of OutputStream.write(byte[], int, int).
|
||||
* OutputStream assumes that you implement OutputStream.write(int) and provides default
|
||||
* implementations of the others, but often the opposite is more efficient.
|
||||
*/
|
||||
public static void writeSingleByte(OutputStream out, int b) throws IOException {
|
||||
byte[] buffer = new byte[1];
|
||||
buffer[0] = (byte) (b & 0xff);
|
||||
out.write(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills 'dst' with bytes from 'in', throwing EOFException if insufficient bytes are available.
|
||||
*/
|
||||
public static void readFully(InputStream in, byte[] dst) throws IOException {
|
||||
readFully(in, dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads exactly 'byteCount' bytes from 'in' (into 'dst' at offset 'offset'), and throws
|
||||
* EOFException if insufficient bytes are available.
|
||||
*
|
||||
* Used to implement {@link java.io.DataInputStream#readFully(byte[], int, int)}.
|
||||
*/
|
||||
public static void readFully(InputStream in, byte[] dst, int offset, int byteCount) throws IOException {
|
||||
if (byteCount == 0) {
|
||||
return;
|
||||
}
|
||||
if (in == null) {
|
||||
throw new NullPointerException("in == null");
|
||||
}
|
||||
if (dst == null) {
|
||||
throw new NullPointerException("dst == null");
|
||||
}
|
||||
checkOffsetAndCount(dst.length, offset, byteCount);
|
||||
while (byteCount > 0) {
|
||||
int bytesRead = in.read(dst, offset, byteCount);
|
||||
if (bytesRead < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
offset += bytesRead;
|
||||
byteCount -= bytesRead;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the remainder of 'reader' as a string, closing it when done.
|
||||
*/
|
||||
public static String readFully(Reader reader) throws IOException {
|
||||
try {
|
||||
StringWriter writer = new StringWriter();
|
||||
char[] buffer = new char[1024];
|
||||
int count;
|
||||
while ((count = reader.read(buffer)) != -1) {
|
||||
writer.write(buffer, 0, count);
|
||||
}
|
||||
return writer.toString();
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void skipAll(InputStream in) throws IOException {
|
||||
do {
|
||||
in.skip(Long.MAX_VALUE);
|
||||
} while (in.read() != -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call {@code in.read()} repeatedly until either the stream is exhausted or
|
||||
* {@code byteCount} bytes have been read.
|
||||
*
|
||||
* <p>This method reuses the skip buffer but is careful to never use it at
|
||||
* the same time that another stream is using it. Otherwise streams that use
|
||||
* the caller's buffer for consistency checks like CRC could be clobbered by
|
||||
* other threads. A thread-local buffer is also insufficient because some
|
||||
* streams may call other streams in their skip() method, also clobbering the
|
||||
* buffer.
|
||||
*/
|
||||
public static long skipByReading(InputStream in, long byteCount) throws IOException {
|
||||
// acquire the shared skip buffer.
|
||||
byte[] buffer = skipBuffer.getAndSet(null);
|
||||
if (buffer == null) {
|
||||
buffer = new byte[4096];
|
||||
}
|
||||
|
||||
long skipped = 0;
|
||||
while (skipped < byteCount) {
|
||||
int toRead = (int) Math.min(byteCount - skipped, buffer.length);
|
||||
int read = in.read(buffer, 0, toRead);
|
||||
if (read == -1) {
|
||||
break;
|
||||
}
|
||||
skipped += read;
|
||||
if (read < toRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// release the shared skip buffer.
|
||||
skipBuffer.set(buffer);
|
||||
|
||||
return skipped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all of the bytes from {@code in} to {@code out}. Neither stream is closed.
|
||||
* Returns the total number of bytes transferred.
|
||||
*/
|
||||
public static int copy(InputStream in, OutputStream out) throws IOException {
|
||||
int total = 0;
|
||||
byte[] buffer = new byte[8192];
|
||||
int c;
|
||||
while ((c = in.read(buffer)) != -1) {
|
||||
total += c;
|
||||
out.write(buffer, 0, c);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ASCII characters up to but not including the next "\r\n", or
|
||||
* "\n".
|
||||
*
|
||||
* @throws java.io.EOFException if the stream is exhausted before the next newline
|
||||
* character.
|
||||
*/
|
||||
public static String readAsciiLine(InputStream in) throws IOException {
|
||||
// TODO: support UTF-8 here instead
|
||||
StringBuilder result = new StringBuilder(80);
|
||||
while (true) {
|
||||
int c = in.read();
|
||||
if (c == -1) {
|
||||
throw new EOFException();
|
||||
} else if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
|
||||
result.append((char) c);
|
||||
}
|
||||
int length = result.length();
|
||||
if (length > 0 && result.charAt(length - 1) == '\r') {
|
||||
result.setLength(length - 1);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.internal.io.Streams;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -60,7 +60,7 @@ abstract class AbstractHttpInputStream extends InputStream {
|
||||
* need to override the latter.
|
||||
*/
|
||||
@Override public final int read() throws IOException {
|
||||
return Streams.readSingleByte(this);
|
||||
return Util.readSingleByte(this);
|
||||
}
|
||||
|
||||
protected final void checkNotClosed() throws IOException {
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
final class HeaderParser {
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.internal.io.Base64;
|
||||
import com.squareup.okhttp.internal.Base64;
|
||||
import java.io.IOException;
|
||||
import java.net.Authenticator;
|
||||
import static java.net.HttpURLConnection.HTTP_PROXY_AUTH;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.Address;
|
||||
import com.squareup.okhttp.Connection;
|
||||
@@ -23,11 +23,11 @@ import com.squareup.okhttp.OkResponseCache;
|
||||
import com.squareup.okhttp.ResponseSource;
|
||||
import com.squareup.okhttp.TunnelRequest;
|
||||
import com.squareup.okhttp.internal.Platform;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import static com.squareup.okhttp.internal.Util.EMPTY_BYTE_ARRAY;
|
||||
import static com.squareup.okhttp.internal.Util.getDefaultPort;
|
||||
import static com.squareup.okhttp.internal.Util.getEffectivePort;
|
||||
import com.squareup.okhttp.internal.io.IoUtils;
|
||||
import com.squareup.okhttp.internal.net.Dns;
|
||||
import com.squareup.okhttp.internal.Dns;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -190,7 +190,7 @@ public class HttpEngine {
|
||||
*/
|
||||
if (requestHeaders.isOnlyIfCached() && responseSource.requiresConnection()) {
|
||||
if (responseSource == ResponseSource.CONDITIONAL_CACHE) {
|
||||
IoUtils.closeQuietly(cachedResponseBody);
|
||||
Util.closeQuietly(cachedResponseBody);
|
||||
}
|
||||
this.responseSource = ResponseSource.CACHE;
|
||||
this.cacheResponse = GATEWAY_TIMEOUT_RESPONSE;
|
||||
@@ -228,7 +228,7 @@ public class HttpEngine {
|
||||
if (!acceptCacheResponseType(candidate)
|
||||
|| responseHeadersMap == null
|
||||
|| cachedResponseBody == null) {
|
||||
IoUtils.closeQuietly(cachedResponseBody);
|
||||
Util.closeQuietly(cachedResponseBody);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ public class HttpEngine {
|
||||
} else if (responseSource == ResponseSource.CONDITIONAL_CACHE) {
|
||||
this.cacheResponse = candidate;
|
||||
} else if (responseSource == ResponseSource.NETWORK) {
|
||||
IoUtils.closeQuietly(cachedResponseBody);
|
||||
Util.closeQuietly(cachedResponseBody);
|
||||
} else {
|
||||
throw new AssertionError();
|
||||
}
|
||||
@@ -426,14 +426,14 @@ public class HttpEngine {
|
||||
public final void release(boolean reusable) {
|
||||
// If the response body comes from the cache, close it.
|
||||
if (responseBodyIn == cachedResponseBody) {
|
||||
IoUtils.closeQuietly(responseBodyIn);
|
||||
Util.closeQuietly(responseBodyIn);
|
||||
}
|
||||
|
||||
if (!connectionReleased && connection != null) {
|
||||
connectionReleased = true;
|
||||
|
||||
if (!reusable || !transport.makeReusable(requestBodyOut, responseTransferIn)) {
|
||||
IoUtils.closeQuietly(connection);
|
||||
Util.closeQuietly(connection);
|
||||
connection = null;
|
||||
} else if (automaticallyReleaseConnectionToPool) {
|
||||
policy.connectionPool.recycle(connection);
|
||||
@@ -658,7 +658,7 @@ public class HttpEngine {
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
IoUtils.closeQuietly(cachedResponseBody);
|
||||
Util.closeQuietly(cachedResponseBody);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.OkResponseCache;
|
||||
import com.squareup.okhttp.ResponseSource;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import static com.squareup.okhttp.internal.Util.US_ASCII;
|
||||
import static com.squareup.okhttp.internal.Util.UTF_8;
|
||||
import com.squareup.okhttp.internal.io.Base64;
|
||||
import com.squareup.okhttp.internal.io.DiskLruCache;
|
||||
import com.squareup.okhttp.internal.io.IoUtils;
|
||||
import com.squareup.okhttp.internal.io.StrictLineReader;
|
||||
import com.squareup.okhttp.internal.Base64;
|
||||
import com.squareup.okhttp.internal.DiskLruCache;
|
||||
import com.squareup.okhttp.internal.StrictLineReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
@@ -319,7 +319,7 @@ public final class HttpResponseCache extends ResponseCache implements OkResponse
|
||||
done = true;
|
||||
writeAbortCount++;
|
||||
}
|
||||
IoUtils.closeQuietly(cacheOut);
|
||||
Util.closeQuietly(cacheOut);
|
||||
try {
|
||||
editor.abort();
|
||||
} catch (IOException ignored) {
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.Connection;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import static com.squareup.okhttp.internal.Util.checkOffsetAndCount;
|
||||
import com.squareup.okhttp.internal.io.Streams;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -200,7 +200,7 @@ public final class HttpTransport implements Transport {
|
||||
int socketTimeout = socket.getSoTimeout();
|
||||
socket.setSoTimeout(DISCARD_STREAM_TIMEOUT_MILLIS);
|
||||
try {
|
||||
Streams.skipAll(responseBodyIn);
|
||||
Util.skipAll(responseBodyIn);
|
||||
return true;
|
||||
} finally {
|
||||
socket.setSoTimeout(socketTimeout);
|
||||
@@ -474,9 +474,9 @@ public final class HttpTransport implements Transport {
|
||||
private void readChunkSize() throws IOException {
|
||||
// read the suffix of the previous chunk
|
||||
if (bytesRemainingInChunk != NO_CHUNK_YET) {
|
||||
Streams.readAsciiLine(in);
|
||||
Util.readAsciiLine(in);
|
||||
}
|
||||
String chunkSizeString = Streams.readAsciiLine(in);
|
||||
String chunkSizeString = Util.readAsciiLine(in);
|
||||
int index = chunkSizeString.indexOf(";");
|
||||
if (index != -1) {
|
||||
chunkSizeString = chunkSizeString.substring(0, index);
|
||||
@@ -15,12 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.Connection;
|
||||
import com.squareup.okhttp.ConnectionPool;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import static com.squareup.okhttp.internal.Util.getEffectivePort;
|
||||
import com.squareup.okhttp.internal.io.IoUtils;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -106,7 +106,7 @@ public class HttpURLConnectionImpl extends HttpURLConnection {
|
||||
// However the response body can be a GZIPInputStream that
|
||||
// still has unread data.
|
||||
if (httpEngine.hasResponse()) {
|
||||
IoUtils.closeQuietly(httpEngine.getResponseBody());
|
||||
Util.closeQuietly(httpEngine.getResponseBody());
|
||||
}
|
||||
httpEngine.release(false);
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.Connection;
|
||||
import com.squareup.okhttp.ConnectionPool;
|
||||
@@ -449,7 +449,7 @@ public final class HttpsURLConnectionImpl extends HttpsURLConnection {
|
||||
@Override protected TunnelRequest getTunnelConfig() {
|
||||
String userAgent = requestHeaders.getUserAgent();
|
||||
if (userAgent == null) {
|
||||
userAgent = HttpEngine.getDefaultUserAgent();
|
||||
userAgent = getDefaultUserAgent();
|
||||
}
|
||||
|
||||
URL url = policy.getURL();
|
||||
@@ -15,10 +15,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.internal.Platform;
|
||||
import com.squareup.okhttp.internal.io.Streams;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -311,7 +311,7 @@ public final class RawHeaders {
|
||||
RawHeaders headers;
|
||||
do {
|
||||
headers = new RawHeaders();
|
||||
headers.setStatusLine(Streams.readAsciiLine(in));
|
||||
headers.setStatusLine(Util.readAsciiLine(in));
|
||||
readHeaders(in, headers);
|
||||
} while (headers.getResponseCode() == HttpEngine.HTTP_CONTINUE);
|
||||
return headers;
|
||||
@@ -323,7 +323,7 @@ public final class RawHeaders {
|
||||
public static void readHeaders(InputStream in, RawHeaders out) throws IOException {
|
||||
// parse the result headers until the first blank line
|
||||
String line;
|
||||
while ((line = Streams.readAsciiLine(in)).length() != 0) {
|
||||
while ((line = Util.readAsciiLine(in)).length() != 0) {
|
||||
out.addLine(line);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.ResponseSource;
|
||||
import static com.squareup.okhttp.internal.Util.equal;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import static com.squareup.okhttp.internal.Util.checkOffsetAndCount;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.Address;
|
||||
import com.squareup.okhttp.Connection;
|
||||
import com.squareup.okhttp.ConnectionPool;
|
||||
import static com.squareup.okhttp.internal.Util.getEffectivePort;
|
||||
import com.squareup.okhttp.internal.net.Dns;
|
||||
import com.squareup.okhttp.internal.Dns;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.internal.net.spdy.SpdyConnection;
|
||||
import com.squareup.okhttp.internal.net.spdy.SpdyStream;
|
||||
import com.squareup.okhttp.internal.spdy.SpdyConnection;
|
||||
import com.squareup.okhttp.internal.spdy.SpdyStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.io;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
public final class IoUtils {
|
||||
private IoUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes 'closeable', ignoring any checked exceptions. Does nothing if 'closeable' is null.
|
||||
*/
|
||||
public static void closeQuietly(Closeable closeable) {
|
||||
if (closeable != null) {
|
||||
try {
|
||||
closeable.close();
|
||||
} catch (RuntimeException rethrown) {
|
||||
throw rethrown;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes {@code a} and {@code b}. If either close fails, this completes
|
||||
* the other close and rethrows the first encountered exception.
|
||||
*/
|
||||
public static void closeAll(Closeable a, Closeable b) throws IOException {
|
||||
Throwable thrown = null;
|
||||
try {
|
||||
a.close();
|
||||
} catch (Throwable e) {
|
||||
thrown = e;
|
||||
}
|
||||
try {
|
||||
b.close();
|
||||
} catch (Throwable e) {
|
||||
if (thrown == null) thrown = e;
|
||||
}
|
||||
if (thrown == null) return;
|
||||
if (thrown instanceof IOException) throw (IOException) thrown;
|
||||
if (thrown instanceof RuntimeException) throw (RuntimeException) thrown;
|
||||
if (thrown instanceof Error) throw (Error) thrown;
|
||||
throw new AssertionError(thrown);
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes 'socket', ignoring any exceptions. Does nothing if 'socket' is null.
|
||||
*/
|
||||
public static void closeQuietly(Socket socket) {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively delete everything in {@code dir}.
|
||||
*/
|
||||
// TODO: this should specify paths as Strings rather than as Files
|
||||
public static void deleteContents(File dir) throws IOException {
|
||||
File[] files = dir.listFiles();
|
||||
if (files == null) {
|
||||
throw new IllegalArgumentException("not a directory: " + dir);
|
||||
}
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
deleteContents(file);
|
||||
}
|
||||
if (!file.delete()) {
|
||||
throw new IOException("failed to delete file: " + file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.io;
|
||||
|
||||
import static com.squareup.okhttp.internal.Util.checkOffsetAndCount;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
public final class Streams {
|
||||
private static AtomicReference<byte[]> skipBuffer = new AtomicReference<byte[]>();
|
||||
|
||||
private Streams() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements InputStream.read(int) in terms of InputStream.read(byte[], int, int).
|
||||
* InputStream assumes that you implement InputStream.read(int) and provides default
|
||||
* implementations of the others, but often the opposite is more efficient.
|
||||
*/
|
||||
public static int readSingleByte(InputStream in) throws IOException {
|
||||
byte[] buffer = new byte[1];
|
||||
int result = in.read(buffer, 0, 1);
|
||||
return (result != -1) ? buffer[0] & 0xff : -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements OutputStream.write(int) in terms of OutputStream.write(byte[], int, int).
|
||||
* OutputStream assumes that you implement OutputStream.write(int) and provides default
|
||||
* implementations of the others, but often the opposite is more efficient.
|
||||
*/
|
||||
public static void writeSingleByte(OutputStream out, int b) throws IOException {
|
||||
byte[] buffer = new byte[1];
|
||||
buffer[0] = (byte) (b & 0xff);
|
||||
out.write(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills 'dst' with bytes from 'in', throwing EOFException if insufficient bytes are available.
|
||||
*/
|
||||
public static void readFully(InputStream in, byte[] dst) throws IOException {
|
||||
readFully(in, dst, 0, dst.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads exactly 'byteCount' bytes from 'in' (into 'dst' at offset 'offset'), and throws
|
||||
* EOFException if insufficient bytes are available.
|
||||
*
|
||||
* Used to implement {@link java.io.DataInputStream#readFully(byte[], int, int)}.
|
||||
*/
|
||||
public static void readFully(InputStream in, byte[] dst, int offset, int byteCount) throws IOException {
|
||||
if (byteCount == 0) {
|
||||
return;
|
||||
}
|
||||
if (in == null) {
|
||||
throw new NullPointerException("in == null");
|
||||
}
|
||||
if (dst == null) {
|
||||
throw new NullPointerException("dst == null");
|
||||
}
|
||||
checkOffsetAndCount(dst.length, offset, byteCount);
|
||||
while (byteCount > 0) {
|
||||
int bytesRead = in.read(dst, offset, byteCount);
|
||||
if (bytesRead < 0) {
|
||||
throw new EOFException();
|
||||
}
|
||||
offset += bytesRead;
|
||||
byteCount -= bytesRead;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the remainder of 'reader' as a string, closing it when done.
|
||||
*/
|
||||
public static String readFully(Reader reader) throws IOException {
|
||||
try {
|
||||
StringWriter writer = new StringWriter();
|
||||
char[] buffer = new char[1024];
|
||||
int count;
|
||||
while ((count = reader.read(buffer)) != -1) {
|
||||
writer.write(buffer, 0, count);
|
||||
}
|
||||
return writer.toString();
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static void skipAll(InputStream in) throws IOException {
|
||||
do {
|
||||
in.skip(Long.MAX_VALUE);
|
||||
} while (in.read() != -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call {@code in.read()} repeatedly until either the stream is exhausted or
|
||||
* {@code byteCount} bytes have been read.
|
||||
*
|
||||
* <p>This method reuses the skip buffer but is careful to never use it at
|
||||
* the same time that another stream is using it. Otherwise streams that use
|
||||
* the caller's buffer for consistency checks like CRC could be clobbered by
|
||||
* other threads. A thread-local buffer is also insufficient because some
|
||||
* streams may call other streams in their skip() method, also clobbering the
|
||||
* buffer.
|
||||
*/
|
||||
public static long skipByReading(InputStream in, long byteCount) throws IOException {
|
||||
// acquire the shared skip buffer.
|
||||
byte[] buffer = skipBuffer.getAndSet(null);
|
||||
if (buffer == null) {
|
||||
buffer = new byte[4096];
|
||||
}
|
||||
|
||||
long skipped = 0;
|
||||
while (skipped < byteCount) {
|
||||
int toRead = (int) Math.min(byteCount - skipped, buffer.length);
|
||||
int read = in.read(buffer, 0, toRead);
|
||||
if (read == -1) {
|
||||
break;
|
||||
}
|
||||
skipped += read;
|
||||
if (read < toRead) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// release the shared skip buffer.
|
||||
skipBuffer.set(buffer);
|
||||
|
||||
return skipped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies all of the bytes from {@code in} to {@code out}. Neither stream is closed.
|
||||
* Returns the total number of bytes transferred.
|
||||
*/
|
||||
public static int copy(InputStream in, OutputStream out) throws IOException {
|
||||
int total = 0;
|
||||
byte[] buffer = new byte[8192];
|
||||
int c;
|
||||
while ((c = in.read(buffer)) != -1) {
|
||||
total += c;
|
||||
out.write(buffer, 0, c);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ASCII characters up to but not including the next "\r\n", or
|
||||
* "\n".
|
||||
*
|
||||
* @throws java.io.EOFException if the stream is exhausted before the next newline
|
||||
* character.
|
||||
*/
|
||||
public static String readAsciiLine(InputStream in) throws IOException {
|
||||
// TODO: support UTF-8 here instead
|
||||
|
||||
StringBuilder result = new StringBuilder(80);
|
||||
while (true) {
|
||||
int c = in.read();
|
||||
if (c == -1) {
|
||||
throw new EOFException();
|
||||
} else if (c == '\n') {
|
||||
break;
|
||||
}
|
||||
|
||||
result.append((char) c);
|
||||
}
|
||||
int length = result.length();
|
||||
if (length > 0 && result.charAt(length - 1) == '\r') {
|
||||
result.setLength(length - 1);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
final class Settings {
|
||||
/** Peer request to clear durable settings. */
|
||||
@@ -14,11 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import com.squareup.okhttp.internal.io.IoUtils;
|
||||
import com.squareup.okhttp.internal.io.Streams;
|
||||
import static com.squareup.okhttp.internal.net.spdy.Threads.newThreadFactory;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -113,11 +111,11 @@ public final class SpdyConnection implements Closeable {
|
||||
|
||||
String prefix = builder.client ? "Spdy Client " : "Spdy Server ";
|
||||
readExecutor = new ThreadPoolExecutor(1, 1, 60, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<Runnable>(), newThreadFactory(prefix + "Reader", false));
|
||||
new SynchronousQueue<Runnable>(), Threads.newThreadFactory(prefix + "Reader", false));
|
||||
writeExecutor = new ThreadPoolExecutor(0, 1, 60, TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<Runnable>(), newThreadFactory(prefix + "Writer", false));
|
||||
new LinkedBlockingQueue<Runnable>(), Threads.newThreadFactory(prefix + "Writer", false));
|
||||
callbackExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<Runnable>(), newThreadFactory(prefix + "Callbacks", false));
|
||||
new SynchronousQueue<Runnable>(), Threads.newThreadFactory(prefix + "Callbacks", false));
|
||||
|
||||
readExecutor.execute(new Reader());
|
||||
}
|
||||
@@ -314,7 +312,7 @@ public final class SpdyConnection implements Closeable {
|
||||
writeExecutor.shutdown();
|
||||
callbackExecutor.shutdown();
|
||||
readExecutor.shutdown();
|
||||
IoUtils.closeAll(spdyReader, spdyWriter);
|
||||
Util.closeAll(spdyReader, spdyWriter);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
@@ -359,7 +357,7 @@ public final class SpdyConnection implements Closeable {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
IoUtils.closeQuietly(SpdyConnection.this);
|
||||
Util.closeQuietly(SpdyConnection.this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,7 +366,7 @@ public final class SpdyConnection implements Closeable {
|
||||
SpdyStream dataStream = getStream(streamId);
|
||||
if (dataStream == null) {
|
||||
writeSynResetLater(streamId, SpdyStream.RST_INVALID_STREAM);
|
||||
Streams.skipByReading(in, length);
|
||||
Util.skipByReading(in, length);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
@@ -377,7 +375,7 @@ public final class SpdyConnection implements Closeable {
|
||||
dataStream.receiveFin();
|
||||
}
|
||||
} catch (ProtocolException e) {
|
||||
Streams.skipByReading(in, length);
|
||||
Util.skipByReading(in, length);
|
||||
dataStream.closeLater(SpdyStream.RST_FLOW_CONTROL_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import com.squareup.okhttp.internal.io.IoUtils;
|
||||
import com.squareup.okhttp.internal.io.Streams;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import java.io.Closeable;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
@@ -170,7 +169,7 @@ final class SpdyReader implements Closeable {
|
||||
// Limit the inflater input stream to only those bytes in the Name/Value block.
|
||||
final InputStream throttleStream = new InputStream() {
|
||||
@Override public int read() throws IOException {
|
||||
return Streams.readSingleByte(this);
|
||||
return Util.readSingleByte(this);
|
||||
}
|
||||
|
||||
@Override public int read(byte[] buffer, int offset, int byteCount) throws IOException {
|
||||
@@ -229,7 +228,7 @@ final class SpdyReader implements Closeable {
|
||||
private String readString() throws DataFormatException, IOException {
|
||||
int length = nameValueBlockIn.readShort();
|
||||
byte[] bytes = new byte[length];
|
||||
Streams.readFully(nameValueBlockIn, bytes);
|
||||
Util.readFully(nameValueBlockIn, bytes);
|
||||
return new String(bytes, 0, length, "UTF-8");
|
||||
}
|
||||
|
||||
@@ -269,7 +268,7 @@ final class SpdyReader implements Closeable {
|
||||
}
|
||||
|
||||
@Override public void close() throws IOException {
|
||||
IoUtils.closeAll(in, nameValueBlockIn);
|
||||
Util.closeAll(in, nameValueBlockIn);
|
||||
}
|
||||
|
||||
public interface Handler {
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import static com.squareup.okhttp.internal.Util.checkOffsetAndCount;
|
||||
import static com.squareup.okhttp.internal.Util.pokeInt;
|
||||
import com.squareup.okhttp.internal.io.Streams;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InterruptedIOException;
|
||||
@@ -367,7 +367,7 @@ public final class SpdyStream {
|
||||
}
|
||||
|
||||
@Override public int read() throws IOException {
|
||||
return Streams.readSingleByte(this);
|
||||
return Util.readSingleByte(this);
|
||||
}
|
||||
|
||||
@Override public int read(byte[] b, int offset, int count) throws IOException {
|
||||
@@ -463,7 +463,7 @@ public final class SpdyStream {
|
||||
|
||||
// Discard data received after the stream is finished. It's probably a benign race.
|
||||
if (finished) {
|
||||
Streams.skipByReading(in, byteCount);
|
||||
Util.skipByReading(in, byteCount);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -472,7 +472,7 @@ public final class SpdyStream {
|
||||
// writes will be blocked until reads complete.
|
||||
if (pos < limit) {
|
||||
int firstCopyCount = Math.min(byteCount, buffer.length - limit);
|
||||
Streams.readFully(in, buffer, limit, firstCopyCount);
|
||||
Util.readFully(in, buffer, limit, firstCopyCount);
|
||||
limit += firstCopyCount;
|
||||
byteCount -= firstCopyCount;
|
||||
if (limit == buffer.length) {
|
||||
@@ -480,7 +480,7 @@ public final class SpdyStream {
|
||||
}
|
||||
}
|
||||
if (byteCount > 0) {
|
||||
Streams.readFully(in, buffer, limit, byteCount);
|
||||
Util.readFully(in, buffer, limit, byteCount);
|
||||
limit += byteCount;
|
||||
}
|
||||
|
||||
@@ -549,7 +549,7 @@ public final class SpdyStream {
|
||||
private boolean finished;
|
||||
|
||||
@Override public void write(int b) throws IOException {
|
||||
Streams.writeSingleByte(this, b);
|
||||
Util.writeSingleByte(this, b);
|
||||
}
|
||||
|
||||
@Override public void write(byte[] bytes, int offset, int count) throws IOException {
|
||||
@@ -14,10 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import com.squareup.okhttp.internal.Platform;
|
||||
import com.squareup.okhttp.internal.io.IoUtils;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.Closeable;
|
||||
import java.io.DataOutputStream;
|
||||
@@ -168,6 +168,6 @@ final class SpdyWriter implements Closeable {
|
||||
}
|
||||
|
||||
@Override public void close() throws IOException {
|
||||
IoUtils.closeAll(out, nameValueBlockOut);
|
||||
Util.closeAll(out, nameValueBlockOut);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.io;
|
||||
package com.squareup.okhttp.internal;
|
||||
|
||||
import static com.squareup.okhttp.internal.io.DiskLruCache.JOURNAL_FILE;
|
||||
import static com.squareup.okhttp.internal.io.DiskLruCache.MAGIC;
|
||||
import static com.squareup.okhttp.internal.io.DiskLruCache.VERSION_1;
|
||||
import com.squareup.okhttp.internal.DiskLruCache;
|
||||
import static com.squareup.okhttp.internal.DiskLruCache.JOURNAL_FILE;
|
||||
import static com.squareup.okhttp.internal.DiskLruCache.MAGIC;
|
||||
import static com.squareup.okhttp.internal.DiskLruCache.VERSION_1;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.ssl;
|
||||
package com.squareup.okhttp.internal;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.io;
|
||||
package com.squareup.okhttp.internal;
|
||||
|
||||
import static com.squareup.okhttp.internal.Util.US_ASCII;
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -30,7 +30,7 @@ public final class StrictLineReaderTest {
|
||||
InputStream refStream = createTestInputStream();
|
||||
while (true) {
|
||||
try {
|
||||
String refLine = Streams.readAsciiLine(refStream);
|
||||
String refLine = Util.readAsciiLine(refStream);
|
||||
try {
|
||||
String line = lineReader.readLine();
|
||||
if (!refLine.equals(line)) {
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import java.io.BufferedReader;
|
||||
@@ -14,14 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.google.mockwebserver.MockResponse;
|
||||
import com.google.mockwebserver.MockWebServer;
|
||||
import com.google.mockwebserver.RecordedRequest;
|
||||
import static com.google.mockwebserver.SocketPolicy.DISCONNECT_AT_END;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.internal.net.ssl.SslContextBuilder;
|
||||
import com.squareup.okhttp.internal.http.HttpResponseCache;
|
||||
import com.squareup.okhttp.internal.SslContextBuilder;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
@@ -13,8 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.internal.http.RawHeaders;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -13,13 +13,13 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.Address;
|
||||
import com.squareup.okhttp.Connection;
|
||||
import com.squareup.okhttp.ConnectionPool;
|
||||
import com.squareup.okhttp.internal.net.Dns;
|
||||
import com.squareup.okhttp.internal.net.ssl.SslContextBuilder;
|
||||
import com.squareup.okhttp.internal.Dns;
|
||||
import com.squareup.okhttp.internal.SslContextBuilder;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.google.mockwebserver.MockResponse;
|
||||
import com.google.mockwebserver.MockWebServer;
|
||||
@@ -25,7 +25,8 @@ import static com.google.mockwebserver.SocketPolicy.DISCONNECT_AT_START;
|
||||
import static com.google.mockwebserver.SocketPolicy.SHUTDOWN_INPUT_AT_END;
|
||||
import static com.google.mockwebserver.SocketPolicy.SHUTDOWN_OUTPUT_AT_END;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.internal.net.ssl.SslContextBuilder;
|
||||
import com.squareup.okhttp.internal.http.HttpResponseCache;
|
||||
import com.squareup.okhttp.internal.SslContextBuilder;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.http;
|
||||
package com.squareup.okhttp.internal.http;
|
||||
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import java.io.IOException;
|
||||
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import com.squareup.okhttp.internal.io.Streams;
|
||||
import com.squareup.okhttp.internal.Util;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -187,7 +187,7 @@ public final class MockSpdyPeer {
|
||||
this.flags = flags;
|
||||
this.streamId = streamId;
|
||||
this.data = new byte[length];
|
||||
Streams.readFully(in, this.data);
|
||||
Util.readFully(in, this.data);
|
||||
}
|
||||
|
||||
@Override public void rstStream(int flags, int streamId, int statusCode) {
|
||||
@@ -13,14 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import static com.squareup.okhttp.internal.net.spdy.Settings.DOWNLOAD_BANDWIDTH;
|
||||
import static com.squareup.okhttp.internal.net.spdy.Settings.DOWNLOAD_RETRANS_RATE;
|
||||
import static com.squareup.okhttp.internal.net.spdy.Settings.MAX_CONCURRENT_STREAMS;
|
||||
import static com.squareup.okhttp.internal.net.spdy.Settings.PERSISTED;
|
||||
import static com.squareup.okhttp.internal.net.spdy.Settings.PERSIST_VALUE;
|
||||
import static com.squareup.okhttp.internal.net.spdy.Settings.UPLOAD_BANDWIDTH;
|
||||
import com.squareup.okhttp.internal.spdy.Settings;
|
||||
import static com.squareup.okhttp.internal.spdy.Settings.DOWNLOAD_BANDWIDTH;
|
||||
import static com.squareup.okhttp.internal.spdy.Settings.DOWNLOAD_RETRANS_RATE;
|
||||
import static com.squareup.okhttp.internal.spdy.Settings.MAX_CONCURRENT_STREAMS;
|
||||
import static com.squareup.okhttp.internal.spdy.Settings.PERSISTED;
|
||||
import static com.squareup.okhttp.internal.spdy.Settings.PERSIST_VALUE;
|
||||
import static com.squareup.okhttp.internal.spdy.Settings.UPLOAD_BANDWIDTH;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -14,23 +14,23 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import static com.squareup.okhttp.internal.Util.UTF_8;
|
||||
import static com.squareup.okhttp.internal.net.spdy.Settings.PERSIST_VALUE;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyConnection.FLAG_FIN;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyConnection.FLAG_UNIDIRECTIONAL;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyConnection.TYPE_DATA;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyConnection.TYPE_GOAWAY;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyConnection.TYPE_NOOP;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyConnection.TYPE_PING;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyConnection.TYPE_RST_STREAM;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyConnection.TYPE_SYN_REPLY;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyConnection.TYPE_SYN_STREAM;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyStream.RST_FLOW_CONTROL_ERROR;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyStream.RST_INVALID_STREAM;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyStream.RST_PROTOCOL_ERROR;
|
||||
import static com.squareup.okhttp.internal.net.spdy.SpdyStream.RST_REFUSED_STREAM;
|
||||
import static com.squareup.okhttp.internal.spdy.Settings.PERSIST_VALUE;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyConnection.FLAG_FIN;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyConnection.FLAG_UNIDIRECTIONAL;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyConnection.TYPE_DATA;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyConnection.TYPE_GOAWAY;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyConnection.TYPE_NOOP;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyConnection.TYPE_PING;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyConnection.TYPE_RST_STREAM;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyConnection.TYPE_SYN_REPLY;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyConnection.TYPE_SYN_STREAM;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyStream.RST_FLOW_CONTROL_ERROR;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyStream.RST_INVALID_STREAM;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyStream.RST_PROTOCOL_ERROR;
|
||||
import static com.squareup.okhttp.internal.spdy.SpdyStream.RST_REFUSED_STREAM;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.squareup.okhttp.internal.net.spdy;
|
||||
package com.squareup.okhttp.internal.spdy;
|
||||
|
||||
import com.squareup.okhttp.internal.net.ssl.SslContextBuilder;
|
||||
import com.squareup.okhttp.internal.SslContextBuilder;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
Reference in New Issue
Block a user