Skip to content

Commit 2dd2d5e

Browse files
committed
Add Javadoc for compression
1 parent ca9884f commit 2dd2d5e

File tree

10 files changed

+84
-7
lines changed

10 files changed

+84
-7
lines changed

src/main/java/com/rabbitmq/stream/Codec.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
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
*/
2224
public interface Codec {
2325

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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;

src/main/java/com/rabbitmq/stream/compression/CommonsCompressCompressionCodecFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@
1919
import com.rabbitmq.stream.compression.CompressionUtils.CommonsCompressSnappyCompressionCodec;
2020
import 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+
*/
2232
public class CommonsCompressCompressionCodecFactory implements CompressionCodecFactory {
2333
private final CompressionCodec[] codecs = new CompressionCodec[5];
2434

src/main/java/com/rabbitmq/stream/compression/Compression.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.rabbitmq.stream.compression;
1616

17+
/** Enum to define types of compression codecs. */
1718
public 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
}

src/main/java/com/rabbitmq/stream/compression/CompressionCodec.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,37 @@
1818
import java.io.InputStream;
1919
import java.io.OutputStream;
2020

21+
/** Codec to compress and decompress sub-entries. */
2122
public 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
}

src/main/java/com/rabbitmq/stream/compression/CompressionCodecFactory.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414

1515
package com.rabbitmq.stream.compression;
1616

17+
/**
18+
* Factory to create {@link CompressionCodec} instances.
19+
*/
1720
public 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+
}

src/main/java/com/rabbitmq/stream/compression/CompressionUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import org.xerial.snappy.SnappyFramedInputStream;
3131
import org.xerial.snappy.SnappyFramedOutputStream;
3232

33+
/**
34+
* Implementation of {@link CompressionCodec}s.
35+
*/
3336
public final class CompressionUtils {
3437

3538
private CompressionUtils() {}

src/main/java/com/rabbitmq/stream/compression/DefaultCompressionCodecFactory.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
import com.rabbitmq.stream.compression.CompressionUtils.XerialSnappyCompressionCodec;
2020
import 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+
*/
2230
public class DefaultCompressionCodecFactory implements CompressionCodecFactory {
2331

2432
private final CompressionCodec[] codecs = new CompressionCodec[5];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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;

0 commit comments

Comments
 (0)