Skip to content

Commit

Permalink
Refactor compression entity class names for consistency. Renamed to u…
Browse files Browse the repository at this point in the history
…se 'ing' form (e.g., CompressingEntity) to align with existing conventions like DecompressingEntity. Moved compression/decompression classes to org.apache.hc.client5.http.entity.compress package
  • Loading branch information
arturobernalg committed Nov 15, 2024
1 parent 5b78afd commit 363c7ca
Show file tree
Hide file tree
Showing 29 changed files with 226 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ default TestClientBuilder addExecInterceptorLast(String name, ExecChainHandler i
throw new UnsupportedOperationException("Operation not supported by " + getProtocolLevel());
}

/**
* Configures whether the client builder should wrap requests and responses.
*
* @param noWrap {@code true} to disable wrapping; {@code false} to enable wrapping.
* @return this builder instance.
* @since 5.5
*/
default TestClientBuilder setNoWrap(boolean noWrap) {
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ public TestClient client() throws Exception {
return client;
}

/**
* Creates a configured {@link TestClient} instance.
*
* @param noWrap {@code true} to disable wrapping; {@code false} to enable wrapping.
* @return a {@link TestClient} instance.
* @throws Exception if an error occurs during client creation.
* @since 5.5
*/
public TestClient client(final boolean noWrap) throws Exception {
clientBuilder.setNoWrap(noWrap);
return client();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public TestClient client() throws Exception {
return testResources.client();
}

/**
* Retrieves a {@link TestClient} instance configured with the specified wrapping option.
*
* @param noWrap {@code true} to disable wrapping; {@code false} to enable wrapping.
* @return a {@link TestClient} instance.
* @throws Exception if an error occurs during client retrieval or configuration.
* @since 5.5
*/
public TestClient client(final boolean noWrap) throws Exception {
return testResources.client(noWrap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Arrays;
import java.util.List;

import org.apache.hc.client5.http.entity.CompressorFactory;
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ClassicHttpRequest;
Expand Down Expand Up @@ -106,7 +106,7 @@ public static void main(final String[] args) {

private static HttpEntity compress(final String data, final String name) {
final StringEntity originalEntity = new StringEntity(data, ContentType.TEXT_PLAIN);
return CompressorFactory.INSTANCE.compressEntity(originalEntity, name);
return CompressingFactory.INSTANCE.compressEntity(originalEntity, name);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
package org.apache.hc.client5.http.entity;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;
import org.apache.hc.core5.http.HttpEntity;

/**
Expand All @@ -34,7 +35,7 @@
*
* @see GzipDecompressingEntity
* @since 5.2
* @deprecated Use {@link CompressorFactory} for handling Brotli decompression.
* @deprecated Use {@link CompressingFactory} for handling Brotli decompression.
*/
@Deprecated
public class BrotliDecompressingEntity extends DecompressingEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.io.InputStream;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.brotli.dec.BrotliInputStream;
Expand All @@ -37,7 +38,7 @@
* {@link InputStreamFactory} for handling Brotli Content Coded responses.
*
* @since 5.2
* @deprecated Use {@link CompressorFactory} for handling Brotli compression.
* @deprecated Use {@link CompressingFactory} for handling Brotli compression.
*/
@Deprecated
@Contract(threading = ThreadingBehavior.STATELESS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* Common base class for decompressing {@link HttpEntity} implementations.
*
* @since 4.4
* @deprecated
* @deprecated Use {{@link org.apache.hc.client5.http.entity.compress.DecompressingEntity}
*/
@Deprecated
public class DecompressingEntity extends HttpEntityWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
package org.apache.hc.client5.http.entity;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;
import org.apache.hc.client5.http.entity.compress.DecompressingEntity;
import org.apache.hc.core5.http.HttpEntity;

/**
Expand All @@ -43,10 +45,10 @@
* @see GzipDecompressingEntity
*
* @since 4.1
* @deprecated Use {@link DecompressEntity} or {@link CompressorFactory} for decompression handling.
* @deprecated Use {@link DecompressingEntity} or {@link CompressingFactory} for decompression handling.
*/
@Deprecated
public class DeflateDecompressingEntity extends DecompressingEntity {
public class DeflateDecompressingEntity extends org.apache.hc.client5.http.entity.DecompressingEntity {

/**
* Creates a new {@link DeflateDecompressingEntity} which will wrap the specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
import java.util.zip.InflaterInputStream;
import java.util.zip.ZipException;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;

/**
* Deflates an input stream. This class includes logic needed for various RFCs in order
* to reasonably implement the "deflate" compression algorithm.
* @deprecated Use {@link CompressorFactory} for handling Deflate compression.
* @deprecated Use {@link CompressingFactory} for handling Deflate compression.
*/
@Deprecated
public class DeflateInputStream extends FilterInputStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@
import java.io.IOException;
import java.io.InputStream;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;

/**
* {@link InputStreamFactory} for handling Deflate Content Coded responses.
*
* @since 5.0
* @deprecated Use {@link CompressorFactory}.
* @deprecated Use {@link CompressingFactory}.
*/
@Deprecated
@Contract(threading = ThreadingBehavior.STATELESS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import java.util.Arrays;
import java.util.List;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;
import org.apache.hc.client5.http.entity.compress.DecompressingEntity;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.NameValuePair;
Expand Down Expand Up @@ -328,7 +330,7 @@ public boolean isChunked() {
* Tests if the entity is to be compressed ({@code true}), or not ({@code false}).
*
* @return {@code true} if entity is to be compressed, {@code false} otherwise.
* @since 5.4
* @since 5.5
*/
public boolean isCompressed() {
return compressed;
Expand All @@ -339,7 +341,7 @@ public boolean isCompressed() {
*
* @param compressed {@code true} if the entity should be compressed, {@code false} otherwise.
* @return this instance.
* @since 5.4
* @since 5.5
*/
public EntityBuilder setCompressed(final boolean compressed) {
this.compressed = compressed;
Expand Down Expand Up @@ -406,7 +408,7 @@ public HttpEntity build() {
throw new IllegalStateException("No entity set");
}
if (this.compressed) {
return new DecompressEntity(e, CompressorFactory.INSTANCE.getFormattedName(contentEncoding));
return new DecompressingEntity(e, CompressingFactory.INSTANCE.getFormattedName(contentEncoding));
}
return e;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@
import java.io.InputStream;
import java.util.zip.GZIPInputStream;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;
import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;

/**
* {@link InputStreamFactory} for handling GZIPContent Coded responses.
*
* @since 5.0
* @deprecated Use {@link CompressorFactory#getCompressorInputStream(String, InputStream, boolean)} instead.
* @deprecated Use {@link CompressingFactory#getDecompressorInputStream(String, InputStream, boolean)} instead.
*/
@Deprecated
@Contract(threading = ThreadingBehavior.STATELESS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.OutputStream;
import java.util.zip.GZIPOutputStream;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.HttpEntityWrapper;
import org.apache.hc.core5.util.Args;
Expand All @@ -40,7 +41,7 @@
*
*
* @since 4.0
* @deprecated Use {@link CompressorFactory#compressEntity(HttpEntity, String)} to handle compression.
* @deprecated Use {@link CompressingFactory#compressEntity(HttpEntity, String)} to handle compression.
*/
@Deprecated
public class GzipCompressingEntity extends HttpEntityWrapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
*/
package org.apache.hc.client5.http.entity;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;
import org.apache.hc.core5.http.HttpEntity;

/**
* {@link org.apache.hc.core5.http.io.entity.HttpEntityWrapper} for handling
* gzip Content Coded responses.
*
* @since 4.1
* @deprecated Use {@link CompressorFactory} for handling Gzip decompression.
* @deprecated Use {@link CompressingFactory} for handling Gzip decompression.
*/
@Deprecated
public class GzipDecompressingEntity extends DecompressingEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import java.io.IOException;
import java.io.InputStream;

import org.apache.hc.client5.http.entity.compress.CompressingFactory;

/**
* Factory for decorated {@link InputStream}s.
*
* @since 4.4
* @deprecated Use {@link CompressorFactory} to retrieve appropriate {@link InputStream}s for compression handling.
* @deprecated Use {@link CompressingFactory} to retrieve appropriate {@link InputStream}s for compression handling.
*/
@Deprecated
public interface InputStreamFactory {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

/**
* Lazy initializes from an {@link InputStream} wrapper.
* @deprecated Use {@link LazyDecompressInputStream}
* @deprecated Use {@link org.apache.hc.client5.http.entity.compress.LazyDecompressingInputStream}
*/
@Deprecated
class LazyDecompressingInputStream extends FilterInputStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* <http://www.apache.org/>.
*
*/
package org.apache.hc.client5.http.entity;
package org.apache.hc.client5.http.entity.compress;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -40,7 +40,7 @@
* an output stream. This class supports various compression algorithms based on the
* specified content encoding.
*
* <p>Compression is performed using {@link CompressorFactory}, which returns a corresponding
* <p>Compression is performed using {@link CompressingFactory}, which returns a corresponding
* {@link OutputStream} for the requested compression type. This class does not support
* reading the content directly through {@link #getContent()} as the content is always compressed
* during write operations.</p>
Expand Down Expand Up @@ -108,20 +108,17 @@ public InputStream getContent() throws IOException {
@Override
public void writeTo(final OutputStream outStream) throws IOException {
Args.notNull(outStream, "Output stream");
// Get the compressor based on the specified content encoding
final OutputStream compressorStream;
try {
compressorStream = CompressorFactory.INSTANCE.getCompressorOutputStream(contentEncoding, outStream);

try (final OutputStream compressorStream = CompressingFactory.INSTANCE.getCompressorOutputStream(contentEncoding, outStream)) {
if (compressorStream != null) {
// Write compressed data
super.writeTo(compressorStream);
} else {
throw new UnsupportedOperationException("Unsupported compression: " + contentEncoding);
}
} catch (final CompressorException e) {
throw new IOException("Error initializing decompression stream", e);
}
if (compressorStream != null) {
// Write compressed data
super.writeTo(compressorStream);
// Close the compressor stream after writing
compressorStream.close();
} else {
throw new UnsupportedOperationException("Unsupported compression: " + contentEncoding);
throw new IOException("Error initializing compression stream", e);
}
}

}
Loading

0 comments on commit 363c7ca

Please sign in to comment.