pgpainless/pgpainless-core/src/main/java/org/pgpainless/algorithm/CompressionAlgorithm.java

58 lines
1.5 KiB
Java
Raw Normal View History

2021-10-07 15:48:52 +02:00
// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.algorithm;
2018-06-02 21:21:35 +02:00
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
2018-06-02 21:21:35 +02:00
import org.bouncycastle.bcpg.CompressionAlgorithmTags;
2021-04-25 13:28:33 +02:00
/**
* Enumeration of possible compression algorithms.
*
* @see <a href="https://tools.ietf.org/html/rfc4880#section-9.3">RFC4880: Compression Algorithm Tags</a>
*/
2018-06-02 21:21:35 +02:00
public enum CompressionAlgorithm {
2018-07-02 21:40:59 +02:00
UNCOMPRESSED (CompressionAlgorithmTags.UNCOMPRESSED),
ZIP (CompressionAlgorithmTags.ZIP),
ZLIB (CompressionAlgorithmTags.ZLIB),
BZIP2 (CompressionAlgorithmTags.BZIP2),
2018-06-02 21:21:35 +02:00
;
private static final Map<Integer, CompressionAlgorithm> MAP = new ConcurrentHashMap<>();
2018-06-02 21:21:35 +02:00
static {
for (CompressionAlgorithm c : CompressionAlgorithm.values()) {
MAP.put(c.algorithmId, c);
}
}
2021-04-25 13:28:33 +02:00
/**
* Return the {@link CompressionAlgorithm} value that corresponds to the provided numerical id.
* If an invalid id is provided, null is returned.
*
* @param id id
* @return compression algorithm
*/
2018-06-02 21:21:35 +02:00
public static CompressionAlgorithm fromId(int id) {
return MAP.get(id);
}
private final int algorithmId;
CompressionAlgorithm(int id) {
this.algorithmId = id;
}
2021-04-25 13:28:33 +02:00
/**
* Return the numerical algorithm tag corresponding to this compression algorithm.
* @return id
*/
2018-06-02 21:21:35 +02:00
public int getAlgorithmId() {
return algorithmId;
}
}