File tree Expand file tree Collapse file tree 10 files changed +84
-7
lines changed
src/main/java/com/rabbitmq/stream Expand file tree Collapse file tree 10 files changed +84
-7
lines changed Original file line number Diff line number Diff line change 1818 * Codec to encode and decode messages.
1919 *
2020 * <p>The codec is expected to use the AMQP 1.0 message format.
21+ *
22+ * <p>This is considered a SPI and is susceptible to change at any time.
2123 */
2224public interface Codec {
2325
Original file line number Diff line number Diff line change 1+ /**
2+ * Implementations of AMQP 1.0 {@link com.rabbitmq.stream.Codec}.
3+ *
4+ * <p>Classes and interfaces in this package are considered SPI and are susceptible to change at any
5+ * time.
6+ */
7+ package com .rabbitmq .stream .codec ;
Original file line number Diff line number Diff line change 1919import com .rabbitmq .stream .compression .CompressionUtils .CommonsCompressSnappyCompressionCodec ;
2020import com .rabbitmq .stream .compression .CompressionUtils .CommonsCompressZstdCompressionCodec ;
2121
22+ /**
23+ * {@link CompressionCodecFactory} creating codecs using <a
24+ * href="https://commons.apache.org/proper/commons-compress/">Apache Commons Compress</a>
25+ * implementations.
26+ *
27+ * The framed format is used for SNAPPY and LZ4.
28+ *
29+ * All but ZSTD compression codecs are implemented in Commons Compress. The ZSTD codec
30+ * uses the <a href="https://github.com/luben/zstd-jni/">zstd-jni</a> library.
31+ */
2232public class CommonsCompressCompressionCodecFactory implements CompressionCodecFactory {
2333 private final CompressionCodec [] codecs = new CompressionCodec [5 ];
2434
Original file line number Diff line number Diff line change 1414
1515package com .rabbitmq .stream .compression ;
1616
17+ /** Enum to define types of compression codecs. */
1718public enum Compression {
1819 NONE ((byte ) 0 ),
1920 GZIP ((byte ) 1 ),
@@ -29,11 +30,11 @@ public enum Compression {
2930 this .code = code ;
3031 }
3132
32- public byte code () {
33- return this .code ;
34- }
35-
3633 public static Compression get (byte code ) {
3734 return COMPRESSIONS [code ];
3835 }
36+
37+ public byte code () {
38+ return this .code ;
39+ }
3940}
Original file line number Diff line number Diff line change 1818import java .io .InputStream ;
1919import java .io .OutputStream ;
2020
21+ /** Codec to compress and decompress sub-entries. */
2122public interface CompressionCodec {
2223
24+ /**
25+ * Provides the maximum compressed size from the source length.
26+ *
27+ * @param sourceLength size of plain, uncompressed data
28+ * @return maximum compressed size
29+ */
2330 int maxCompressedLength (int sourceLength );
2431
25- OutputStream compress (ByteBuf byteBuf );
32+ /**
33+ * Creates an {@link OutputStream} to compress data.
34+ *
35+ * @param target {@link ByteBuf} to write compressed data to
36+ * @return output stream to write plain data to
37+ */
38+ OutputStream compress (ByteBuf target );
2639
27- InputStream decompress (ByteBuf byteBuf );
40+ /**
41+ * Creates an {@link InputStream} to read decompressed data from.
42+ *
43+ * @param source the {@link ByteBuf} to read compressed from
44+ * @return input stream to read decompressed from
45+ */
46+ InputStream decompress (ByteBuf source );
2847
48+ /**
49+ * Return the code for this type of codec.
50+ *
51+ * @return compression code
52+ */
2953 byte code ();
3054}
Original file line number Diff line number Diff line change 1414
1515package com .rabbitmq .stream .compression ;
1616
17+ /**
18+ * Factory to create {@link CompressionCodec} instances.
19+ */
1720public interface CompressionCodecFactory {
1821
22+ /**
23+ * Get a compression codec for a given type of compression.
24+ * @param compression the type of compression codec
25+ * @return the appropriate compression codec
26+ */
1927 CompressionCodec get (Compression compression );
20- }
28+ }
Original file line number Diff line number Diff line change 3030import org .xerial .snappy .SnappyFramedInputStream ;
3131import org .xerial .snappy .SnappyFramedOutputStream ;
3232
33+ /**
34+ * Implementation of {@link CompressionCodec}s.
35+ */
3336public final class CompressionUtils {
3437
3538 private CompressionUtils () {}
Original file line number Diff line number Diff line change 1919import com .rabbitmq .stream .compression .CompressionUtils .XerialSnappyCompressionCodec ;
2020import com .rabbitmq .stream .compression .CompressionUtils .ZstdJniCompressionCodec ;
2121
22+ /**
23+ * {@link CompressionCodecFactory} implementation using various compression libraries.
24+ *
25+ * <p>The GZIP codec is based on the JDK implementation, the SNAPPY codec uses <a
26+ * href="https://github.com/xerial/snappy-java">Xerial Snappy</a> (framed), the LZ4 codec uses <a
27+ * href="https://github.com/lz4/lz4-java">LZ4 Java</a> (framed), the ZSTD codec uses <a
28+ * href="https://github.com/luben/zstd-jni/">zstd-jni</a>.
29+ */
2230public class DefaultCompressionCodecFactory implements CompressionCodecFactory {
2331
2432 private final CompressionCodec [] codecs = new CompressionCodec [5 ];
Original file line number Diff line number Diff line change 1+ /**
2+ * Compression codec utilities to compress and decompress sub-entries.
3+ *
4+ * <p>Classes and interfaces in this package are considered SPI and are susceptible to change at any
5+ * time.
6+ */
7+ package com .rabbitmq .stream .compression ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Package for metrics collection utilities.
3+ *
4+ * <p>Classes and interfaces in this package are considered SPI and are susceptible to change at any
5+ * time.
6+ */
7+ package com .rabbitmq .stream .metrics ;
You can’t perform that action at this time.
0 commit comments