]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/java/src/main/java/org/rocksdb/CompressionType.java
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / rocksdb / java / src / main / java / org / rocksdb / CompressionType.java
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.
5
6 package org.rocksdb;
7
8 /**
9 * Enum CompressionType
10 *
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>
15 */
16 public enum CompressionType {
17
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);
27
28 /**
29 * <p>Get the CompressionType enumeration value by
30 * passing the library name to this method.</p>
31 *
32 * <p>If library cannot be found the enumeration
33 * value {@code NO_COMPRESSION} will be returned.</p>
34 *
35 * @param libraryName compression library name.
36 *
37 * @return CompressionType instance.
38 */
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;
45 }
46 }
47 }
48 return CompressionType.NO_COMPRESSION;
49 }
50
51 /**
52 * <p>Get the CompressionType enumeration value by
53 * passing the byte identifier to this method.</p>
54 *
55 * @param byteIdentifier of CompressionType.
56 *
57 * @return CompressionType instance.
58 *
59 * @throws IllegalArgumentException If CompressionType cannot be found for the
60 * provided byteIdentifier
61 */
62 public static CompressionType getCompressionType(byte byteIdentifier) {
63 for (final CompressionType compressionType : CompressionType.values()) {
64 if (compressionType.getValue() == byteIdentifier) {
65 return compressionType;
66 }
67 }
68
69 throw new IllegalArgumentException(
70 "Illegal value provided for CompressionType.");
71 }
72
73 /**
74 * <p>Returns the byte value of the enumerations value.</p>
75 *
76 * @return byte representation
77 */
78 public byte getValue() {
79 return value_;
80 }
81
82 /**
83 * <p>Returns the library name of the compression type
84 * identified by the enumeration value.</p>
85 *
86 * @return library name
87 */
88 public String getLibraryName() {
89 return libraryName_;
90 }
91
92 CompressionType(final byte value, final String libraryName) {
93 value_ = value;
94 libraryName_ = libraryName;
95 }
96
97 private final byte value_;
98 private final String libraryName_;
99 }