Skip to content

Commit 63088bc

Browse files
committed
Refactor compression entity class names for consistency. Renamed to use '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
1 parent 35924fc commit 63088bc

25 files changed

+199
-147
lines changed

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/compress/CompressedResponseHandlingExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.Arrays;
3131
import java.util.List;
3232

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

107107
private static HttpEntity compress(final String data, final String name) {
108108
final StringEntity originalEntity = new StringEntity(data, ContentType.TEXT_PLAIN);
109-
return CompressorFactory.INSTANCE.compressEntity(originalEntity, name);
109+
return CompressingFactory.INSTANCE.compressEntity(originalEntity, name);
110110
}
111111

112112
}

httpclient5/src/main/java/org/apache/hc/client5/http/entity/BrotliDecompressingEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
*/
2727
package org.apache.hc.client5.http.entity;
2828

29+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
2930
import org.apache.hc.core5.http.HttpEntity;
3031

3132
/**
@@ -34,7 +35,7 @@
3435
*
3536
* @see GzipDecompressingEntity
3637
* @since 5.2
37-
* @deprecated Use {@link CompressorFactory} for handling Brotli decompression.
38+
* @deprecated Use {@link CompressingFactory} for handling Brotli decompression.
3839
*/
3940
@Deprecated
4041
public class BrotliDecompressingEntity extends DecompressingEntity {

httpclient5/src/main/java/org/apache/hc/client5/http/entity/BrotliInputStreamFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.IOException;
3030
import java.io.InputStream;
3131

32+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
3233
import org.apache.hc.core5.annotation.Contract;
3334
import org.apache.hc.core5.annotation.ThreadingBehavior;
3435
import org.brotli.dec.BrotliInputStream;
@@ -37,7 +38,7 @@
3738
* {@link InputStreamFactory} for handling Brotli Content Coded responses.
3839
*
3940
* @since 5.2
40-
* @deprecated Use {@link CompressorFactory} for handling Brotli compression.
41+
* @deprecated Use {@link CompressingFactory} for handling Brotli compression.
4142
*/
4243
@Deprecated
4344
@Contract(threading = ThreadingBehavior.STATELESS)

httpclient5/src/main/java/org/apache/hc/client5/http/entity/DecompressingEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* Common base class for decompressing {@link HttpEntity} implementations.
3939
*
4040
* @since 4.4
41-
* @deprecated
41+
* @deprecated Use {{@link org.apache.hc.client5.http.entity.compress.DecompressingEntity}
4242
*/
4343
@Deprecated
4444
public class DecompressingEntity extends HttpEntityWrapper {

httpclient5/src/main/java/org/apache/hc/client5/http/entity/DeflateDecompressingEntity.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
package org.apache.hc.client5.http.entity;
2828

29+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
30+
import org.apache.hc.client5.http.entity.compress.DecompressingEntity;
2931
import org.apache.hc.core5.http.HttpEntity;
3032

3133
/**
@@ -43,10 +45,10 @@
4345
* @see GzipDecompressingEntity
4446
*
4547
* @since 4.1
46-
* @deprecated Use {@link DecompressEntity} or {@link CompressorFactory} for decompression handling.
48+
* @deprecated Use {@link DecompressingEntity} or {@link CompressingFactory} for decompression handling.
4749
*/
4850
@Deprecated
49-
public class DeflateDecompressingEntity extends DecompressingEntity {
51+
public class DeflateDecompressingEntity extends org.apache.hc.client5.http.entity.DecompressingEntity {
5052

5153
/**
5254
* Creates a new {@link DeflateDecompressingEntity} which will wrap the specified

httpclient5/src/main/java/org/apache/hc/client5/http/entity/DeflateInputStream.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
import java.util.zip.InflaterInputStream;
3636
import java.util.zip.ZipException;
3737

38+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
39+
3840
/**
3941
* Deflates an input stream. This class includes logic needed for various RFCs in order
4042
* to reasonably implement the "deflate" compression algorithm.
41-
* @deprecated Use {@link CompressorFactory} for handling Deflate compression.
43+
* @deprecated Use {@link CompressingFactory} for handling Deflate compression.
4244
*/
4345
@Deprecated
4446
public class DeflateInputStream extends FilterInputStream {

httpclient5/src/main/java/org/apache/hc/client5/http/entity/DeflateInputStreamFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@
3030
import java.io.IOException;
3131
import java.io.InputStream;
3232

33+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
3334
import org.apache.hc.core5.annotation.Contract;
3435
import org.apache.hc.core5.annotation.ThreadingBehavior;
3536

3637
/**
3738
* {@link InputStreamFactory} for handling Deflate Content Coded responses.
3839
*
3940
* @since 5.0
40-
* @deprecated Use {@link CompressorFactory}.
41+
* @deprecated Use {@link CompressingFactory}.
4142
*/
4243
@Deprecated
4344
@Contract(threading = ThreadingBehavior.STATELESS)

httpclient5/src/main/java/org/apache/hc/client5/http/entity/EntityBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.util.Arrays;
3434
import java.util.List;
3535

36+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
37+
import org.apache.hc.client5.http.entity.compress.DecompressingEntity;
3638
import org.apache.hc.core5.http.ContentType;
3739
import org.apache.hc.core5.http.HttpEntity;
3840
import org.apache.hc.core5.http.NameValuePair;
@@ -406,7 +408,7 @@ public HttpEntity build() {
406408
throw new IllegalStateException("No entity set");
407409
}
408410
if (this.compressed) {
409-
return new DecompressEntity(e, CompressorFactory.INSTANCE.getFormattedName(contentEncoding));
411+
return new DecompressingEntity(e, CompressingFactory.INSTANCE.getFormattedName(contentEncoding));
410412
}
411413
return e;
412414
}

httpclient5/src/main/java/org/apache/hc/client5/http/entity/GZIPInputStreamFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
import java.io.InputStream;
3232
import java.util.zip.GZIPInputStream;
3333

34+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
3435
import org.apache.hc.core5.annotation.Contract;
3536
import org.apache.hc.core5.annotation.ThreadingBehavior;
3637

3738
/**
3839
* {@link InputStreamFactory} for handling GZIPContent Coded responses.
3940
*
4041
* @since 5.0
41-
* @deprecated Use {@link CompressorFactory#getCompressorInputStream(String, InputStream, boolean)} instead.
42+
* @deprecated Use {@link CompressingFactory#getDecompressorInputStream(String, InputStream, boolean)} instead.
4243
*/
4344
@Deprecated
4445
@Contract(threading = ThreadingBehavior.STATELESS)

httpclient5/src/main/java/org/apache/hc/client5/http/entity/GzipCompressingEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.io.OutputStream;
3232
import java.util.zip.GZIPOutputStream;
3333

34+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
3435
import org.apache.hc.core5.http.HttpEntity;
3536
import org.apache.hc.core5.http.io.entity.HttpEntityWrapper;
3637
import org.apache.hc.core5.util.Args;
@@ -40,7 +41,7 @@
4041
*
4142
*
4243
* @since 4.0
43-
* @deprecated Use {@link CompressorFactory#compressEntity(HttpEntity, String)} to handle compression.
44+
* @deprecated Use {@link CompressingFactory#compressEntity(HttpEntity, String)} to handle compression.
4445
*/
4546
@Deprecated
4647
public class GzipCompressingEntity extends HttpEntityWrapper {

httpclient5/src/main/java/org/apache/hc/client5/http/entity/GzipDecompressingEntity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@
2626
*/
2727
package org.apache.hc.client5.http.entity;
2828

29+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
2930
import org.apache.hc.core5.http.HttpEntity;
3031

3132
/**
3233
* {@link org.apache.hc.core5.http.io.entity.HttpEntityWrapper} for handling
3334
* gzip Content Coded responses.
3435
*
3536
* @since 4.1
36-
* @deprecated Use {@link CompressorFactory} for handling Gzip decompression.
37+
* @deprecated Use {@link CompressingFactory} for handling Gzip decompression.
3738
*/
3839
@Deprecated
3940
public class GzipDecompressingEntity extends DecompressingEntity {

httpclient5/src/main/java/org/apache/hc/client5/http/entity/InputStreamFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@
2929
import java.io.IOException;
3030
import java.io.InputStream;
3131

32+
import org.apache.hc.client5.http.entity.compress.CompressingFactory;
33+
3234
/**
3335
* Factory for decorated {@link InputStream}s.
3436
*
3537
* @since 4.4
36-
* @deprecated Use {@link CompressorFactory} to retrieve appropriate {@link InputStream}s for compression handling.
38+
* @deprecated Use {@link CompressingFactory} to retrieve appropriate {@link InputStream}s for compression handling.
3739
*/
3840
@Deprecated
3941
public interface InputStreamFactory {

httpclient5/src/main/java/org/apache/hc/client5/http/entity/LazyDecompressingInputStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
/**
3737
* Lazy initializes from an {@link InputStream} wrapper.
38-
* @deprecated Use {@link LazyDecompressInputStream}
38+
* @deprecated Use {@link org.apache.hc.client5.http.entity.compress.LazyDecompressingInputStream}
3939
*/
4040
@Deprecated
4141
class LazyDecompressingInputStream extends FilterInputStream {

httpclient5/src/main/java/org/apache/hc/client5/http/entity/CompressingEntity.java renamed to httpclient5/src/main/java/org/apache/hc/client5/http/entity/compress/CompressingEntity.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* <http://www.apache.org/>.
2525
*
2626
*/
27-
package org.apache.hc.client5.http.entity;
27+
package org.apache.hc.client5.http.entity.compress;
2828

2929
import java.io.IOException;
3030
import java.io.InputStream;
@@ -40,7 +40,7 @@
4040
* an output stream. This class supports various compression algorithms based on the
4141
* specified content encoding.
4242
*
43-
* <p>Compression is performed using {@link CompressorFactory}, which returns a corresponding
43+
* <p>Compression is performed using {@link CompressingFactory}, which returns a corresponding
4444
* {@link OutputStream} for the requested compression type. This class does not support
4545
* reading the content directly through {@link #getContent()} as the content is always compressed
4646
* during write operations.</p>
@@ -108,20 +108,17 @@ public InputStream getContent() throws IOException {
108108
@Override
109109
public void writeTo(final OutputStream outStream) throws IOException {
110110
Args.notNull(outStream, "Output stream");
111-
// Get the compressor based on the specified content encoding
112-
final OutputStream compressorStream;
113-
try {
114-
compressorStream = CompressorFactory.INSTANCE.getCompressorOutputStream(contentEncoding, outStream);
111+
112+
try (final OutputStream compressorStream = CompressingFactory.INSTANCE.getCompressorOutputStream(contentEncoding, outStream)) {
113+
if (compressorStream != null) {
114+
// Write compressed data
115+
super.writeTo(compressorStream);
116+
} else {
117+
throw new UnsupportedOperationException("Unsupported compression: " + contentEncoding);
118+
}
115119
} catch (final CompressorException e) {
116-
throw new IOException("Error initializing decompression stream", e);
117-
}
118-
if (compressorStream != null) {
119-
// Write compressed data
120-
super.writeTo(compressorStream);
121-
// Close the compressor stream after writing
122-
compressorStream.close();
123-
} else {
124-
throw new UnsupportedOperationException("Unsupported compression: " + contentEncoding);
120+
throw new IOException("Error initializing compression stream", e);
125121
}
126122
}
123+
127124
}

0 commit comments

Comments
 (0)