From 09ae5f212af08774d8374af8a03b894bd188b5c6 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 28 Jun 2023 21:01:50 -0400 Subject: [PATCH] Mostly missing Javadoc in org.apache.hc.client5.http.entity and minor clean ups --- .../hc/client5/http/cache/Resource.java | 2 +- .../http/entity/DecompressingEntity.java | 3 +- .../hc/client5/http/entity/EntityBuilder.java | 124 +++++++++++++----- .../PoolingAsyncClientConnectionManager.java | 9 +- 4 files changed, 95 insertions(+), 43 deletions(-) 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 b2cf02892..809ce4a1d 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 @@ -48,7 +48,7 @@ public abstract class Resource implements Serializable { private static final long serialVersionUID = 1L; /** - * Returns resource content as a {@link InputStream}. + * Returns resource content as an {@link InputStream}. * * @throws ResourceIOException */ diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DecompressingEntity.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DecompressingEntity.java index 38f51cd21..dd164371c 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DecompressingEntity.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/DecompressingEntity.java @@ -47,6 +47,7 @@ public class DecompressingEntity extends HttpEntityWrapper { private static final int BUFFER_SIZE = 1024 * 2; private final InputStreamFactory inputStreamFactory; + /** * {@link #getContent()} method must return the same {@link InputStream} * instance when DecompressingEntity is wrapping a streaming entity. @@ -54,7 +55,7 @@ public class DecompressingEntity extends HttpEntityWrapper { private InputStream content; /** - * Creates a new {@link DecompressingEntity}. + * Constructs a new {@link DecompressingEntity}. * * @param wrapped the non-null {@link HttpEntity} to be wrapped * @param inputStreamFactory factory to create decompressing stream. diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/EntityBuilder.java b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/EntityBuilder.java index e8768a50e..bfcf947d2 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/entity/EntityBuilder.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/entity/EntityBuilder.java @@ -92,7 +92,9 @@ public class EntityBuilder { } /** - * Returns entity content as a string if set using {@link #setText(String)} method. + * Gets the entity content as a string if set using {@link #setText(String)}. + * + * @return the entity content as a string, may be null. */ public String getText() { return text; @@ -101,11 +103,14 @@ public class EntityBuilder { /** * Sets entity content as a string. This method is mutually exclusive with * {@link #setBinary(byte[])}, - * {@link #setStream(java.io.InputStream)} , - * {@link #setSerializable(java.io.Serializable)} , + * {@link #setStream(java.io.InputStream)}, + * {@link #setSerializable(java.io.Serializable)}, * {@link #setParameters(java.util.List)}, * {@link #setParameters(NameValuePair...)} * {@link #setFile(java.io.File)} methods. + * + * @param text entity content as a string. + * @return this */ public EntityBuilder setText(final String text) { clearContent(); @@ -114,8 +119,10 @@ public class EntityBuilder { } /** - * Returns entity content as a byte array if set using - * {@link #setBinary(byte[])} method. + * Gets entity content as a byte array if set using + * {@link #setBinary(byte[])}. + * + * @return entity content as a byte array. */ public byte[] getBinary() { return binary; @@ -124,11 +131,14 @@ public class EntityBuilder { /** * Sets entity content as a byte array. This method is mutually exclusive with * {@link #setText(String)}, - * {@link #setStream(java.io.InputStream)} , - * {@link #setSerializable(java.io.Serializable)} , + * {@link #setStream(java.io.InputStream)}, + * {@link #setSerializable(java.io.Serializable)}, * {@link #setParameters(java.util.List)}, * {@link #setParameters(NameValuePair...)} - * {@link #setFile(java.io.File)} methods. + * {@link #setFile(java.io.File)}. + * + * @param binary The new entity content as a byte array. + * @return this */ public EntityBuilder setBinary(final byte[] binary) { clearContent(); @@ -137,21 +147,26 @@ public class EntityBuilder { } /** - * Returns entity content as a {@link InputStream} if set using + * Gets entity content as an {@link InputStream} if set using * {@link #setStream(java.io.InputStream)} method. + * + * @return entity content as an {@link InputStream} */ public InputStream getStream() { return stream; } /** - * Sets entity content as a {@link InputStream}. This method is mutually exclusive with + * Sets entity content as an {@link InputStream}. This method is mutually exclusive with * {@link #setText(String)}, * {@link #setBinary(byte[])}, - * {@link #setSerializable(java.io.Serializable)} , + * {@link #setSerializable(java.io.Serializable)}, * {@link #setParameters(java.util.List)}, * {@link #setParameters(NameValuePair...)} - * {@link #setFile(java.io.File)} methods. + * {@link #setFile(java.io.File)}. + * + * @param stream The new entity content as an InputStream. + * @return this */ public EntityBuilder setStream(final InputStream stream) { clearContent(); @@ -160,9 +175,11 @@ public class EntityBuilder { } /** - * Returns entity content as a parameter list if set using + * Gets entity content as a parameter list if set using * {@link #setParameters(java.util.List)} or - * {@link #setParameters(NameValuePair...)} methods. + * {@link #setParameters(NameValuePair...)}. + * + * @return entity content as a parameter list. */ public List getParameters() { return parameters; @@ -172,9 +189,12 @@ public class EntityBuilder { * Sets entity content as a parameter list. This method is mutually exclusive with * {@link #setText(String)}, * {@link #setBinary(byte[])}, - * {@link #setStream(java.io.InputStream)} , - * {@link #setSerializable(java.io.Serializable)} , - * {@link #setFile(java.io.File)} methods. + * {@link #setStream(java.io.InputStream)}, + * {@link #setSerializable(java.io.Serializable)}, + * {@link #setFile(java.io.File)}. + * + * @param parameters entity content as a parameter list. + * @return this */ public EntityBuilder setParameters(final List parameters) { clearContent(); @@ -186,17 +206,22 @@ public class EntityBuilder { * Sets entity content as a parameter list. This method is mutually exclusive with * {@link #setText(String)}, * {@link #setBinary(byte[])}, - * {@link #setStream(java.io.InputStream)} , - * {@link #setSerializable(java.io.Serializable)} , - * {@link #setFile(java.io.File)} methods. + * {@link #setStream(java.io.InputStream)}, + * {@link #setSerializable(java.io.Serializable)}, + * {@link #setFile(java.io.File)}. + * + * @param parameters entity content as a parameter list. + * @return this */ public EntityBuilder setParameters(final NameValuePair... parameters) { return setParameters(Arrays.asList(parameters)); } /** - * Returns entity content as a {@link Serializable} if set using + * Gets entity content as a {@link Serializable} if set using * {@link #setSerializable(java.io.Serializable)} method. + * + * @return entity content as a {@link Serializable}. */ public Serializable getSerializable() { return serializable; @@ -206,10 +231,13 @@ public class EntityBuilder { * Sets entity content as a {@link Serializable}. This method is mutually exclusive with * {@link #setText(String)}, * {@link #setBinary(byte[])}, - * {@link #setStream(java.io.InputStream)} , + * {@link #setStream(java.io.InputStream)}, * {@link #setParameters(java.util.List)}, * {@link #setParameters(NameValuePair...)} - * {@link #setFile(java.io.File)} methods. + * {@link #setFile(java.io.File)}. + * + * @param serializable entity content as a {@link Serializable}. + * @return this */ public EntityBuilder setSerializable(final Serializable serializable) { clearContent(); @@ -218,8 +246,10 @@ public class EntityBuilder { } /** - * Returns entity content as a {@link File} if set using - * {@link #setFile(java.io.File)} method. + * Gets the entity content as a {@link File} if set using + * {@link #setFile(java.io.File)}. + * + * @return Gets the entity content as a {@link File}. */ public File getFile() { return file; @@ -229,10 +259,13 @@ public class EntityBuilder { * Sets entity content as a {@link File}. This method is mutually exclusive with * {@link #setText(String)}, * {@link #setBinary(byte[])}, - * {@link #setStream(java.io.InputStream)} , + * {@link #setStream(java.io.InputStream)}, * {@link #setParameters(java.util.List)}, * {@link #setParameters(NameValuePair...)} - * {@link #setSerializable(java.io.Serializable)} methods. + * {@link #setSerializable(java.io.Serializable)}. + * + * @param file entity content as a {@link File}. + * @return this */ public EntityBuilder setFile(final File file) { clearContent(); @@ -241,14 +274,19 @@ public class EntityBuilder { } /** - * Returns {@link ContentType} of the entity, if set. + * Gets the {@link ContentType} of the entity, may be null. + * + * @return the {@link ContentType} of the entity, may be null. */ public ContentType getContentType() { return contentType; } /** - * Sets {@link ContentType} of the entity. + * Sets the {@link ContentType} of the entity. + * + * @param contentType the {@link ContentType} of the entity, may be null. + * @return this */ public EntityBuilder setContentType(final ContentType contentType) { this.contentType = contentType; @@ -256,14 +294,19 @@ public class EntityBuilder { } /** - * Returns content encoding of the entity, if set. + * Gets the content encoding of the entity, may be null. + * + * @return the content encoding of the entity, may be null. */ public String getContentEncoding() { return contentEncoding; } /** - * Sets content encoding of the entity. + * Sets the content encoding of the entity. + * + * @param contentEncoding the content encoding of the entity, may be null. + * @return this */ public EntityBuilder setContentEncoding(final String contentEncoding) { this.contentEncoding = contentEncoding; @@ -271,14 +314,17 @@ public class EntityBuilder { } /** - * Returns {@code true} if entity is to be chunk coded, {@code false} otherwise. + * Tests if the entity is to be chunk coded ({@code true}), or not ({@code false}). + * + * @return {@code true} if entity is to be chunk coded, {@code false} otherwise. */ public boolean isChunked() { return chunked; } /** - * Makes entity chunk coded. + * Sets entities to be chunked. + * @return this */ public EntityBuilder chunked() { this.chunked = true; @@ -286,14 +332,18 @@ public class EntityBuilder { } /** - * Returns {@code true} if entity is to be GZIP compressed, {@code false} otherwise. + * Tests if entities are to be GZIP compressed ({@code true}), or not ({@code false}). + * + * @return {@code true} if entity is to be GZIP compressed, {@code false} otherwise. */ public boolean isGzipCompressed() { return gzipCompressed; } /** - * Makes entity GZIP compressed. + * Sets entities to be GZIP compressed. + * + * @return this */ public EntityBuilder gzipCompressed() { this.gzipCompressed = true; @@ -305,7 +355,9 @@ public class EntityBuilder { } /** - * Creates new instance of {@link HttpEntity} based on the current state. + * Builds a new instance of {@link HttpEntity} based on the current state. + * + * @return a new instance. */ public HttpEntity build() { final AbstractHttpEntity e; diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java index b56c24628..4ab181189 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/nio/PoolingAsyncClientConnectionManager.java @@ -302,12 +302,11 @@ public class PoolingAsyncClientConnectionManager implements AsyncClientConnectio leaseCompleted(poolEntry); })), Command.Priority.IMMEDIATE); return; - } else { - if (LOG.isDebugEnabled()) { - LOG.debug("{} connection {} is closed", id, ConnPoolSupport.getId(connection)); - } - poolEntry.discardConnection(CloseMode.IMMEDIATE); } + if (LOG.isDebugEnabled()) { + LOG.debug("{} connection {} is closed", id, ConnPoolSupport.getId(connection)); + } + poolEntry.discardConnection(CloseMode.IMMEDIATE); } } }