[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/release] Move FileType and add PLAIN FileType for no compression.
commit 4ee320caeace98776e7bd51f054df7641b7c3eb1
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date: Fri Jul 28 07:53:30 2017 +0000
Move FileType and add PLAIN FileType for no compression.
---
.../org/torproject/descriptor/index/IndexNode.java | 2 ++
.../descriptor/{index => internal}/FileType.java | 24 ++++++++++++++++++++--
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/torproject/descriptor/index/IndexNode.java b/src/main/java/org/torproject/descriptor/index/IndexNode.java
index c7a79a0..516bbdf 100644
--- a/src/main/java/org/torproject/descriptor/index/IndexNode.java
+++ b/src/main/java/org/torproject/descriptor/index/IndexNode.java
@@ -3,6 +3,8 @@
package org.torproject.descriptor.index;
+import org.torproject.descriptor.internal.FileType;
+
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;
diff --git a/src/main/java/org/torproject/descriptor/index/FileType.java b/src/main/java/org/torproject/descriptor/internal/FileType.java
similarity index 69%
rename from src/main/java/org/torproject/descriptor/index/FileType.java
rename to src/main/java/org/torproject/descriptor/internal/FileType.java
index 9bb7e5f..47bbd28 100644
--- a/src/main/java/org/torproject/descriptor/index/FileType.java
+++ b/src/main/java/org/torproject/descriptor/internal/FileType.java
@@ -1,7 +1,7 @@
/* Copyright 2016--2017 The Tor Project
* See LICENSE for licensing information */
-package org.torproject.descriptor.index;
+package org.torproject.descriptor.internal;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
@@ -16,14 +16,20 @@ import java.io.InputStream;
import java.io.OutputStream;
/**
- * A file type enum provides all compression functionality.
+ * These enums provide compression functionality.
+ *
+ * <p>{@link #findType} determines the compression type by the given extension.
+ * Compression can also be zero-compression, which is currently provided by
+ * the PLAIN and JSON enums.</p>
*
* @since 1.4.0
*/
public enum FileType {
+
BZ2(BZip2CompressorInputStream.class, BZip2CompressorOutputStream.class),
GZ(GzipCompressorInputStream.class, GzipCompressorOutputStream.class),
JSON(BufferedInputStream.class, BufferedOutputStream.class),
+ PLAIN(BufferedInputStream.class, BufferedOutputStream.class),
XZ(XZCompressorInputStream.class, XZCompressorOutputStream.class);
private final Class<? extends InputStream> inClass;
@@ -34,6 +40,20 @@ public enum FileType {
this.outClass = out;
}
+ /**
+ * Returns <code>valueOf</code> or the default enum {@link #PLAIN}, i.e.,
+ * this method doesn't throw any exceptions and allways returns a valid enum.
+ */
+ public static FileType findType(String ext) {
+ FileType res = null;
+ try {
+ res = FileType.valueOf(ext.toUpperCase());
+ return res;
+ } catch (IllegalArgumentException | NullPointerException re) {
+ return PLAIN;
+ }
+ }
+
/** Return the appropriate input stream. */
public InputStream inputStream(InputStream is) throws Exception {
return this.inClass.getConstructor(new Class[]{InputStream.class})
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits