diff --git a/src/main/java/com/squareup/okhttp/Connection.java b/src/main/java/com/squareup/okhttp/Connection.java index 6103db68d..61122355b 100644 --- a/src/main/java/com/squareup/okhttp/Connection.java +++ b/src/main/java/com/squareup/okhttp/Connection.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/ConnectionPool.java b/src/main/java/com/squareup/okhttp/ConnectionPool.java index 65f03281f..afb0e58e1 100644 --- a/src/main/java/com/squareup/okhttp/ConnectionPool.java +++ b/src/main/java/com/squareup/okhttp/ConnectionPool.java @@ -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); } /** diff --git a/src/main/java/com/squareup/okhttp/OkHttpClient.java b/src/main/java/com/squareup/okhttp/OkHttpClient.java index dcc0a537b..22054872b 100644 --- a/src/main/java/com/squareup/okhttp/OkHttpClient.java +++ b/src/main/java/com/squareup/okhttp/OkHttpClient.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/TunnelRequest.java b/src/main/java/com/squareup/okhttp/TunnelRequest.java index 254e836ba..39a820c2b 100644 --- a/src/main/java/com/squareup/okhttp/TunnelRequest.java +++ b/src/main/java/com/squareup/okhttp/TunnelRequest.java @@ -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 diff --git a/src/main/java/com/squareup/okhttp/internal/io/Base64.java b/src/main/java/com/squareup/okhttp/internal/Base64.java similarity index 99% rename from src/main/java/com/squareup/okhttp/internal/io/Base64.java rename to src/main/java/com/squareup/okhttp/internal/Base64.java index 16ced25bf..458e536d8 100644 --- a/src/main/java/com/squareup/okhttp/internal/io/Base64.java +++ b/src/main/java/com/squareup/okhttp/internal/Base64.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/io/DiskLruCache.java b/src/main/java/com/squareup/okhttp/internal/DiskLruCache.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/io/DiskLruCache.java rename to src/main/java/com/squareup/okhttp/internal/DiskLruCache.java index 0a029a8e3..96f6d96fa 100644 --- a/src/main/java/com/squareup/okhttp/internal/io/DiskLruCache.java +++ b/src/main/java/com/squareup/okhttp/internal/DiskLruCache.java @@ -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); } } diff --git a/src/main/java/com/squareup/okhttp/internal/net/Dns.java b/src/main/java/com/squareup/okhttp/internal/Dns.java similarity index 96% rename from src/main/java/com/squareup/okhttp/internal/net/Dns.java rename to src/main/java/com/squareup/okhttp/internal/Dns.java index 7b2c8e59a..37fa6092e 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/Dns.java +++ b/src/main/java/com/squareup/okhttp/internal/Dns.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/io/StrictLineReader.java b/src/main/java/com/squareup/okhttp/internal/StrictLineReader.java similarity index 99% rename from src/main/java/com/squareup/okhttp/internal/io/StrictLineReader.java rename to src/main/java/com/squareup/okhttp/internal/StrictLineReader.java index dccf16f0b..9011b2c6a 100644 --- a/src/main/java/com/squareup/okhttp/internal/io/StrictLineReader.java +++ b/src/main/java/com/squareup/okhttp/internal/StrictLineReader.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/Util.java b/src/main/java/com/squareup/okhttp/internal/Util.java index 9c4f0e874..f47362c02 100644 --- a/src/main/java/com/squareup/okhttp/internal/Util.java +++ b/src/main/java/com/squareup/okhttp/internal/Util.java @@ -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 skipBuffer = new AtomicReference(); 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. + * + *

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(); + } } diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/AbstractHttpInputStream.java b/src/main/java/com/squareup/okhttp/internal/http/AbstractHttpInputStream.java similarity index 96% rename from src/main/java/com/squareup/okhttp/internal/net/http/AbstractHttpInputStream.java rename to src/main/java/com/squareup/okhttp/internal/http/AbstractHttpInputStream.java index dca5505fe..d915552fb 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/AbstractHttpInputStream.java +++ b/src/main/java/com/squareup/okhttp/internal/http/AbstractHttpInputStream.java @@ -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 { diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/AbstractHttpOutputStream.java b/src/main/java/com/squareup/okhttp/internal/http/AbstractHttpOutputStream.java similarity index 96% rename from src/main/java/com/squareup/okhttp/internal/net/http/AbstractHttpOutputStream.java rename to src/main/java/com/squareup/okhttp/internal/http/AbstractHttpOutputStream.java index 336ecc3f1..5d835ccc6 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/AbstractHttpOutputStream.java +++ b/src/main/java/com/squareup/okhttp/internal/http/AbstractHttpOutputStream.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/HeaderParser.java b/src/main/java/com/squareup/okhttp/internal/http/HeaderParser.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/HeaderParser.java rename to src/main/java/com/squareup/okhttp/internal/http/HeaderParser.java index 051dc7ee6..0dd096e7a 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/HeaderParser.java +++ b/src/main/java/com/squareup/okhttp/internal/http/HeaderParser.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.squareup.okhttp.internal.net.http; +package com.squareup.okhttp.internal.http; final class HeaderParser { diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/HttpAuthenticator.java b/src/main/java/com/squareup/okhttp/internal/http/HttpAuthenticator.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/HttpAuthenticator.java rename to src/main/java/com/squareup/okhttp/internal/http/HttpAuthenticator.java index 4345f2d93..70104a5a9 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/HttpAuthenticator.java +++ b/src/main/java/com/squareup/okhttp/internal/http/HttpAuthenticator.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/HttpDate.java b/src/main/java/com/squareup/okhttp/internal/http/HttpDate.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/HttpDate.java rename to src/main/java/com/squareup/okhttp/internal/http/HttpDate.java index 60f1f3559..41f03fafc 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/HttpDate.java +++ b/src/main/java/com/squareup/okhttp/internal/http/HttpDate.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/HttpEngine.java b/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/HttpEngine.java rename to src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java index 01512efc7..22483ac35 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/HttpEngine.java +++ b/src/main/java/com/squareup/okhttp/internal/http/HttpEngine.java @@ -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); } } diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/HttpResponseCache.java b/src/main/java/com/squareup/okhttp/internal/http/HttpResponseCache.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/HttpResponseCache.java rename to src/main/java/com/squareup/okhttp/internal/http/HttpResponseCache.java index 757dd65fb..4bdd8fc27 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/HttpResponseCache.java +++ b/src/main/java/com/squareup/okhttp/internal/http/HttpResponseCache.java @@ -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) { diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/HttpTransport.java b/src/main/java/com/squareup/okhttp/internal/http/HttpTransport.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/HttpTransport.java rename to src/main/java/com/squareup/okhttp/internal/http/HttpTransport.java index e47cd78f8..1c73423bc 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/HttpTransport.java +++ b/src/main/java/com/squareup/okhttp/internal/http/HttpTransport.java @@ -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); diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/HttpURLConnectionImpl.java b/src/main/java/com/squareup/okhttp/internal/http/HttpURLConnectionImpl.java similarity index 99% rename from src/main/java/com/squareup/okhttp/internal/net/http/HttpURLConnectionImpl.java rename to src/main/java/com/squareup/okhttp/internal/http/HttpURLConnectionImpl.java index 6470e2e6e..aec7b4e75 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/HttpURLConnectionImpl.java +++ b/src/main/java/com/squareup/okhttp/internal/http/HttpURLConnectionImpl.java @@ -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); } diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/HttpsURLConnectionImpl.java b/src/main/java/com/squareup/okhttp/internal/http/HttpsURLConnectionImpl.java similarity index 99% rename from src/main/java/com/squareup/okhttp/internal/net/http/HttpsURLConnectionImpl.java rename to src/main/java/com/squareup/okhttp/internal/http/HttpsURLConnectionImpl.java index dbf56986e..b0fc73b4d 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/HttpsURLConnectionImpl.java +++ b/src/main/java/com/squareup/okhttp/internal/http/HttpsURLConnectionImpl.java @@ -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(); diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/RawHeaders.java b/src/main/java/com/squareup/okhttp/internal/http/RawHeaders.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/RawHeaders.java rename to src/main/java/com/squareup/okhttp/internal/http/RawHeaders.java index a367c5ef0..edb14364a 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/RawHeaders.java +++ b/src/main/java/com/squareup/okhttp/internal/http/RawHeaders.java @@ -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); } } diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/RequestHeaders.java b/src/main/java/com/squareup/okhttp/internal/http/RequestHeaders.java similarity index 99% rename from src/main/java/com/squareup/okhttp/internal/net/http/RequestHeaders.java rename to src/main/java/com/squareup/okhttp/internal/http/RequestHeaders.java index b53fc8106..2c12b9583 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/RequestHeaders.java +++ b/src/main/java/com/squareup/okhttp/internal/http/RequestHeaders.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/ResponseHeaders.java b/src/main/java/com/squareup/okhttp/internal/http/ResponseHeaders.java similarity index 99% rename from src/main/java/com/squareup/okhttp/internal/net/http/ResponseHeaders.java rename to src/main/java/com/squareup/okhttp/internal/http/ResponseHeaders.java index 5e6962d10..d333d8b45 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/ResponseHeaders.java +++ b/src/main/java/com/squareup/okhttp/internal/http/ResponseHeaders.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/RetryableOutputStream.java b/src/main/java/com/squareup/okhttp/internal/http/RetryableOutputStream.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/RetryableOutputStream.java rename to src/main/java/com/squareup/okhttp/internal/http/RetryableOutputStream.java index 5cca27a52..a5c5842e9 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/RetryableOutputStream.java +++ b/src/main/java/com/squareup/okhttp/internal/http/RetryableOutputStream.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/RouteSelector.java b/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/RouteSelector.java rename to src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java index 81ddf96fd..5b0d079a2 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/RouteSelector.java +++ b/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/SpdyTransport.java b/src/main/java/com/squareup/okhttp/internal/http/SpdyTransport.java similarity index 95% rename from src/main/java/com/squareup/okhttp/internal/net/http/SpdyTransport.java rename to src/main/java/com/squareup/okhttp/internal/http/SpdyTransport.java index 4110fb796..28a47ab58 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/SpdyTransport.java +++ b/src/main/java/com/squareup/okhttp/internal/http/SpdyTransport.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/http/Transport.java b/src/main/java/com/squareup/okhttp/internal/http/Transport.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/http/Transport.java rename to src/main/java/com/squareup/okhttp/internal/http/Transport.java index 3d73c15f7..f1212d5bc 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/http/Transport.java +++ b/src/main/java/com/squareup/okhttp/internal/http/Transport.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/io/IoUtils.java b/src/main/java/com/squareup/okhttp/internal/io/IoUtils.java deleted file mode 100644 index d8fa785a0..000000000 --- a/src/main/java/com/squareup/okhttp/internal/io/IoUtils.java +++ /dev/null @@ -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); - } - } - } -} diff --git a/src/main/java/com/squareup/okhttp/internal/io/Streams.java b/src/main/java/com/squareup/okhttp/internal/io/Streams.java deleted file mode 100644 index 4352d9642..000000000 --- a/src/main/java/com/squareup/okhttp/internal/io/Streams.java +++ /dev/null @@ -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 skipBuffer = new AtomicReference(); - - 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. - * - *

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(); - } -} diff --git a/src/main/java/com/squareup/okhttp/internal/net/spdy/IncomingStreamHandler.java b/src/main/java/com/squareup/okhttp/internal/spdy/IncomingStreamHandler.java similarity index 96% rename from src/main/java/com/squareup/okhttp/internal/net/spdy/IncomingStreamHandler.java rename to src/main/java/com/squareup/okhttp/internal/spdy/IncomingStreamHandler.java index 25012d560..fc554f410 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/spdy/IncomingStreamHandler.java +++ b/src/main/java/com/squareup/okhttp/internal/spdy/IncomingStreamHandler.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/spdy/Ping.java b/src/main/java/com/squareup/okhttp/internal/spdy/Ping.java similarity index 97% rename from src/main/java/com/squareup/okhttp/internal/net/spdy/Ping.java rename to src/main/java/com/squareup/okhttp/internal/spdy/Ping.java index dc712809e..1fc3979c2 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/spdy/Ping.java +++ b/src/main/java/com/squareup/okhttp/internal/spdy/Ping.java @@ -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; diff --git a/src/main/java/com/squareup/okhttp/internal/net/spdy/Settings.java b/src/main/java/com/squareup/okhttp/internal/spdy/Settings.java similarity index 99% rename from src/main/java/com/squareup/okhttp/internal/net/spdy/Settings.java rename to src/main/java/com/squareup/okhttp/internal/spdy/Settings.java index 2f9a5a399..f4136e6c0 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/spdy/Settings.java +++ b/src/main/java/com/squareup/okhttp/internal/spdy/Settings.java @@ -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. */ diff --git a/src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyConnection.java b/src/main/java/com/squareup/okhttp/internal/spdy/SpdyConnection.java similarity index 95% rename from src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyConnection.java rename to src/main/java/com/squareup/okhttp/internal/spdy/SpdyConnection.java index 1050f4a23..a67e3e83f 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyConnection.java +++ b/src/main/java/com/squareup/okhttp/internal/spdy/SpdyConnection.java @@ -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(), newThreadFactory(prefix + "Reader", false)); + new SynchronousQueue(), Threads.newThreadFactory(prefix + "Reader", false)); writeExecutor = new ThreadPoolExecutor(0, 1, 60, TimeUnit.SECONDS, - new LinkedBlockingQueue(), newThreadFactory(prefix + "Writer", false)); + new LinkedBlockingQueue(), Threads.newThreadFactory(prefix + "Writer", false)); callbackExecutor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, TimeUnit.SECONDS, - new SynchronousQueue(), newThreadFactory(prefix + "Callbacks", false)); + new SynchronousQueue(), 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); } } diff --git a/src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyReader.java b/src/main/java/com/squareup/okhttp/internal/spdy/SpdyReader.java similarity index 97% rename from src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyReader.java rename to src/main/java/com/squareup/okhttp/internal/spdy/SpdyReader.java index c8608f89d..98fc97545 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyReader.java +++ b/src/main/java/com/squareup/okhttp/internal/spdy/SpdyReader.java @@ -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 { diff --git a/src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyStream.java b/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java similarity index 98% rename from src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyStream.java rename to src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java index f059c8932..5c3d9711a 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyStream.java +++ b/src/main/java/com/squareup/okhttp/internal/spdy/SpdyStream.java @@ -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 { diff --git a/src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyWriter.java b/src/main/java/com/squareup/okhttp/internal/spdy/SpdyWriter.java similarity index 97% rename from src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyWriter.java rename to src/main/java/com/squareup/okhttp/internal/spdy/SpdyWriter.java index 6428b9ee4..8cd6ae00e 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/spdy/SpdyWriter.java +++ b/src/main/java/com/squareup/okhttp/internal/spdy/SpdyWriter.java @@ -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); } } diff --git a/src/main/java/com/squareup/okhttp/internal/net/spdy/Threads.java b/src/main/java/com/squareup/okhttp/internal/spdy/Threads.java similarity index 95% rename from src/main/java/com/squareup/okhttp/internal/net/spdy/Threads.java rename to src/main/java/com/squareup/okhttp/internal/spdy/Threads.java index c7e577045..ef1d4f3df 100644 --- a/src/main/java/com/squareup/okhttp/internal/net/spdy/Threads.java +++ b/src/main/java/com/squareup/okhttp/internal/spdy/Threads.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/io/DiskLruCacheTest.java b/src/test/java/com/squareup/okhttp/internal/DiskLruCacheTest.java similarity index 98% rename from src/test/java/com/squareup/okhttp/internal/io/DiskLruCacheTest.java rename to src/test/java/com/squareup/okhttp/internal/DiskLruCacheTest.java index c77cdd9a3..160ec7856 100644 --- a/src/test/java/com/squareup/okhttp/internal/io/DiskLruCacheTest.java +++ b/src/test/java/com/squareup/okhttp/internal/DiskLruCacheTest.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/net/ssl/SslContextBuilder.java b/src/test/java/com/squareup/okhttp/internal/SslContextBuilder.java similarity index 99% rename from src/test/java/com/squareup/okhttp/internal/net/ssl/SslContextBuilder.java rename to src/test/java/com/squareup/okhttp/internal/SslContextBuilder.java index ec3345e70..c0a520ce8 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/ssl/SslContextBuilder.java +++ b/src/test/java/com/squareup/okhttp/internal/SslContextBuilder.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/io/StrictLineReaderTest.java b/src/test/java/com/squareup/okhttp/internal/StrictLineReaderTest.java similarity index 96% rename from src/test/java/com/squareup/okhttp/internal/io/StrictLineReaderTest.java rename to src/test/java/com/squareup/okhttp/internal/StrictLineReaderTest.java index dc52e9e49..5f85b5262 100644 --- a/src/test/java/com/squareup/okhttp/internal/io/StrictLineReaderTest.java +++ b/src/test/java/com/squareup/okhttp/internal/StrictLineReaderTest.java @@ -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)) { diff --git a/src/test/java/com/squareup/okhttp/internal/net/http/ExternalSpdyExample.java b/src/test/java/com/squareup/okhttp/internal/http/ExternalSpdyExample.java similarity index 97% rename from src/test/java/com/squareup/okhttp/internal/net/http/ExternalSpdyExample.java rename to src/test/java/com/squareup/okhttp/internal/http/ExternalSpdyExample.java index 4624b9d08..f93c4939b 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/http/ExternalSpdyExample.java +++ b/src/test/java/com/squareup/okhttp/internal/http/ExternalSpdyExample.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/net/http/HttpResponseCacheTest.java b/src/test/java/com/squareup/okhttp/internal/http/HttpResponseCacheTest.java similarity index 99% rename from src/test/java/com/squareup/okhttp/internal/net/http/HttpResponseCacheTest.java rename to src/test/java/com/squareup/okhttp/internal/http/HttpResponseCacheTest.java index dfc0f8173..841647dd5 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/http/HttpResponseCacheTest.java +++ b/src/test/java/com/squareup/okhttp/internal/http/HttpResponseCacheTest.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/net/http/RawHeadersTest.java b/src/test/java/com/squareup/okhttp/internal/http/RawHeadersTest.java similarity index 96% rename from src/test/java/com/squareup/okhttp/internal/net/http/RawHeadersTest.java rename to src/test/java/com/squareup/okhttp/internal/http/RawHeadersTest.java index ccee0a04e..377227f30 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/http/RawHeadersTest.java +++ b/src/test/java/com/squareup/okhttp/internal/http/RawHeadersTest.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/net/http/RouteSelectorTest.java b/src/test/java/com/squareup/okhttp/internal/http/RouteSelectorTest.java similarity index 99% rename from src/test/java/com/squareup/okhttp/internal/net/http/RouteSelectorTest.java rename to src/test/java/com/squareup/okhttp/internal/http/RouteSelectorTest.java index dd75bc8f1..14642e950 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/http/RouteSelectorTest.java +++ b/src/test/java/com/squareup/okhttp/internal/http/RouteSelectorTest.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/net/http/URLConnectionTest.java b/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java similarity index 99% rename from src/test/java/com/squareup/okhttp/internal/net/http/URLConnectionTest.java rename to src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java index b94eb62b8..4d1518973 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/http/URLConnectionTest.java +++ b/src/test/java/com/squareup/okhttp/internal/http/URLConnectionTest.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/net/http/URLEncodingTest.java b/src/test/java/com/squareup/okhttp/internal/http/URLEncodingTest.java similarity index 99% rename from src/test/java/com/squareup/okhttp/internal/net/http/URLEncodingTest.java rename to src/test/java/com/squareup/okhttp/internal/http/URLEncodingTest.java index ad54cb797..0f8edcab7 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/http/URLEncodingTest.java +++ b/src/test/java/com/squareup/okhttp/internal/http/URLEncodingTest.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/net/spdy/MockSpdyPeer.java b/src/test/java/com/squareup/okhttp/internal/spdy/MockSpdyPeer.java similarity index 98% rename from src/test/java/com/squareup/okhttp/internal/net/spdy/MockSpdyPeer.java rename to src/test/java/com/squareup/okhttp/internal/spdy/MockSpdyPeer.java index ba70085f8..652786aed 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/spdy/MockSpdyPeer.java +++ b/src/test/java/com/squareup/okhttp/internal/spdy/MockSpdyPeer.java @@ -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) { diff --git a/src/test/java/com/squareup/okhttp/internal/net/spdy/SettingsTest.java b/src/test/java/com/squareup/okhttp/internal/spdy/SettingsTest.java similarity index 90% rename from src/test/java/com/squareup/okhttp/internal/net/spdy/SettingsTest.java rename to src/test/java/com/squareup/okhttp/internal/spdy/SettingsTest.java index bc276862c..1c444932a 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/spdy/SettingsTest.java +++ b/src/test/java/com/squareup/okhttp/internal/spdy/SettingsTest.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/net/spdy/SpdyConnectionTest.java b/src/test/java/com/squareup/okhttp/internal/spdy/SpdyConnectionTest.java similarity index 96% rename from src/test/java/com/squareup/okhttp/internal/net/spdy/SpdyConnectionTest.java rename to src/test/java/com/squareup/okhttp/internal/spdy/SpdyConnectionTest.java index 0df67b6ba..d51fed7bc 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/spdy/SpdyConnectionTest.java +++ b/src/test/java/com/squareup/okhttp/internal/spdy/SpdyConnectionTest.java @@ -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; diff --git a/src/test/java/com/squareup/okhttp/internal/net/spdy/SpdyServer.java b/src/test/java/com/squareup/okhttp/internal/spdy/SpdyServer.java similarity index 98% rename from src/test/java/com/squareup/okhttp/internal/net/spdy/SpdyServer.java rename to src/test/java/com/squareup/okhttp/internal/spdy/SpdyServer.java index db4e91afd..1b5574dca 100644 --- a/src/test/java/com/squareup/okhttp/internal/net/spdy/SpdyServer.java +++ b/src/test/java/com/squareup/okhttp/internal/spdy/SpdyServer.java @@ -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;