1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
2 // This source code is licensed under the BSD-style license found in the
3 // LICENSE file in the root directory of this source tree. An additional grant
4 // of patent rights can be found in the PATENTS file in the same directory.
11 * <p>DB contents are stored in a set of blocks, each of which holds a
12 * sequence of key,value pairs. Each block may be compressed before
13 * being stored in a file. The following enum describes which
14 * compression method (if any) is used to compress a block.</p>
16 public enum CompressionType
{
18 NO_COMPRESSION((byte) 0x0, null),
19 SNAPPY_COMPRESSION((byte) 0x1, "snappy"),
20 ZLIB_COMPRESSION((byte) 0x2, "z"),
21 BZLIB2_COMPRESSION((byte) 0x3, "bzip2"),
22 LZ4_COMPRESSION((byte) 0x4, "lz4"),
23 LZ4HC_COMPRESSION((byte) 0x5, "lz4hc"),
24 XPRESS_COMPRESSION((byte) 0x6, "xpress"),
25 ZSTD_COMPRESSION((byte)0x7, "zstd"),
26 DISABLE_COMPRESSION_OPTION((byte)0x7F, null);
29 * <p>Get the CompressionType enumeration value by
30 * passing the library name to this method.</p>
32 * <p>If library cannot be found the enumeration
33 * value {@code NO_COMPRESSION} will be returned.</p>
35 * @param libraryName compression library name.
37 * @return CompressionType instance.
39 public static CompressionType
getCompressionType(String libraryName
) {
40 if (libraryName
!= null) {
41 for (CompressionType compressionType
: CompressionType
.values()) {
42 if (compressionType
.getLibraryName() != null &&
43 compressionType
.getLibraryName().equals(libraryName
)) {
44 return compressionType
;
48 return CompressionType
.NO_COMPRESSION
;
52 * <p>Get the CompressionType enumeration value by
53 * passing the byte identifier to this method.</p>
55 * @param byteIdentifier of CompressionType.
57 * @return CompressionType instance.
59 * @throws IllegalArgumentException If CompressionType cannot be found for the
60 * provided byteIdentifier
62 public static CompressionType
getCompressionType(byte byteIdentifier
) {
63 for (final CompressionType compressionType
: CompressionType
.values()) {
64 if (compressionType
.getValue() == byteIdentifier
) {
65 return compressionType
;
69 throw new IllegalArgumentException(
70 "Illegal value provided for CompressionType.");
74 * <p>Returns the byte value of the enumerations value.</p>
76 * @return byte representation
78 public byte getValue() {
83 * <p>Returns the library name of the compression type
84 * identified by the enumeration value.</p>
86 * @return library name
88 public String
getLibraryName() {
92 CompressionType(final byte value
, final String libraryName
) {
94 libraryName_
= libraryName
;
97 private final byte value_
;
98 private final String libraryName_
;