Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding utility classe to completely hide Thrift

  • Loading branch information...
commit 10169144fbae98264f67b551793a514005107d0e 1 parent fa82762
Julien Le Dem julienledem authored
Showing with 61 additions and 0 deletions.
  1. +61 −0 src/main/java/parquet/format/Util.java
61 src/main/java/parquet/format/Util.java
View
@@ -0,0 +1,61 @@
+package parquet.format;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.thrift.TBase;
+import org.apache.thrift.TException;
+import org.apache.thrift.protocol.TCompactProtocol;
+import org.apache.thrift.transport.TIOStreamTransport;
+
+/**
+ * Utility to read/write metadata
+ * We use the TCompactProtocol to serialize metadata
+ *
+ * @author Julien Le Dem
+ *
+ */
+public class Util {
+
+ public static void writePageHeader(PageHeader pageHeader, OutputStream to) throws IOException {
+ write(pageHeader, to);
+ }
+
+ public static PageHeader readPageHeader(InputStream from) throws IOException {
+ return read(from, new PageHeader());
+ }
+
+ public static void writeFileMetaData(parquet.format.FileMetaData fileMetadata, OutputStream to) throws IOException {
+ write(fileMetadata, to);
+ }
+
+ public static FileMetaData readFileMetaData(InputStream from) throws IOException {
+ return read(from, new FileMetaData());
+ }
+
+ private static TCompactProtocol protocol(OutputStream to) {
+ return new TCompactProtocol(new TIOStreamTransport(to));
+ }
+
+ private static TCompactProtocol protocol(InputStream from) {
+ return new TCompactProtocol(new TIOStreamTransport(from));
+ }
+
+ private static <T extends TBase<?,?>> T read(InputStream from, T tbase) throws IOException {
+ try {
+ tbase.read(protocol(from));
+ return tbase;
+ } catch (TException e) {
+ throw new IOException("can not read " + tbase.getClass() + ": " + e.getMessage(), e);
+ }
+ }
+
+ private static void write(TBase<?, ?> tbase, OutputStream to) throws IOException {
+ try {
+ tbase.write(protocol(to));
+ } catch (TException e) {
+ throw new IOException("can not write " + tbase, e);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.