diff --git a/.gitignore b/.gitignore
index 0f182a034..133735f7b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,22 @@
-*.class
+.classpath
+.project
+.settings
+eclipsebin
-# Package Files #
-*.jar
-*.war
-*.ear
+bin
+gen
+build
+out
+lib
+
+target
+pom.xml.*
+release.properties
+
+.idea
+*.iml
+classes
+
+obj
+
+.DS_Store
diff --git a/README.md b/README.md
index 6f33b50dc..4d7f6f01c 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,57 @@
okhttp
======
-An HTTP+SPDY client for Android and Java applications
\ No newline at end of file
+An HTTP+SPDY client for Android and Java applications.
+
+
+Download
+--------
+
+Downloadable .jars can be found on the [GitHub download page][1].
+
+You can also depend on the .jar through Maven:
+
+```xml
+
+ com.squareup
+ okhttp
+ (insert latest version)
+
+```
+
+
+Contributing
+------------
+
+If you would like to contribute code to OKHTTP you can do so through GitHub by
+forking the repository and sending a pull request.
+
+When submitting code, please make every effort to follow existing conventions
+and style in order to keep the code as readable as possible. Please also make
+sure your code compiles by running `mvn clean verify`. Checkstyle failures
+during compilation indicate errors in your style and can be viewed in the
+`checkstyle-result.xml` file.
+
+Before your code can be accepted into the project you must also sign the
+[Individual Contributor License Agreement (CLA)][2].
+
+
+License
+-------
+
+ 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.
+
+
+
+ [1]: http://github.com/square/okhttp/downloads
+ [2]: https://spreadsheets.google.com/spreadsheet/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1
\ No newline at end of file
diff --git a/checkstyle.xml b/checkstyle.xml
new file mode 100644
index 000000000..5cf5e522c
--- /dev/null
+++ b/checkstyle.xml
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 08ec17872..a2977d991 100644
--- a/pom.xml
+++ b/pom.xml
@@ -96,6 +96,7 @@
org.sonatype.plugins
jarjar-maven-plugin
+ 1.5
package
@@ -118,7 +119,9 @@
+ org.apache.maven.plugins
maven-surefire-plugin
+ 2.9
-Xbootclasspath/p:${settings.localRepository}/org/mortbay/jetty/npn/npn-boot/${npn.version}/npn-boot-${npn.version}.jar
@@ -137,6 +140,7 @@
-->
org.apache.maven.plugins
maven-enforcer-plugin
+ 1.1
enforce-java
@@ -153,6 +157,24 @@
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 2.9.1
+
+ true
+ checkstyle.xml
+ **/OsConstants.java
+
+
+
+ verify
+
+ checkstyle
+
+
+
+
diff --git a/src/main/java/com/squareup/okhttp/OkHttpConnection.java b/src/main/java/com/squareup/okhttp/OkHttpConnection.java
index d98d330ec..c937d219b 100644
--- a/src/main/java/com/squareup/okhttp/OkHttpConnection.java
+++ b/src/main/java/com/squareup/okhttp/OkHttpConnection.java
@@ -328,157 +328,157 @@ public abstract class OkHttpConnection extends URLConnection {
// 4XX: client error
// 5XX: server error
/**
- * Numeric status code, 202: Accepted
+ * Numeric status code, 202: Accepted.
*/
public static final int HTTP_ACCEPTED = 202;
/**
- * Numeric status code, 502: Bad Gateway
+ * Numeric status code, 502: Bad Gateway.
*/
public static final int HTTP_BAD_GATEWAY = 502;
/**
- * Numeric status code, 405: Bad Method
+ * Numeric status code, 405: Bad Method.
*/
public static final int HTTP_BAD_METHOD = 405;
/**
- * Numeric status code, 400: Bad Request
+ * Numeric status code, 400: Bad Request.
*/
public static final int HTTP_BAD_REQUEST = 400;
/**
- * Numeric status code, 408: Client Timeout
+ * Numeric status code, 408: Client Timeout.
*/
public static final int HTTP_CLIENT_TIMEOUT = 408;
/**
- * Numeric status code, 409: Conflict
+ * Numeric status code, 409: Conflict.
*/
public static final int HTTP_CONFLICT = 409;
/**
- * Numeric status code, 201: Created
+ * Numeric status code, 201: Created.
*/
public static final int HTTP_CREATED = 201;
/**
- * Numeric status code, 413: Entity too large
+ * Numeric status code, 413: Entity too large.
*/
public static final int HTTP_ENTITY_TOO_LARGE = 413;
/**
- * Numeric status code, 403: Forbidden
+ * Numeric status code, 403: Forbidden.
*/
public static final int HTTP_FORBIDDEN = 403;
/**
- * Numeric status code, 504: Gateway timeout
+ * Numeric status code, 504: Gateway timeout.
*/
public static final int HTTP_GATEWAY_TIMEOUT = 504;
/**
- * Numeric status code, 410: Gone
+ * Numeric status code, 410: Gone.
*/
public static final int HTTP_GONE = 410;
/**
- * Numeric status code, 500: Internal error
+ * Numeric status code, 500: Internal error.
*/
public static final int HTTP_INTERNAL_ERROR = 500;
/**
- * Numeric status code, 411: Length required
+ * Numeric status code, 411: Length required.
*/
public static final int HTTP_LENGTH_REQUIRED = 411;
/**
- * Numeric status code, 301 Moved permanently
+ * Numeric status code, 301 Moved permanently.
*/
public static final int HTTP_MOVED_PERM = 301;
/**
- * Numeric status code, 302: Moved temporarily
+ * Numeric status code, 302: Moved temporarily.
*/
public static final int HTTP_MOVED_TEMP = 302;
/**
- * Numeric status code, 300: Multiple choices
+ * Numeric status code, 300: Multiple choices.
*/
public static final int HTTP_MULT_CHOICE = 300;
/**
- * Numeric status code, 204: No content
+ * Numeric status code, 204: No content.
*/
public static final int HTTP_NO_CONTENT = 204;
/**
- * Numeric status code, 406: Not acceptable
+ * Numeric status code, 406: Not acceptable.
*/
public static final int HTTP_NOT_ACCEPTABLE = 406;
/**
- * Numeric status code, 203: Not authoritative
+ * Numeric status code, 203: Not authoritative.
*/
public static final int HTTP_NOT_AUTHORITATIVE = 203;
/**
- * Numeric status code, 404: Not found
+ * Numeric status code, 404: Not found.
*/
public static final int HTTP_NOT_FOUND = 404;
/**
- * Numeric status code, 501: Not implemented
+ * Numeric status code, 501: Not implemented.
*/
public static final int HTTP_NOT_IMPLEMENTED = 501;
/**
- * Numeric status code, 304: Not modified
+ * Numeric status code, 304: Not modified.
*/
public static final int HTTP_NOT_MODIFIED = 304;
/**
- * Numeric status code, 200: OK
+ * Numeric status code, 200: OK.
*/
public static final int HTTP_OK = 200;
/**
- * Numeric status code, 206: Partial
+ * Numeric status code, 206: Partial.
*/
public static final int HTTP_PARTIAL = 206;
/**
- * Numeric status code, 402: Payment required
+ * Numeric status code, 402: Payment required.
*/
public static final int HTTP_PAYMENT_REQUIRED = 402;
/**
- * Numeric status code, 412: Precondition failed
+ * Numeric status code, 412: Precondition failed.
*/
public static final int HTTP_PRECON_FAILED = 412;
/**
- * Numeric status code, 407: Proxy authentication required
+ * Numeric status code, 407: Proxy authentication required.
*/
public static final int HTTP_PROXY_AUTH = 407;
/**
- * Numeric status code, 414: Request too long
+ * Numeric status code, 414: Request too long.
*/
public static final int HTTP_REQ_TOO_LONG = 414;
/**
- * Numeric status code, 205: Reset
+ * Numeric status code, 205: Reset.
*/
public static final int HTTP_RESET = 205;
/**
- * Numeric status code, 303: See other
+ * Numeric status code, 303: See other.
*/
public static final int HTTP_SEE_OTHER = 303;
/**
- * Numeric status code, 500: Internal error
+ * Numeric status code, 500: Internal error.
*
* @deprecated Use {@link #HTTP_INTERNAL_ERROR}
*/
@@ -495,22 +495,22 @@ public abstract class OkHttpConnection extends URLConnection {
public static final int HTTP_USE_PROXY = 305;
/**
- * Numeric status code, 401: Unauthorized
+ * Numeric status code, 401: Unauthorized.
*/
public static final int HTTP_UNAUTHORIZED = 401;
/**
- * Numeric status code, 415: Unsupported type
+ * Numeric status code, 415: Unsupported type.
*/
public static final int HTTP_UNSUPPORTED_TYPE = 415;
/**
- * Numeric status code, 503: Unavailable
+ * Numeric status code, 503: Unavailable.
*/
public static final int HTTP_UNAVAILABLE = 503;
/**
- * Numeric status code, 505: Version not supported
+ * Numeric status code, 505: Version not supported.
*/
public static final int HTTP_VERSION = 505;
@@ -687,8 +687,8 @@ public abstract class OkHttpConnection extends URLConnection {
}
}
// if none matches, then throw ProtocolException
- throw new ProtocolException("Unknown method '" + method + "'; must be one of " +
- Arrays.toString(PERMITTED_USER_METHODS));
+ throw new ProtocolException("Unknown method '" + method + "'; must be one of "
+ + Arrays.toString(PERMITTED_USER_METHODS));
}
/**
diff --git a/src/main/java/com/squareup/okhttp/OkHttpsConnection.java b/src/main/java/com/squareup/okhttp/OkHttpsConnection.java
index 7c7540c32..58f0b8ae0 100644
--- a/src/main/java/com/squareup/okhttp/OkHttpsConnection.java
+++ b/src/main/java/com/squareup/okhttp/OkHttpsConnection.java
@@ -112,7 +112,7 @@ public abstract class OkHttpsConnection extends OkHttpConnection {
private static SSLSocketFactory defaultSSLSocketFactory = (SSLSocketFactory) SSLSocketFactory
.getDefault();
-
+
public static OkHttpsConnection open(URL url) {
return new libcore.net.http.HttpsURLConnectionImpl(url, 443);
}
diff --git a/src/main/java/libcore/io/Base64.java b/src/main/java/libcore/io/Base64.java
index 153722192..867c76b9a 100644
--- a/src/main/java/libcore/io/Base64.java
+++ b/src/main/java/libcore/io/Base64.java
@@ -50,11 +50,11 @@ public final class Base64 {
byte chr;
// compute the number of the padding characters
// and adjust the length of the input
- for (;;len--) {
- chr = in[len-1];
+ for (;; len--) {
+ chr = in[len - 1];
// skip the neutral characters
- if ((chr == '\n') || (chr == '\r') ||
- (chr == ' ') || (chr == '\t')) {
+ if ((chr == '\n') || (chr == '\r')
+ || (chr == ' ') || (chr == '\t')) {
continue;
}
if (chr == '=') {
@@ -71,11 +71,11 @@ public final class Base64 {
int bits = 0;
// holds the value of the input quantum
int quantum = 0;
- for (int i=0; i= 'A') && (chr <= 'Z')) {
@@ -102,7 +102,7 @@ public final class Base64 {
}
// append the value to the quantum
quantum = (quantum << 6) | (byte) bits;
- if (inIndex%4 == 3) {
+ if (inIndex % 4 == 3) {
// 4 characters were read, so make the output:
out[outIndex++] = (byte) (quantum >> 16);
out[outIndex++] = (byte) (quantum >> 8);
@@ -112,7 +112,7 @@ public final class Base64 {
}
if (pad > 0) {
// adjust the quantum value according to the padding
- quantum = quantum << (6*pad);
+ quantum = quantum << (6 * pad);
// make output
out[outIndex++] = (byte) (quantum >> 16);
if (pad == 1) {
@@ -125,7 +125,7 @@ public final class Base64 {
return result;
}
- private static final byte[] map = new byte[]
+ private static final byte[] MAP = new byte[]
{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
@@ -137,22 +137,22 @@ public final class Base64 {
byte[] out = new byte[length];
int index = 0, end = in.length - in.length % 3;
for (int i = 0; i < end; i += 3) {
- out[index++] = map[(in[i] & 0xff) >> 2];
- out[index++] = map[((in[i] & 0x03) << 4) | ((in[i+1] & 0xff) >> 4)];
- out[index++] = map[((in[i+1] & 0x0f) << 2) | ((in[i+2] & 0xff) >> 6)];
- out[index++] = map[(in[i+2] & 0x3f)];
+ out[index++] = MAP[(in[i] & 0xff) >> 2];
+ out[index++] = MAP[((in[i] & 0x03) << 4) | ((in[i + 1] & 0xff) >> 4)];
+ out[index++] = MAP[((in[i + 1] & 0x0f) << 2) | ((in[i + 2] & 0xff) >> 6)];
+ out[index++] = MAP[(in[i + 2] & 0x3f)];
}
switch (in.length % 3) {
case 1:
- out[index++] = map[(in[end] & 0xff) >> 2];
- out[index++] = map[(in[end] & 0x03) << 4];
+ out[index++] = MAP[(in[end] & 0xff) >> 2];
+ out[index++] = MAP[(in[end] & 0x03) << 4];
out[index++] = '=';
out[index++] = '=';
break;
case 2:
- out[index++] = map[(in[end] & 0xff) >> 2];
- out[index++] = map[((in[end] & 0x03) << 4) | ((in[end+1] & 0xff) >> 4)];
- out[index++] = map[((in[end+1] & 0x0f) << 2)];
+ out[index++] = MAP[(in[end] & 0xff) >> 2];
+ out[index++] = MAP[((in[end] & 0x03) << 4) | ((in[end + 1] & 0xff) >> 4)];
+ out[index++] = MAP[((in[end + 1] & 0x0f) << 2)];
out[index++] = '=';
break;
}
diff --git a/src/main/java/libcore/io/DiskLruCache.java b/src/main/java/libcore/io/DiskLruCache.java
index b6c3638cd..691183426 100644
--- a/src/main/java/libcore/io/DiskLruCache.java
+++ b/src/main/java/libcore/io/DiskLruCache.java
@@ -293,7 +293,7 @@ public final class DiskLruCache implements Closeable {
*/
private void processJournal() throws IOException {
deleteIfExists(journalFileTmp);
- for (Iterator i = lruEntries.values().iterator(); i.hasNext(); ) {
+ for (Iterator i = lruEntries.values().iterator(); i.hasNext();) {
Entry entry = i.next();
if (entry.currentEditor == null) {
for (int t = 0; t < valueCount; t++) {
@@ -499,8 +499,8 @@ public final class DiskLruCache implements Closeable {
* and eliminate at least 2000 ops.
*/
private boolean journalRebuildRequired() {
- final int REDUNDANT_OP_COMPACT_THRESHOLD = 2000;
- return redundantOpCount >= REDUNDANT_OP_COMPACT_THRESHOLD
+ final int redundantOpCompactThreshold = 2000;
+ return redundantOpCount >= redundantOpCompactThreshold
&& redundantOpCount >= lruEntries.size();
}
@@ -735,7 +735,7 @@ public final class DiskLruCache implements Closeable {
completeEdit(this, false);
}
- private class FaultHidingOutputStream extends FilterOutputStream {
+ private final class FaultHidingOutputStream extends FilterOutputStream {
private FaultHidingOutputStream(OutputStream out) {
super(out);
}
@@ -780,7 +780,7 @@ public final class DiskLruCache implements Closeable {
/** Lengths of this entry's files. */
private final long[] lengths;
- /** True if this entry has ever been published */
+ /** True if this entry has ever been published. */
private boolean readable;
/** The ongoing edit or null if this entry is not being edited. */
diff --git a/src/main/java/libcore/io/Streams.java b/src/main/java/libcore/io/Streams.java
index 194b77510..1ad2356ba 100644
--- a/src/main/java/libcore/io/Streams.java
+++ b/src/main/java/libcore/io/Streams.java
@@ -29,7 +29,8 @@ import libcore.util.Libcore;
public final class Streams {
private static AtomicReference skipBuffer = new AtomicReference();
- private Streams() {}
+ private Streams() {
+ }
/**
* Implements InputStream.read(int) in terms of InputStream.read(byte[], int, int).
diff --git a/src/main/java/libcore/net/MimeUtils.java b/src/main/java/libcore/net/MimeUtils.java
index f8038f0b6..65cfd0dd5 100644
--- a/src/main/java/libcore/net/MimeUtils.java
+++ b/src/main/java/libcore/net/MimeUtils.java
@@ -29,9 +29,9 @@ import java.util.Properties;
* Used to implement java.net.URLConnection and android.webkit.MimeTypeMap.
*/
public final class MimeUtils {
- private static final Map mimeTypeToExtensionMap = new HashMap();
+ private static final Map MIME_TYPE_TO_EXTENSION_MAP = new HashMap();
- private static final Map extensionToMimeTypeMap = new HashMap();
+ private static final Map EXTENSION_TO_MIME_TYPE_MAP = new HashMap();
static {
// The following table is based on /etc/mime.types data minus
@@ -364,10 +364,10 @@ public final class MimeUtils {
// the first extension is considered the most popular and is
// added first; we do not want to overwrite it later).
//
- if (!mimeTypeToExtensionMap.containsKey(mimeType)) {
- mimeTypeToExtensionMap.put(mimeType, extension);
+ if (!MIME_TYPE_TO_EXTENSION_MAP.containsKey(mimeType)) {
+ MIME_TYPE_TO_EXTENSION_MAP.put(mimeType, extension);
}
- extensionToMimeTypeMap.put(extension, mimeType);
+ EXTENSION_TO_MIME_TYPE_MAP.put(extension, mimeType);
}
private static InputStream getContentTypesPropertiesStream() {
@@ -437,7 +437,7 @@ public final class MimeUtils {
if (mimeType == null || mimeType.isEmpty()) {
return false;
}
- return mimeTypeToExtensionMap.containsKey(mimeType);
+ return MIME_TYPE_TO_EXTENSION_MAP.containsKey(mimeType);
}
/**
@@ -449,7 +449,7 @@ public final class MimeUtils {
if (extension == null || extension.isEmpty()) {
return null;
}
- return extensionToMimeTypeMap.get(extension);
+ return EXTENSION_TO_MIME_TYPE_MAP.get(extension);
}
/**
@@ -461,7 +461,7 @@ public final class MimeUtils {
if (extension == null || extension.isEmpty()) {
return false;
}
- return extensionToMimeTypeMap.containsKey(extension);
+ return EXTENSION_TO_MIME_TYPE_MAP.containsKey(extension);
}
/**
@@ -475,6 +475,6 @@ public final class MimeUtils {
if (mimeType == null || mimeType.isEmpty()) {
return null;
}
- return mimeTypeToExtensionMap.get(mimeType);
+ return MIME_TYPE_TO_EXTENSION_MAP.get(mimeType);
}
}
diff --git a/src/main/java/libcore/net/http/AbstractHttpOutputStream.java b/src/main/java/libcore/net/http/AbstractHttpOutputStream.java
index 1e1b47b09..145bc5056 100644
--- a/src/main/java/libcore/net/http/AbstractHttpOutputStream.java
+++ b/src/main/java/libcore/net/http/AbstractHttpOutputStream.java
@@ -29,7 +29,7 @@ abstract class AbstractHttpOutputStream extends OutputStream {
protected boolean closed;
@Override public final void write(int data) throws IOException {
- write(new byte[] { (byte) data });
+ write(new byte[] {(byte) data});
}
protected final void checkNotClosed() throws IOException {
diff --git a/src/main/java/libcore/net/http/HeaderParser.java b/src/main/java/libcore/net/http/HeaderParser.java
index 26e77b64c..4a4ac2af6 100644
--- a/src/main/java/libcore/net/http/HeaderParser.java
+++ b/src/main/java/libcore/net/http/HeaderParser.java
@@ -160,4 +160,7 @@ final class HeaderParser {
return -1;
}
}
+
+ private HeaderParser() {
+ }
}
diff --git a/src/main/java/libcore/net/http/HttpDate.java b/src/main/java/libcore/net/http/HttpDate.java
index a41cf8193..41ae5ef62 100644
--- a/src/main/java/libcore/net/http/HttpDate.java
+++ b/src/main/java/libcore/net/http/HttpDate.java
@@ -88,4 +88,7 @@ public final class HttpDate {
public static String format(Date value) {
return STANDARD_DATE_FORMAT.get().format(value);
}
+
+ private HttpDate() {
+ }
}
diff --git a/src/main/java/libcore/net/http/HttpEngine.java b/src/main/java/libcore/net/http/HttpEngine.java
index 6fd15a422..9acb72f07 100644
--- a/src/main/java/libcore/net/http/HttpEngine.java
+++ b/src/main/java/libcore/net/http/HttpEngine.java
@@ -120,7 +120,7 @@ public class HttpEngine {
final RequestHeaders requestHeaders;
- /** Null until a response is received from the network or the cache */
+ /** Null until a response is received from the network or the cache. */
ResponseHeaders responseHeaders;
/*
diff --git a/src/main/java/libcore/net/http/HttpTransport.java b/src/main/java/libcore/net/http/HttpTransport.java
index e47f32bdc..869e8035e 100644
--- a/src/main/java/libcore/net/http/HttpTransport.java
+++ b/src/main/java/libcore/net/http/HttpTransport.java
@@ -260,7 +260,7 @@ final class HttpTransport implements Transport {
/**
* An HTTP body with a fixed length known in advance.
*/
- private static class FixedLengthOutputStream extends AbstractHttpOutputStream {
+ private static final class FixedLengthOutputStream extends AbstractHttpOutputStream {
private final OutputStream socketOut;
private int bytesRemaining;
@@ -303,15 +303,15 @@ final class HttpTransport implements Transport {
* buffered until {@code maxChunkLength} bytes are ready, at which point the
* chunk is written and the buffer is cleared.
*/
- private static class ChunkedOutputStream extends AbstractHttpOutputStream {
- private static final byte[] CRLF = { '\r', '\n' };
+ private static final class ChunkedOutputStream extends AbstractHttpOutputStream {
+ private static final byte[] CRLF = {'\r', '\n'};
private static final byte[] HEX_DIGITS = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
};
- private static final byte[] FINAL_CHUNK = new byte[] { '0', '\r', '\n', '\r', '\n' };
+ private static final byte[] FINAL_CHUNK = new byte[] {'0', '\r', '\n', '\r', '\n'};
- /** Scratch space for up to 8 hex digits, and then a constant CRLF */
- private final byte[] hex = { 0, 0, 0, 0, 0, 0, 0, 0, '\r', '\n' };
+ /** Scratch space for up to 8 hex digits, and then a constant CRLF. */
+ private final byte[] hex = {0, 0, 0, 0, 0, 0, 0, 0, '\r', '\n'};
private final OutputStream socketOut;
private final int maxChunkLength;
@@ -554,7 +554,7 @@ final class HttpTransport implements Transport {
/**
* An HTTP payload terminated by the end of the socket stream.
*/
- private static class UnknownLengthHttpInputStream extends AbstractHttpInputStream {
+ private static final class UnknownLengthHttpInputStream extends AbstractHttpInputStream {
private boolean inputExhausted;
private UnknownLengthHttpInputStream(InputStream is, CacheRequest cacheRequest,
diff --git a/src/main/java/libcore/net/http/HttpURLConnectionImpl.java b/src/main/java/libcore/net/http/HttpURLConnectionImpl.java
index dda9b95eb..dcf58c220 100644
--- a/src/main/java/libcore/net/http/HttpURLConnectionImpl.java
+++ b/src/main/java/libcore/net/http/HttpURLConnectionImpl.java
@@ -24,7 +24,6 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.net.Authenticator;
import java.net.HttpRetryException;
-import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
@@ -463,12 +462,12 @@ public class HttpURLConnectionImpl extends OkHttpConnection {
return defaultPort;
}
- /** @see HttpURLConnection#setFixedLengthStreamingMode(int) */
+ /** @see java.net.HttpURLConnection#setFixedLengthStreamingMode(int) */
final int getFixedContentLength() {
return fixedContentLength;
}
- /** @see HttpURLConnection#setChunkedStreamingMode(int) */
+ /** @see java.net.HttpURLConnection#setChunkedStreamingMode(int) */
final int getChunkLength() {
return chunkLength;
}
diff --git a/src/main/java/libcore/net/http/HttpsURLConnectionImpl.java b/src/main/java/libcore/net/http/HttpsURLConnectionImpl.java
index 49d8d6f3b..0ea33f7c1 100644
--- a/src/main/java/libcore/net/http/HttpsURLConnectionImpl.java
+++ b/src/main/java/libcore/net/http/HttpsURLConnectionImpl.java
@@ -39,7 +39,7 @@ import javax.net.ssl.SSLSocketFactory;
public final class HttpsURLConnectionImpl extends OkHttpsConnection {
- /** HttpUrlConnectionDelegate allows reuse of HttpURLConnectionImpl */
+ /** HttpUrlConnectionDelegate allows reuse of HttpURLConnectionImpl. */
private final HttpUrlConnectionDelegate delegate;
public HttpsURLConnectionImpl(URL url, int port) {
@@ -397,7 +397,7 @@ public final class HttpsURLConnectionImpl extends OkHttpsConnection {
}
}
- private static class HttpsEngine extends HttpEngine {
+ private static final class HttpsEngine extends HttpEngine {
/**
* Local stash of HttpsEngine.connection.sslSocket for answering
diff --git a/src/main/java/libcore/net/http/RawHeaders.java b/src/main/java/libcore/net/http/RawHeaders.java
index 4f9ec9e06..cd1b44fc9 100644
--- a/src/main/java/libcore/net/http/RawHeaders.java
+++ b/src/main/java/libcore/net/http/RawHeaders.java
@@ -68,7 +68,8 @@ public final class RawHeaders {
private int responseCode = -1;
private String responseMessage;
- public RawHeaders() {}
+ public RawHeaders() {
+ }
public RawHeaders(RawHeaders copyFrom) {
namesAndValues.addAll(copyFrom.namesAndValues);
@@ -112,9 +113,9 @@ public final class RawHeaders {
String version = null;
for (int i = 0; i < namesAndValues.size(); i += 2) {
String name = namesAndValues.get(i);
- if (name.equals("status")) {
+ if ("status".equals(name)) {
status = namesAndValues.get(i + 1);
- } else if (name.equals("version")) {
+ } else if ("version".equals(name)) {
version = namesAndValues.get(i + 1);
}
}
@@ -374,7 +375,7 @@ public final class RawHeaders {
for (int i = 0; i < nameValueBlock.size(); i += 2) {
String name = nameValueBlock.get(i);
String values = nameValueBlock.get(i + 1);
- for (int start = 0; start < values.length(); ) {
+ for (int start = 0; start < values.length();) {
int end = values.indexOf(start, '\0');
if (end == -1) {
end = values.length();
diff --git a/src/main/java/libcore/net/http/RequestHeaders.java b/src/main/java/libcore/net/http/RequestHeaders.java
index 3b536ce58..a84437e16 100644
--- a/src/main/java/libcore/net/http/RequestHeaders.java
+++ b/src/main/java/libcore/net/http/RequestHeaders.java
@@ -67,15 +67,15 @@ public final class RequestHeaders {
HeaderParser.CacheControlHandler handler = new HeaderParser.CacheControlHandler() {
@Override public void handle(String directive, String parameter) {
- if (directive.equalsIgnoreCase("no-cache")) {
+ if ("no-cache".equalsIgnoreCase(directive)) {
noCache = true;
- } else if (directive.equalsIgnoreCase("max-age")) {
+ } else if ("max-age".equalsIgnoreCase(directive)) {
maxAgeSeconds = HeaderParser.parseSeconds(parameter);
- } else if (directive.equalsIgnoreCase("max-stale")) {
+ } else if ("max-stale".equalsIgnoreCase(directive)) {
maxStaleSeconds = HeaderParser.parseSeconds(parameter);
- } else if (directive.equalsIgnoreCase("min-fresh")) {
+ } else if ("min-fresh".equalsIgnoreCase(directive)) {
minFreshSeconds = HeaderParser.parseSeconds(parameter);
- } else if (directive.equalsIgnoreCase("only-if-cached")) {
+ } else if ("only-if-cached".equalsIgnoreCase(directive)) {
onlyIfCached = true;
}
}
@@ -87,7 +87,7 @@ public final class RequestHeaders {
if ("Cache-Control".equalsIgnoreCase(fieldName)) {
HeaderParser.parseCacheControl(value, handler);
} else if ("Pragma".equalsIgnoreCase(fieldName)) {
- if (value.equalsIgnoreCase("no-cache")) {
+ if ("no-cache".equalsIgnoreCase(value)) {
noCache = true;
}
} else if ("If-None-Match".equalsIgnoreCase(fieldName)) {
diff --git a/src/main/java/libcore/net/http/ResponseHeaders.java b/src/main/java/libcore/net/http/ResponseHeaders.java
index d2311f350..0776bb9d2 100644
--- a/src/main/java/libcore/net/http/ResponseHeaders.java
+++ b/src/main/java/libcore/net/http/ResponseHeaders.java
@@ -116,17 +116,17 @@ public final class ResponseHeaders {
HeaderParser.CacheControlHandler handler = new HeaderParser.CacheControlHandler() {
@Override public void handle(String directive, String parameter) {
- if (directive.equalsIgnoreCase("no-cache")) {
+ if ("no-cache".equalsIgnoreCase(directive)) {
noCache = true;
- } else if (directive.equalsIgnoreCase("no-store")) {
+ } else if ("no-store".equalsIgnoreCase(directive)) {
noStore = true;
- } else if (directive.equalsIgnoreCase("max-age")) {
+ } else if ("max-age".equalsIgnoreCase(directive)) {
maxAgeSeconds = HeaderParser.parseSeconds(parameter);
- } else if (directive.equalsIgnoreCase("s-maxage")) {
+ } else if ("s-maxage".equalsIgnoreCase(directive)) {
sMaxAgeSeconds = HeaderParser.parseSeconds(parameter);
- } else if (directive.equalsIgnoreCase("public")) {
+ } else if ("public".equalsIgnoreCase(directive)) {
isPublic = true;
- } else if (directive.equalsIgnoreCase("must-revalidate")) {
+ } else if ("must-revalidate".equalsIgnoreCase(directive)) {
mustRevalidate = true;
}
}
@@ -146,7 +146,7 @@ public final class ResponseHeaders {
} else if ("ETag".equalsIgnoreCase(fieldName)) {
etag = value;
} else if ("Pragma".equalsIgnoreCase(fieldName)) {
- if (value.equalsIgnoreCase("no-cache")) {
+ if ("no-cache".equalsIgnoreCase(value)) {
noCache = true;
}
} else if ("Age".equalsIgnoreCase(fieldName)) {
@@ -468,7 +468,7 @@ public final class ResponseHeaders {
for (int i = 0; i < headers.length(); i++) {
String fieldName = headers.getFieldName(i);
String value = headers.getValue(i);
- if (fieldName.equals("Warning") && value.startsWith("1")) {
+ if ("Warning".equals(fieldName) && value.startsWith("1")) {
continue; // drop 100-level freshness warnings
}
if (!isEndToEnd(fieldName) || network.headers.get(fieldName) == null) {
@@ -491,13 +491,13 @@ public final class ResponseHeaders {
* defined by RFC 2616, 13.5.1.
*/
private static boolean isEndToEnd(String fieldName) {
- return !fieldName.equalsIgnoreCase("Connection")
- && !fieldName.equalsIgnoreCase("Keep-Alive")
- && !fieldName.equalsIgnoreCase("Proxy-Authenticate")
- && !fieldName.equalsIgnoreCase("Proxy-Authorization")
- && !fieldName.equalsIgnoreCase("TE")
- && !fieldName.equalsIgnoreCase("Trailers")
- && !fieldName.equalsIgnoreCase("Transfer-Encoding")
- && !fieldName.equalsIgnoreCase("Upgrade");
+ return !"Connection".equalsIgnoreCase(fieldName)
+ && !"Keep-Alive".equalsIgnoreCase(fieldName)
+ && !"Proxy-Authenticate".equalsIgnoreCase(fieldName)
+ && !"Proxy-Authorization".equalsIgnoreCase(fieldName)
+ && !"TE".equalsIgnoreCase(fieldName)
+ && !"Trailers".equalsIgnoreCase(fieldName)
+ && !"Transfer-Encoding".equalsIgnoreCase(fieldName)
+ && !"Upgrade".equalsIgnoreCase(fieldName);
}
}
diff --git a/src/main/java/libcore/net/spdy/SpdyConnection.java b/src/main/java/libcore/net/spdy/SpdyConnection.java
index daef8f5f6..44194f125 100644
--- a/src/main/java/libcore/net/spdy/SpdyConnection.java
+++ b/src/main/java/libcore/net/spdy/SpdyConnection.java
@@ -55,7 +55,7 @@ public final class SpdyConnection implements Closeable {
static final int TYPE_HEADERS = 0x08;
static final int VERSION = 2;
- /** Guarded by this */
+ /** Guarded by this. */
private int nextStreamId;
private final SpdyReader spdyReader;
private final SpdyWriter spdyWriter;
@@ -273,10 +273,11 @@ public final class SpdyConnection implements Closeable {
case SpdyConnection.TYPE_GOAWAY:
case SpdyConnection.TYPE_HEADERS:
throw new UnsupportedOperationException();
- }
- // TODO: throw IOException here?
- return false;
+ default:
+ // TODO: throw IOException here?
+ return false;
+ }
}
}
}
diff --git a/src/main/java/libcore/net/spdy/SpdyServer.java b/src/main/java/libcore/net/spdy/SpdyServer.java
index 190c549a8..4a3f827a5 100644
--- a/src/main/java/libcore/net/spdy/SpdyServer.java
+++ b/src/main/java/libcore/net/spdy/SpdyServer.java
@@ -52,7 +52,7 @@ public final class SpdyServer implements IncomingStreamHandler {
String path = null;
for (int i = 0; i < requestHeaders.size(); i += 2) {
String s = requestHeaders.get(i);
- if (s.equals("url")) {
+ if ("url".equals(s)) {
path = requestHeaders.get(i + 1);
break;
}
diff --git a/src/main/java/libcore/net/spdy/Threads.java b/src/main/java/libcore/net/spdy/Threads.java
index cb29a519f..a1fbf67de 100644
--- a/src/main/java/libcore/net/spdy/Threads.java
+++ b/src/main/java/libcore/net/spdy/Threads.java
@@ -26,4 +26,7 @@ final class Threads {
}
};
}
+
+ private Threads() {
+ }
}
diff --git a/src/main/java/libcore/util/BasicLruCache.java b/src/main/java/libcore/util/BasicLruCache.java
index 14124381b..b5f6fdf47 100644
--- a/src/main/java/libcore/util/BasicLruCache.java
+++ b/src/main/java/libcore/util/BasicLruCache.java
@@ -93,7 +93,8 @@ public class BasicLruCache {
* Called for entries that have reached the tail of the least recently used
* queue and are be removed. The default implementation does nothing.
*/
- protected void entryEvicted(K key, V value) {}
+ protected void entryEvicted(K key, V value) {
+ }
/**
* Called after a cache miss to compute a value for the corresponding key.
diff --git a/src/main/java/libcore/util/Charsets.java b/src/main/java/libcore/util/Charsets.java
index c8b2c348b..95848ee45 100644
--- a/src/main/java/libcore/util/Charsets.java
+++ b/src/main/java/libcore/util/Charsets.java
@@ -27,7 +27,7 @@ import java.nio.charset.Charset;
*
* @hide internal use only
*/
-public class Charsets {
+public final class Charsets {
/**
* A cheap and type-safe constant for the ISO-8859-1 Charset.
*/
diff --git a/src/main/java/libcore/util/CollectionUtils.java b/src/main/java/libcore/util/CollectionUtils.java
index 45c2ae6ab..45edf4f89 100644
--- a/src/main/java/libcore/util/CollectionUtils.java
+++ b/src/main/java/libcore/util/CollectionUtils.java
@@ -17,14 +17,14 @@
package libcore.util;
import java.lang.ref.Reference;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
public final class CollectionUtils {
- private CollectionUtils() {}
+ private CollectionUtils() {
+ }
/**
* Returns an iterator over the values referenced by the elements of {@code
diff --git a/src/main/java/libcore/util/EmptyArray.java b/src/main/java/libcore/util/EmptyArray.java
index 6c9987829..0f919c50c 100644
--- a/src/main/java/libcore/util/EmptyArray.java
+++ b/src/main/java/libcore/util/EmptyArray.java
@@ -17,7 +17,8 @@
package libcore.util;
public final class EmptyArray {
- private EmptyArray() {}
+ private EmptyArray() {
+ }
public static final boolean[] BOOLEAN = new boolean[0];
public static final byte[] BYTE = new byte[0];
diff --git a/src/main/java/libcore/util/Libcore.java b/src/main/java/libcore/util/Libcore.java
index 4ccda8294..63ab921fa 100644
--- a/src/main/java/libcore/util/Libcore.java
+++ b/src/main/java/libcore/util/Libcore.java
@@ -18,11 +18,14 @@ import org.eclipse.jetty.npn.NextProtoNego;
* APIs for interacting with Android's core library. This mostly emulates the
* Android core library for interoperability with other runtimes.
*/
-public class Libcore {
-
+public final class Libcore {
+
+ private Libcore() {
+ }
+
public static void makeTlsTolerant(SSLSocket socket, String socketHost, boolean tlsTolerant) {
if (!tlsTolerant) {
- socket.setEnabledProtocols(new String [] { "SSLv3" });
+ socket.setEnabledProtocols(new String[] {"SSLv3"});
return;
}
@@ -31,7 +34,7 @@ public class Libcore {
"org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl");
if (openSslSocketClass.isInstance(socket)) {
openSslSocketClass.getMethod("setEnabledCompressionMethods", String[].class)
- .invoke(socket, new Object[] { new String[]{"ZLIB"}});
+ .invoke(socket, new Object[] {new String[] {"ZLIB"}});
openSslSocketClass.getMethod("setUseSessionTickets", boolean.class)
.invoke(socket, true);
openSslSocketClass.getMethod("setHostname", String.class)
@@ -47,7 +50,7 @@ public class Libcore {
throw new AssertionError(e);
}
}
-
+
public static byte[] getNpnSelectedProtocol(SSLSocket socket) {
// First try Android's APIs.
try {
@@ -93,7 +96,7 @@ public class Libcore {
// Next try OpenJDK.
List strings = new ArrayList();
- for (int i = 0; i < npnProtocols.length; ) {
+ for (int i = 0; i < npnProtocols.length;) {
int length = npnProtocols[i++];
strings.add(new String(npnProtocols, i, length, Charsets.US_ASCII));
i += length;
@@ -139,7 +142,7 @@ public class Libcore {
// okhttp-changed: was System.logw()
System.out.println(warning);
}
-
+
public static int getEffectivePort(URI uri) {
return getEffectivePort(uri.getScheme(), uri.getPort());
}
@@ -161,19 +164,19 @@ public class Libcore {
return -1;
}
}
-
+
public static void checkOffsetAndCount(int arrayLength, int offset, int count) {
if ((offset | count) < 0 || offset > arrayLength || arrayLength - offset < count) {
throw new ArrayIndexOutOfBoundsException();
}
}
-
+
public static void tagSocket(Socket socket) {
}
-
+
public static void untagSocket(Socket socket) throws SocketException {
}
-
+
public static URI toUriLenient(URL url) throws URISyntaxException {
return url.toURI(); // this isn't as good as the built-in toUriLenient
}
diff --git a/src/main/java/libcore/util/Objects.java b/src/main/java/libcore/util/Objects.java
index 781731677..050888d4a 100644
--- a/src/main/java/libcore/util/Objects.java
+++ b/src/main/java/libcore/util/Objects.java
@@ -17,7 +17,8 @@
package libcore.util;
public final class Objects {
- private Objects() {}
+ private Objects() {
+ }
/**
* Returns true if two possibly-null objects are equal.
diff --git a/src/main/java/libcore/util/SneakyThrow.java b/src/main/java/libcore/util/SneakyThrow.java
index 1911788cc..f5c077cec 100644
--- a/src/main/java/libcore/util/SneakyThrow.java
+++ b/src/main/java/libcore/util/SneakyThrow.java
@@ -53,7 +53,8 @@ package libcore.util;
* }
*/
public final class SneakyThrow {
- private SneakyThrow() {}
+ private SneakyThrow() {
+ }
public static void sneakyThrow(Throwable t) {
SneakyThrow.sneakyThrow2(t);