From 3aa9c1fd33570c4d2086a3aad5b2a00495548a09 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 13 Aug 2018 16:58:10 -0600 Subject: [PATCH] - Always use blocks - Add missing serial version ID (default 1L) - Camel-case names. - Don't nest in else clause unnecessarily. - Remove declared exceptions that are not thrown (but don't break BC.) - Remove redundant superinterface - Access static methods directly - Better local var names. --- .../http/cache/HttpCacheStorageEntry.java | 1 + .../hc/client5/http/cache/Resource.java | 2 ++ .../http/cache/ResourceIOException.java | 2 ++ .../client5/http/impl/cache/CachingExec.java | 4 +-- .../http/impl/cache/CombinedEntity.java | 10 +++--- .../http/impl/cache/FileResourceFactory.java | 4 +-- .../MemcachedOperationTimeoutException.java | 2 ++ .../hc/client5/http/fluent/Request.java | 8 ++--- ...AbstractHttpAsyncClientAuthentication.java | 2 ++ .../examples/ClientConnectionRelease.java | 4 +-- .../methods/ConfigurableHttpRequest.java | 1 + .../http/async/methods/SimpleHttpRequest.java | 1 + .../async/methods/SimpleHttpResponse.java | 1 + .../http/entity/DecompressingEntity.java | 10 +++--- .../http/entity/GzipCompressingEntity.java | 6 ++-- .../http/entity/mime/MultipartFormEntity.java | 12 +++---- .../hc/client5/http/impl/ConnPoolSupport.java | 9 +++-- .../http/impl/IdleConnectionEvictor.java | 4 +-- .../http/impl/async/LoggingIOSession.java | 14 ++++---- .../impl/classic/CloseableHttpResponse.java | 8 ++--- .../http/impl/classic/RequestEntityProxy.java | 4 +-- .../impl/classic/ResponseEntityProxy.java | 6 ++-- .../io/BasicHttpClientConnectionManager.java | 11 +++--- .../DefaultManagedHttpClientConnection.java | 24 ++++++------- .../ManagedHttpClientConnectionFactory.java | 20 +++++------ .../PoolingHttpClientConnectionManager.java | 4 +-- .../hc/client5/http/io/LeaseRequest.java | 4 +-- .../hc/client5/http/auth/TestCredentials.java | 24 ++++++------- .../http/entity/TestDecompressingEntity.java | 4 +-- ...TestAbstractHttpClientResponseHandler.java | 6 ++-- .../classic/TestBasicResponseHandler.java | 6 ++-- .../http/impl/classic/TestConnectExec.java | 12 +++---- .../http/impl/classic/TestProtocolExec.java | 30 ++++++++-------- .../http/impl/classic/TestRedirectExec.java | 18 +++++----- .../classic/TestResponseEntityWrapper.java | 30 ++++++++-------- .../impl/cookie/TestBasicClientCookie.java | 12 +++---- .../impl/cookie/TestBasicCookieStore.java | 34 +++++++++---------- 37 files changed, 181 insertions(+), 173 deletions(-) diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/HttpCacheStorageEntry.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/HttpCacheStorageEntry.java index d8060694b..5e3cb7a20 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/HttpCacheStorageEntry.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/HttpCacheStorageEntry.java @@ -32,6 +32,7 @@ import org.apache.hc.core5.util.Args; public final class HttpCacheStorageEntry implements Serializable { + private static final long serialVersionUID = 1L; private final String key; private final HttpCacheEntry content; diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/Resource.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/Resource.java index 66afc5384..1a986e22f 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/Resource.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/Resource.java @@ -38,6 +38,8 @@ import java.io.Serializable; */ public abstract class Resource implements Serializable { + private static final long serialVersionUID = 1L; + /** * Returns resource content as a {@link InputStream}. * diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/ResourceIOException.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/ResourceIOException.java index 6ec7feced..6b557c581 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/ResourceIOException.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/cache/ResourceIOException.java @@ -33,6 +33,8 @@ import java.io.IOException; */ public class ResourceIOException extends IOException { + private static final long serialVersionUID = 1L; + public ResourceIOException(final String message) { super(); } diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java index ebf5b7294..a5150944a 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CachingExec.java @@ -396,11 +396,11 @@ public class CachingExec extends CachingExecBase implements ExecChainHandler { final HttpEntity entity = backendResponse.getEntity(); if (entity != null) { buf = new ByteArrayBuffer(1024); - final InputStream instream = entity.getContent(); + final InputStream inStream = entity.getContent(); final byte[] tmp = new byte[2048]; long total = 0; int l; - while ((l = instream.read(tmp)) != -1) { + while ((l = inStream.read(tmp)) != -1) { buf.append(tmp, 0, l); total += l; if (total > cacheConfig.getMaxObjectSize()) { diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CombinedEntity.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CombinedEntity.java index 40ab70675..4d89a2e57 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CombinedEntity.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/CombinedEntity.java @@ -99,13 +99,13 @@ class CombinedEntity implements HttpEntity { } @Override - public void writeTo(final OutputStream outstream) throws IOException { - Args.notNull(outstream, "Output stream"); - try (InputStream instream = getContent()) { + public void writeTo(final OutputStream outStream) throws IOException { + Args.notNull(outStream, "Output stream"); + try (InputStream inStream = getContent()) { int l; final byte[] tmp = new byte[2048]; - while ((l = instream.read(tmp)) != -1) { - outstream.write(tmp, 0, l); + while ((l = inStream.read(tmp)) != -1) { + outStream.write(tmp, 0, l); } } } diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/FileResourceFactory.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/FileResourceFactory.java index d1c82322e..99f1ddb68 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/FileResourceFactory.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/FileResourceFactory.java @@ -79,9 +79,9 @@ public class FileResourceFactory implements ResourceFactory { final byte[] content, final int off, final int len) throws ResourceIOException { Args.notNull(requestId, "Request id"); final File file = generateUniqueCacheFile(requestId); - try (FileOutputStream outstream = new FileOutputStream(file)) { + try (FileOutputStream outStream = new FileOutputStream(file)) { if (content != null) { - outstream.write(content, off, len); + outStream.write(content, off, len); } } catch (final IOException ex) { throw new ResourceIOException(ex.getMessage(), ex); diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedOperationTimeoutException.java b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedOperationTimeoutException.java index aac711e1f..054753cbe 100644 --- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedOperationTimeoutException.java +++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/memcached/MemcachedOperationTimeoutException.java @@ -33,6 +33,8 @@ import org.apache.hc.client5.http.cache.ResourceIOException; */ class MemcachedOperationTimeoutException extends ResourceIOException { + private static final long serialVersionUID = 1L; + public MemcachedOperationTimeoutException(final Throwable cause) { super(cause != null ? cause.getMessage() : null, cause); } diff --git a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java index da9695d19..fca40f413 100644 --- a/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java +++ b/httpclient5-fluent/src/main/java/org/apache/hc/client5/http/fluent/Request.java @@ -359,12 +359,12 @@ public class Request { return body(new ByteArrayEntity(b, off, len, contentType)); } - public Request bodyStream(final InputStream instream) { - return body(new InputStreamEntity(instream, -1, null)); + public Request bodyStream(final InputStream inStream) { + return body(new InputStreamEntity(inStream, -1, null)); } - public Request bodyStream(final InputStream instream, final ContentType contentType) { - return body(new InputStreamEntity(instream, -1, contentType)); + public Request bodyStream(final InputStream inStream, final ContentType contentType) { + return body(new InputStreamEntity(inStream, -1, contentType)); } @Override diff --git a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthentication.java b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthentication.java index 817fb50c7..ff5c34068 100644 --- a/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthentication.java +++ b/httpclient5-testing/src/test/java/org/apache/hc/client5/testing/async/AbstractHttpAsyncClientAuthentication.java @@ -457,6 +457,8 @@ public abstract class AbstractHttpAsyncClientAuthentication 25 * 1024) { throw new ContentTooLongException("Content length is too long: " + this.contentLength); } - final ByteArrayOutputStream outstream = new ByteArrayOutputStream(); - writeTo(outstream); - outstream.flush(); - return new ByteArrayInputStream(outstream.toByteArray()); + final ByteArrayOutputStream outStream = new ByteArrayOutputStream(); + writeTo(outStream); + outStream.flush(); + return new ByteArrayInputStream(outStream.toByteArray()); } @Override - public void writeTo(final OutputStream outstream) throws IOException { - this.multipart.writeTo(outstream); + public void writeTo(final OutputStream outStream) throws IOException { + this.multipart.writeTo(outStream); } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java index 3de413c4d..a7d0da8ee 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/ConnPoolSupport.java @@ -39,11 +39,10 @@ public final class ConnPoolSupport { if (object == null) { return null; } - if (object instanceof Identifiable) { - return ((Identifiable) object).getId(); - } else { - return object.getClass().getSimpleName() + "-" + Integer.toHexString(System.identityHashCode(object)); - } + return object instanceof Identifiable + ? ((Identifiable) object).getId() + : object.getClass().getSimpleName() + "-" + + Integer.toHexString(System.identityHashCode(object)); } public static String formatStats( diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java index 5ba2d7850..d9b5364ae 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/IdleConnectionEvictor.java @@ -91,8 +91,8 @@ public final class IdleConnectionEvictor { return thread.isAlive(); } - public void awaitTermination(final long time, final TimeUnit tunit) throws InterruptedException { - thread.join((tunit != null ? tunit : TimeUnit.MILLISECONDS).toMillis(time)); + public void awaitTermination(final long time, final TimeUnit timeUnit) throws InterruptedException { + thread.join((timeUnit != null ? timeUnit : TimeUnit.MILLISECONDS).toMillis(time)); } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java index b9f4ede62..e8a8166e8 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/LoggingIOSession.java @@ -49,17 +49,17 @@ import org.slf4j.Logger; class LoggingIOSession implements TlsCapableIOSession { private final Logger log; - private final Wire wirelog; + private final Wire wireLog; private final String id; private final TlsCapableIOSession session; private final ByteChannel channel; - public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log, final Logger wirelog) { + public LoggingIOSession(final TlsCapableIOSession session, final String id, final Logger log, final Logger wireLog) { super(); this.session = session; this.id = id; this.log = log; - this.wirelog = new Wire(wirelog, this.id); + this.wireLog = new Wire(wireLog, this.id); this.channel = new LoggingByteChannel(); } @@ -246,12 +246,12 @@ class LoggingIOSession implements TlsCapableIOSession { if (log.isDebugEnabled()) { log.debug(id + " " + session + ": " + bytesRead + " bytes read"); } - if (bytesRead > 0 && wirelog.isEnabled()) { + if (bytesRead > 0 && wireLog.isEnabled()) { final ByteBuffer b = dst.duplicate(); final int p = b.position(); b.limit(p); b.position(p - bytesRead); - wirelog.input(b); + wireLog.input(b); } return bytesRead; } @@ -262,12 +262,12 @@ class LoggingIOSession implements TlsCapableIOSession { if (log.isDebugEnabled()) { log.debug(id + " " + session + ": " + byteWritten + " bytes written"); } - if (byteWritten > 0 && wirelog.isEnabled()) { + if (byteWritten > 0 && wireLog.isEnabled()) { final ByteBuffer b = src.duplicate(); final int p = b.position(); b.limit(p); b.position(p - byteWritten); - wirelog.output(b); + wireLog.output(b); } return byteWritten; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/CloseableHttpResponse.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/CloseableHttpResponse.java index 146b2d7b7..a132d9cb9 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/CloseableHttpResponse.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/CloseableHttpResponse.java @@ -53,11 +53,9 @@ public final class CloseableHttpResponse implements ClassicHttpResponse { if (response == null) { return null; } - if (response instanceof CloseableHttpResponse) { - return (CloseableHttpResponse) response; - } else { - return new CloseableHttpResponse(response, null); - } + return response instanceof CloseableHttpResponse + ? (CloseableHttpResponse) response + : new CloseableHttpResponse(response, null); } CloseableHttpResponse(final ClassicHttpResponse response, final ExecRuntime execRuntime) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RequestEntityProxy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RequestEntityProxy.java index d2c45378c..4a9b81a82 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RequestEntityProxy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/RequestEntityProxy.java @@ -106,9 +106,9 @@ class RequestEntityProxy implements HttpEntity { } @Override - public void writeTo(final OutputStream outstream) throws IOException { + public void writeTo(final OutputStream outStream) throws IOException { consumed = true; - original.writeTo(outstream); + original.writeTo(outStream); } @Override diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ResponseEntityProxy.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ResponseEntityProxy.java index 6dcdcad59..9dc55046b 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ResponseEntityProxy.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ResponseEntityProxy.java @@ -92,10 +92,10 @@ class ResponseEntityProxy extends HttpEntityWrapper implements EofSensorWatcher } @Override - public void writeTo(final OutputStream outstream) throws IOException { + public void writeTo(final OutputStream outStream) throws IOException { try { - if (outstream != null) { - super.writeTo(outstream); + if (outStream != null) { + super.writeTo(outStream); } releaseConnection(); } catch (final IOException | RuntimeException ex) { diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java index 924ec3c0b..478c47aaa 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/BasicHttpClientConnectionManager.java @@ -189,7 +189,7 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan @Override public ConnectionEndpoint get( final long timeout, - final TimeUnit tunit) throws InterruptedException, ExecutionException, TimeoutException { + final TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { try { return new InternalConnectionEndpoint(route, getConnection(route, state)); } catch (final IOException ex) { @@ -246,9 +246,8 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan private InternalConnectionEndpoint cast(final ConnectionEndpoint endpoint) { if (endpoint instanceof InternalConnectionEndpoint) { return (InternalConnectionEndpoint) endpoint; - } else { - throw new IllegalStateException("Unexpected endpoint class: " + endpoint.getClass()); } + throw new IllegalStateException("Unexpected endpoint class: " + endpoint.getClass()); } @Override @@ -341,13 +340,13 @@ public class BasicHttpClientConnectionManager implements HttpClientConnectionMan } } - public synchronized void closeIdle(final long idletime, final TimeUnit tunit) { - Args.notNull(tunit, "Time unit"); + public synchronized void closeIdle(final long idletime, final TimeUnit timeUnit) { + Args.notNull(timeUnit, "Time unit"); if (this.closed.get()) { return; } if (!this.leased) { - long time = tunit.toMillis(idletime); + long time = timeUnit.toMillis(idletime); if (time < 0) { time = 0; } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java index 6e5d78cca..ef2cd9099 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultManagedHttpClientConnection.java @@ -63,8 +63,8 @@ final class DefaultManagedHttpClientConnection extends DefaultBHttpClientConnection implements ManagedHttpClientConnection, Identifiable { private final Logger log = LoggerFactory.getLogger(DefaultManagedHttpClientConnection.class); - private final Logger headerlog = LoggerFactory.getLogger("org.apache.hc.client5.http.headers"); - private final Logger wirelog = LoggerFactory.getLogger("org.apache.hc.client5.http.wire"); + private final Logger headerLog = LoggerFactory.getLogger("org.apache.hc.client5.http.headers"); + private final Logger wireLog = LoggerFactory.getLogger("org.apache.hc.client5.http.wire"); private final String id; private final AtomicBoolean closed; @@ -73,14 +73,14 @@ final class DefaultManagedHttpClientConnection public DefaultManagedHttpClientConnection( final String id, - final CharsetDecoder chardecoder, - final CharsetEncoder charencoder, + final CharsetDecoder charDecoder, + final CharsetEncoder charEncoder, final H1Config h1Config, final ContentLengthStrategy incomingContentStrategy, final ContentLengthStrategy outgoingContentStrategy, final HttpMessageWriterFactory requestWriterFactory, final HttpMessageParserFactory responseParserFactory) { - super(h1Config, chardecoder, charencoder, incomingContentStrategy, outgoingContentStrategy, requestWriterFactory, responseParserFactory); + super(h1Config, charDecoder, charEncoder, incomingContentStrategy, outgoingContentStrategy, requestWriterFactory, responseParserFactory); this.id = id; this.closed = new AtomicBoolean(); } @@ -152,28 +152,28 @@ final class DefaultManagedHttpClientConnection @Override public void bind(final Socket socket) throws IOException { - super.bind(this.wirelog.isDebugEnabled() ? new LoggingSocketHolder(socket, this.id, this.wirelog) : new SocketHolder(socket)); + super.bind(this.wireLog.isDebugEnabled() ? new LoggingSocketHolder(socket, this.id, this.wireLog) : new SocketHolder(socket)); socketTimeout = socket.getSoTimeout(); } @Override protected void onResponseReceived(final ClassicHttpResponse response) { - if (response != null && this.headerlog.isDebugEnabled()) { - this.headerlog.debug(this.id + " << " + new StatusLine(response)); + if (response != null && this.headerLog.isDebugEnabled()) { + this.headerLog.debug(this.id + " << " + new StatusLine(response)); final Header[] headers = response.getAllHeaders(); for (final Header header : headers) { - this.headerlog.debug(this.id + " << " + header.toString()); + this.headerLog.debug(this.id + " << " + header.toString()); } } } @Override protected void onRequestSubmitted(final ClassicHttpRequest request) { - if (request != null && this.headerlog.isDebugEnabled()) { - this.headerlog.debug(this.id + " >> " + new RequestLine(request)); + if (request != null && this.headerLog.isDebugEnabled()) { + this.headerLog.debug(this.id + " >> " + new RequestLine(request)); final Header[] headers = request.getAllHeaders(); for (final Header header : headers) { - this.headerlog.debug(this.id + " >> " + header.toString()); + this.headerLog.debug(this.id + " >> " + header.toString()); } } } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java index e016182e5..c2a19e50a 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/ManagedHttpClientConnectionFactory.java @@ -108,26 +108,26 @@ public class ManagedHttpClientConnectionFactory implements HttpConnectionFactory @Override public ManagedHttpClientConnection createConnection(final Socket socket) throws IOException { - CharsetDecoder chardecoder = null; - CharsetEncoder charencoder = null; + CharsetDecoder charDecoder = null; + CharsetEncoder charEncoder = null; final Charset charset = this.charCodingConfig.getCharset(); final CodingErrorAction malformedInputAction = this.charCodingConfig.getMalformedInputAction() != null ? this.charCodingConfig.getMalformedInputAction() : CodingErrorAction.REPORT; final CodingErrorAction unmappableInputAction = this.charCodingConfig.getUnmappableInputAction() != null ? this.charCodingConfig.getUnmappableInputAction() : CodingErrorAction.REPORT; if (charset != null) { - chardecoder = charset.newDecoder(); - chardecoder.onMalformedInput(malformedInputAction); - chardecoder.onUnmappableCharacter(unmappableInputAction); - charencoder = charset.newEncoder(); - charencoder.onMalformedInput(malformedInputAction); - charencoder.onUnmappableCharacter(unmappableInputAction); + charDecoder = charset.newDecoder(); + charDecoder.onMalformedInput(malformedInputAction); + charDecoder.onUnmappableCharacter(unmappableInputAction); + charEncoder = charset.newEncoder(); + charEncoder.onMalformedInput(malformedInputAction); + charEncoder.onUnmappableCharacter(unmappableInputAction); } final String id = "http-outgoing-" + Long.toString(COUNTER.getAndIncrement()); final DefaultManagedHttpClientConnection conn = new DefaultManagedHttpClientConnection( id, - chardecoder, - charencoder, + charDecoder, + charEncoder, h1Config, incomingContentStrategy, outgoingContentStrategy, diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java index 8edb55139..ecd7cbbc8 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/PoolingHttpClientConnectionManager.java @@ -264,13 +264,13 @@ public class PoolingHttpClientConnectionManager @Override public synchronized ConnectionEndpoint get( final long timeout, - final TimeUnit tunit) throws InterruptedException, ExecutionException, TimeoutException { + final TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { if (this.endpoint != null) { return this.endpoint; } final PoolEntry poolEntry; try { - poolEntry = leaseFuture.get(timeout, tunit); + poolEntry = leaseFuture.get(timeout, timeUnit); if (poolEntry == null || leaseFuture.isCancelled()) { throw new InterruptedException(); } diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/io/LeaseRequest.java b/httpclient5/src/main/java/org/apache/hc/client5/http/io/LeaseRequest.java index 80e0fc824..dbee508e2 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/io/LeaseRequest.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/io/LeaseRequest.java @@ -52,7 +52,7 @@ public interface LeaseRequest extends Cancellable { * be thrown. * * @param timeout the timeout, 0 or negative for no timeout - * @param tunit the unit for the {@code timeout}, + * @param timeUnit the unit for the {@code timeout}, * may be {@code null} only if there is no timeout * * @return a connection that can be used to communicate @@ -63,7 +63,7 @@ public interface LeaseRequest extends Cancellable { * @throws InterruptedException * if the calling thread is interrupted while waiting */ - ConnectionEndpoint get(long timeout, TimeUnit tunit) + ConnectionEndpoint get(long timeout, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException; } \ No newline at end of file diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestCredentials.java b/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestCredentials.java index 30f925d9c..60177d343 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestCredentials.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/auth/TestCredentials.java @@ -172,13 +172,13 @@ public class TestCredentials { public void testUsernamePasswordCredentialsSerialization() throws Exception { final UsernamePasswordCredentials orig = new UsernamePasswordCredentials("name","pwd".toCharArray()); final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream(); - final ObjectOutputStream outstream = new ObjectOutputStream(outbuffer); - outstream.writeObject(orig); - outstream.close(); + final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer); + outStream.writeObject(orig); + outStream.close(); final byte[] raw = outbuffer.toByteArray(); - final ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw); - final ObjectInputStream instream = new ObjectInputStream(inbuffer); - final UsernamePasswordCredentials clone = (UsernamePasswordCredentials) instream.readObject(); + final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw); + final ObjectInputStream inStream = new ObjectInputStream(inBuffer); + final UsernamePasswordCredentials clone = (UsernamePasswordCredentials) inStream.readObject(); Assert.assertEquals(orig, clone); } @@ -186,13 +186,13 @@ public class TestCredentials { public void testNTCredentialsSerialization() throws Exception { final NTCredentials orig = new NTCredentials("name","pwd".toCharArray(), "somehost", "domain"); final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream(); - final ObjectOutputStream outstream = new ObjectOutputStream(outbuffer); - outstream.writeObject(orig); - outstream.close(); + final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer); + outStream.writeObject(orig); + outStream.close(); final byte[] raw = outbuffer.toByteArray(); - final ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw); - final ObjectInputStream instream = new ObjectInputStream(inbuffer); - final NTCredentials clone = (NTCredentials) instream.readObject(); + final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw); + final ObjectInputStream inStream = new ObjectInputStream(inBuffer); + final NTCredentials clone = (NTCredentials) inStream.readObject(); Assert.assertEquals(orig, clone); } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestDecompressingEntity.java b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestDecompressingEntity.java index 8830527f5..e66897594 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestDecompressingEntity.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestDecompressingEntity.java @@ -97,8 +97,8 @@ public class TestDecompressingEntity { super(wrapped, new InputStreamFactory() { @Override - public InputStream create(final InputStream instream) throws IOException { - return new CheckedInputStream(instream, checksum); + public InputStream create(final InputStream inStream) throws IOException { + return new CheckedInputStream(inStream, checksum); } }); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAbstractHttpClientResponseHandler.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAbstractHttpClientResponseHandler.java index 24b297571..0f0b23df2 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAbstractHttpClientResponseHandler.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestAbstractHttpClientResponseHandler.java @@ -65,10 +65,10 @@ public class TestAbstractHttpClientResponseHandler { @SuppressWarnings("boxing") @Test public void testUnsuccessfulResponse() throws Exception { - final InputStream instream = Mockito.mock(InputStream.class); + final InputStream inStream = Mockito.mock(InputStream.class); final HttpEntity entity = Mockito.mock(HttpEntity.class); Mockito.when(entity.isStreaming()).thenReturn(true); - Mockito.when(entity.getContent()).thenReturn(instream); + Mockito.when(entity.getContent()).thenReturn(inStream); final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class); Mockito.when(response.getCode()).thenReturn(404); Mockito.when(response.getEntity()).thenReturn(entity); @@ -81,7 +81,7 @@ public class TestAbstractHttpClientResponseHandler { Assert.assertEquals(404, ex.getStatusCode()); } Mockito.verify(entity).getContent(); - Mockito.verify(instream).close(); + Mockito.verify(inStream).close(); } } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestBasicResponseHandler.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestBasicResponseHandler.java index 08ac384e4..958b903de 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestBasicResponseHandler.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestBasicResponseHandler.java @@ -57,10 +57,10 @@ public class TestBasicResponseHandler { @Test public void testUnsuccessfulResponse() throws Exception { - final InputStream instream = Mockito.mock(InputStream.class); + final InputStream inStream = Mockito.mock(InputStream.class); final HttpEntity entity = Mockito.mock(HttpEntity.class); Mockito.when(entity.isStreaming()).thenReturn(true); - Mockito.when(entity.getContent()).thenReturn(instream); + Mockito.when(entity.getContent()).thenReturn(inStream); final ClassicHttpResponse response = Mockito.mock(ClassicHttpResponse.class); Mockito.when(response.getCode()).thenReturn(404); Mockito.when(response.getEntity()).thenReturn(entity); @@ -73,7 +73,7 @@ public class TestBasicResponseHandler { Assert.assertEquals(404, ex.getStatusCode()); } Mockito.verify(entity).getContent(); - Mockito.verify(instream).close(); + Mockito.verify(inStream).close(); } } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java index c7755fdb0..744f0a7a4 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestConnectExec.java @@ -234,9 +234,9 @@ public class TestConnectExec { final ClassicHttpRequest request = new HttpGet("http://bar/test"); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?"); response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, "Basic realm=test"); - final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); + final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); response1.setEntity(EntityBuilder.create() - .setStream(instream1) + .setStream(inStream1) .build()); final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK"); @@ -264,7 +264,7 @@ public class TestConnectExec { exec.execute(request, scope, execChain); Mockito.verify(execRuntime).connect(context); - Mockito.verify(instream1).close(); + Mockito.verify(inStream1).close(); } @Test @@ -274,9 +274,9 @@ public class TestConnectExec { final ClassicHttpRequest request = new HttpGet("http://bar/test"); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(407, "Huh?"); response1.setHeader(HttpHeaders.PROXY_AUTHENTICATE, "Basic realm=test"); - final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); + final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); response1.setEntity(EntityBuilder.create() - .setStream(instream1) + .setStream(inStream1) .build()); final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK"); @@ -304,7 +304,7 @@ public class TestConnectExec { exec.execute(request, scope, execChain); Mockito.verify(execRuntime).connect(context); - Mockito.verify(instream1, Mockito.never()).close(); + Mockito.verify(inStream1, Mockito.never()).close(); Mockito.verify(execRuntime).disconnect(); } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java index 049f79fef..b385dc18a 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestProtocolExec.java @@ -214,14 +214,14 @@ public class TestProtocolExec { final ClassicHttpRequest request = new HttpGet("http://foo/test"); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?"); response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test"); - final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); + final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); response1.setEntity(EntityBuilder.create() - .setStream(instream1) + .setStream(inStream1) .build()); final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK"); - final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4})); + final InputStream inStream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4})); response2.setEntity(EntityBuilder.create() - .setStream(instream2) + .setStream(inStream2) .build()); final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); @@ -240,8 +240,8 @@ public class TestProtocolExec { final ExecChain.Scope scope = new ExecChain.Scope("test", route, request, execRuntime, context); final ClassicHttpResponse finalResponse = protocolExec.execute(request, scope, chain); Mockito.verify(chain, Mockito.times(2)).proceed(request, scope); - Mockito.verify(instream1).close(); - Mockito.verify(instream2, Mockito.never()).close(); + Mockito.verify(inStream1).close(); + Mockito.verify(inStream2, Mockito.never()).close(); Assert.assertNotNull(finalResponse); Assert.assertEquals(200, finalResponse.getCode()); @@ -253,14 +253,14 @@ public class TestProtocolExec { final ClassicHttpRequest request = new HttpGet("http://foo/test"); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?"); response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test"); - final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); + final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); response1.setEntity(EntityBuilder.create() - .setStream(instream1) + .setStream(inStream1) .build()); final ClassicHttpResponse response2 = new BasicClassicHttpResponse(200, "OK"); - final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4})); + final InputStream inStream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {2, 3, 4})); response2.setEntity(EntityBuilder.create() - .setStream(instream2) + .setStream(inStream2) .build()); final HttpClientContext context = new HttpClientContext(); @@ -287,7 +287,7 @@ public class TestProtocolExec { final ClassicHttpResponse finalResponse = protocolExec.execute(request, scope, chain); Mockito.verify(chain, Mockito.times(2)).proceed(request, scope); Mockito.verify(execRuntime).disconnect(); - Mockito.verify(instream2, Mockito.never()).close(); + Mockito.verify(inStream2, Mockito.never()).close(); Assert.assertNotNull(finalResponse); Assert.assertEquals(200, finalResponse.getCode()); @@ -299,15 +299,15 @@ public class TestProtocolExec { final HttpRoute route = new HttpRoute(target); final HttpClientContext context = new HttpClientContext(); final HttpPost request = new HttpPost("http://foo/test"); - final InputStream instream0 = new ByteArrayInputStream(new byte[] {1, 2, 3}); + final InputStream inStream0 = new ByteArrayInputStream(new byte[] {1, 2, 3}); request.setEntity(EntityBuilder.create() - .setStream(instream0) + .setStream(inStream0) .build()); final ClassicHttpResponse response1 = new BasicClassicHttpResponse(401, "Huh?"); response1.setHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=test"); - final InputStream instream1 = new ByteArrayInputStream(new byte[] {1, 2, 3}); + final InputStream inStream1 = new ByteArrayInputStream(new byte[] {1, 2, 3}); response1.setEntity(EntityBuilder.create() - .setStream(instream1) + .setStream(inStream1) .build()); final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider(); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java index 0a53ec7f6..d202fe115 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestRedirectExec.java @@ -99,15 +99,15 @@ public class TestRedirectExec { final ClassicHttpResponse response1 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY)); final URI redirect = new URI("http://localhost:80/redirect"); response1.setHeader(HttpHeaders.LOCATION, redirect.toASCIIString()); - final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); + final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); final HttpEntity entity1 = EntityBuilder.create() - .setStream(instream1) + .setStream(inStream1) .build(); response1.setEntity(entity1); final ClassicHttpResponse response2 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_OK)); - final InputStream instream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); + final InputStream inStream2 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); final HttpEntity entity2 = EntityBuilder.create() - .setStream(instream2) + .setStream(inStream2) .build(); response2.setEntity(entity2); @@ -130,9 +130,9 @@ public class TestRedirectExec { Assert.assertSame(request, allValues.get(0)); Mockito.verify(response1, Mockito.times(1)).close(); - Mockito.verify(instream1, Mockito.times(2)).close(); + Mockito.verify(inStream1, Mockito.times(2)).close(); Mockito.verify(response2, Mockito.never()).close(); - Mockito.verify(instream2, Mockito.never()).close(); + Mockito.verify(inStream2, Mockito.never()).close(); } @Test(expected = RedirectException.class) @@ -332,9 +332,9 @@ public class TestRedirectExec { final ClassicHttpResponse response1 = Mockito.spy(new BasicClassicHttpResponse(HttpStatus.SC_MOVED_TEMPORARILY)); final URI redirect = new URI("http://localhost:80/redirect"); response1.setHeader(HttpHeaders.LOCATION, redirect.toASCIIString()); - final InputStream instream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); + final InputStream inStream1 = Mockito.spy(new ByteArrayInputStream(new byte[] {1, 2, 3})); final HttpEntity entity1 = EntityBuilder.create() - .setStream(instream1) + .setStream(inStream1) .build(); response1.setEntity(entity1); Mockito.when(chain.proceed( @@ -349,7 +349,7 @@ public class TestRedirectExec { try { redirectExec.execute(request, scope, chain); } catch (final Exception ex) { - Mockito.verify(instream1, Mockito.times(2)).close(); + Mockito.verify(inStream1, Mockito.times(2)).close(); Mockito.verify(response1).close(); throw ex; } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestResponseEntityWrapper.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestResponseEntityWrapper.java index 46250cf7e..a8ad4e46a 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestResponseEntityWrapper.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/classic/TestResponseEntityWrapper.java @@ -42,16 +42,16 @@ import org.mockito.Mockito; @SuppressWarnings("boxing") // test code public class TestResponseEntityWrapper { - private InputStream instream; + private InputStream inStream; private HttpEntity entity; private ExecRuntime execRuntime; private ResponseEntityProxy wrapper; @Before public void setup() throws Exception { - instream = Mockito.mock(InputStream.class); + inStream = Mockito.mock(InputStream.class); entity = Mockito.mock(HttpEntity.class); - Mockito.when(entity.getContent()).thenReturn(instream); + Mockito.when(entity.getContent()).thenReturn(inStream); execRuntime = Mockito.mock(ExecRuntime.class); wrapper = new ResponseEntityProxy(entity, execRuntime); } @@ -62,7 +62,7 @@ public class TestResponseEntityWrapper { Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true); EntityUtils.consume(wrapper); - Mockito.verify(instream, Mockito.times(1)).close(); + Mockito.verify(inStream, Mockito.times(1)).close(); Mockito.verify(execRuntime).releaseConnection(); } @@ -70,7 +70,7 @@ public class TestResponseEntityWrapper { public void testReusableEntityStreamClosedIOError() throws Exception { Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true); - Mockito.doThrow(new IOException()).when(instream).close(); + Mockito.doThrow(new IOException()).when(inStream).close(); try { EntityUtils.consume(wrapper); Assert.fail("IOException expected"); @@ -84,28 +84,28 @@ public class TestResponseEntityWrapper { Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true); Mockito.when(execRuntime.isConnectionAcquired()).thenReturn(false); - Mockito.doThrow(new SocketException()).when(instream).close(); + Mockito.doThrow(new SocketException()).when(inStream).close(); EntityUtils.consume(wrapper); Mockito.verify(execRuntime).discardConnection(); } @Test public void testReusableEntityWriteTo() throws Exception { - final OutputStream outstream = Mockito.mock(OutputStream.class); + final OutputStream outStream = Mockito.mock(OutputStream.class); Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true); - wrapper.writeTo(outstream); + wrapper.writeTo(outStream); Mockito.verify(execRuntime).releaseConnection(); } @Test public void testReusableEntityWriteToIOError() throws Exception { - final OutputStream outstream = Mockito.mock(OutputStream.class); + final OutputStream outStream = Mockito.mock(OutputStream.class); Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true); - Mockito.doThrow(new IOException()).when(entity).writeTo(outstream); + Mockito.doThrow(new IOException()).when(entity).writeTo(outStream); try { - wrapper.writeTo(outstream); + wrapper.writeTo(outStream); Assert.fail("IOException expected"); } catch (final IOException ex) { } @@ -115,21 +115,21 @@ public class TestResponseEntityWrapper { @Test public void testReusableEntityEndOfStream() throws Exception { - Mockito.when(instream.read()).thenReturn(-1); + Mockito.when(inStream.read()).thenReturn(-1); Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true); final InputStream content = wrapper.getContent(); Assert.assertEquals(-1, content.read()); - Mockito.verify(instream).close(); + Mockito.verify(inStream).close(); Mockito.verify(execRuntime).releaseConnection(); } @Test public void testReusableEntityEndOfStreamIOError() throws Exception { - Mockito.when(instream.read()).thenReturn(-1); + Mockito.when(inStream.read()).thenReturn(-1); Mockito.when(entity.isStreaming()).thenReturn(true); Mockito.when(execRuntime.isConnectionReusable()).thenReturn(true); - Mockito.doThrow(new IOException()).when(instream).close(); + Mockito.doThrow(new IOException()).when(inStream).close(); final InputStream content = wrapper.getContent(); try { content.read(); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicClientCookie.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicClientCookie.java index 69eac4451..ed2c1e1ab 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicClientCookie.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicClientCookie.java @@ -75,13 +75,13 @@ public class TestBasicClientCookie { orig.setPath("/"); orig.setAttribute("attrib", "stuff"); final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream(); - final ObjectOutputStream outstream = new ObjectOutputStream(outbuffer); - outstream.writeObject(orig); - outstream.close(); + final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer); + outStream.writeObject(orig); + outStream.close(); final byte[] raw = outbuffer.toByteArray(); - final ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw); - final ObjectInputStream instream = new ObjectInputStream(inbuffer); - final BasicClientCookie clone = (BasicClientCookie) instream.readObject(); + final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw); + final ObjectInputStream inStream = new ObjectInputStream(inBuffer); + final BasicClientCookie clone = (BasicClientCookie) inStream.readObject(); Assert.assertEquals(orig.getName(), clone.getName()); Assert.assertEquals(orig.getValue(), clone.getValue()); Assert.assertEquals(orig.getDomain(), clone.getDomain()); diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieStore.java b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieStore.java index f01f60938..ed2cea285 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieStore.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/impl/cookie/TestBasicCookieStore.java @@ -49,15 +49,15 @@ public class TestBasicCookieStore { final BasicCookieStore store = new BasicCookieStore(); store.addCookie(new BasicClientCookie("name1", "value1")); store.addCookies(new BasicClientCookie[] {new BasicClientCookie("name2", "value2")}); - List l = store.getCookies(); - Assert.assertNotNull(l); - Assert.assertEquals(2, l.size()); - Assert.assertEquals("name1", l.get(0).getName()); - Assert.assertEquals("name2", l.get(1).getName()); + List list = store.getCookies(); + Assert.assertNotNull(list); + Assert.assertEquals(2, list.size()); + Assert.assertEquals("name1", list.get(0).getName()); + Assert.assertEquals("name2", list.get(1).getName()); store.clear(); - l = store.getCookies(); - Assert.assertNotNull(l); - Assert.assertEquals(0, l.size()); + list = store.getCookies(); + Assert.assertNotNull(list); + Assert.assertEquals(0, list.size()); } @Test @@ -69,9 +69,9 @@ public class TestBasicCookieStore { c.add(Calendar.DAY_OF_YEAR, -10); cookie.setExpiryDate(c.getTime()); store.addCookie(cookie); - final List l = store.getCookies(); - Assert.assertNotNull(l); - Assert.assertEquals(0, l.size()); + final List list = store.getCookies(); + Assert.assertNotNull(list); + Assert.assertEquals(0, list.size()); } @Test @@ -80,13 +80,13 @@ public class TestBasicCookieStore { orig.addCookie(new BasicClientCookie("name1", "value1")); orig.addCookie(new BasicClientCookie("name2", "value2")); final ByteArrayOutputStream outbuffer = new ByteArrayOutputStream(); - final ObjectOutputStream outstream = new ObjectOutputStream(outbuffer); - outstream.writeObject(orig); - outstream.close(); + final ObjectOutputStream outStream = new ObjectOutputStream(outbuffer); + outStream.writeObject(orig); + outStream.close(); final byte[] raw = outbuffer.toByteArray(); - final ByteArrayInputStream inbuffer = new ByteArrayInputStream(raw); - final ObjectInputStream instream = new ObjectInputStream(inbuffer); - final BasicCookieStore clone = (BasicCookieStore) instream.readObject(); + final ByteArrayInputStream inBuffer = new ByteArrayInputStream(raw); + final ObjectInputStream inStream = new ObjectInputStream(inBuffer); + final BasicCookieStore clone = (BasicCookieStore) inStream.readObject(); final List expected = orig.getCookies(); final List clones = clone.getCookies(); Assert.assertNotNull(expected);