org.apache.hc.client5.http.async.methods

## Class DeflatingZstdEntityProducer

- java.lang.Object
- - org.apache.hc.client5.http.async.methods.DeflatingZstdEntityProducer

All Implemented Interfaces:
  EntityDetails, AsyncDataProducer, AsyncEntityProducer, ResourceHolder

    public final class DeflatingZstdEntityProducer
    extends Object
    implements AsyncEntityProducer

`AsyncEntityProducer` that compresses the bytes produced by a delegate entity into a single Zstandard (zstd) frame on the fly.

This producer wraps a `AsyncEntityProducer` and performs streaming, ByteBuffer-to-ByteBuffer compression as the delegate writes to the provided `DataStreamChannel`. No `InputStream` is used in the client pipeline.

Metadata reported by this producer:

- `getContentEncoding()` returns `"zstd"`.
- `getContentLength()` returns `-1` (unknown after compression).
- `isChunked()` returns `true` (requests are typically sent chunked).

Behavior

- Streaming & back-pressure: compressed output is staged in direct `ByteBuffer`s and written only when the channel accepts bytes. When `DataStreamChannel.write(...)` returns `0`, the producer pauses and requests another output turn.
- Finalization: after the delegate signals `endStream()`, this producer emits the zstd frame epilogue and then calls `DataStreamChannel.endStream()`.
- Repeatability: repeatable only if the delegate is repeatable.
- Headers: callers are responsible for sending `Content-Encoding: zstd` on the request if required by the server. Content length is not known in advance.
- Resources: invoke `releaseResources()` to free native compressor resources.

Constructors

- `DeflatingZstdEntityProducer(delegate)` – uses a default compression level.
- `DeflatingZstdEntityProducer(delegate, level)` – explicitly sets the zstd level.

Thread-safety

Not thread-safe; one instance per message exchange.

Runtime dependency

Requires `com.github.luben:zstd-jni` on the classpath.

Since:
  5.6
See Also:
  `InflatingZstdDataConsumer`, `BasicRequestProducer`, `StringAsyncEntityProducer`, `ContentCompressionAsyncExec`

### Constructor Summary

Constructors
Constructor and Description
`DeflatingZstdEntityProducer(AsyncEntityProducer delegate)`
`DeflatingZstdEntityProducer(AsyncEntityProducer delegate, int level)`

### Method Summary

All Methods Instance Methods Concrete Methods
`int` `available()`
`void` `failed(Exception cause)`
`String` `getContentEncoding()`
`long` `getContentLength()`
`String` `getContentType()`
`Set<String>` `getTrailerNames()`
`boolean` `isChunked()`
`boolean` `isRepeatable()`
`void` `produce(DataStreamChannel chan)`
`void` `releaseResources()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### DeflatingZstdEntityProducer

    public DeflatingZstdEntityProducer(AsyncEntityProducer delegate)

#### DeflatingZstdEntityProducer

    public DeflatingZstdEntityProducer(AsyncEntityProducer delegate,
                                       int level)

### Method Detail

#### isRepeatable

    public boolean isRepeatable()

Specified by:
  `isRepeatable` in interface `AsyncEntityProducer`

#### getContentLength

    public long getContentLength()

Specified by:
  `getContentLength` in interface `EntityDetails`

#### getContentType

    public String getContentType()

Specified by:
  `getContentType` in interface `EntityDetails`

#### getContentEncoding

    public String getContentEncoding()

Specified by:
  `getContentEncoding` in interface `EntityDetails`

#### isChunked

    public boolean isChunked()

Specified by:
  `isChunked` in interface `EntityDetails`

#### getTrailerNames

    public Set<String> getTrailerNames()

Specified by:
  `getTrailerNames` in interface `EntityDetails`

#### available

    public int available()

Specified by:
  `available` in interface `AsyncDataProducer`

#### produce

    public void produce(DataStreamChannel chan)
                 throws IOException

Specified by:
  `produce` in interface `AsyncDataProducer`
Throws:
  `IOException`

#### failed

    public void failed(Exception cause)

Specified by:
  `failed` in interface `AsyncEntityProducer`

#### releaseResources

    public void releaseResources()

Specified by:
  `releaseResources` in interface `ResourceHolder`