You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by dh...@apache.org on 2017/02/23 00:20:25 UTC

[2/4] beam git commit: Add SerializableConfiguration

Add SerializableConfiguration


Project: http://git-wip-us.apache.org/repos/asf/beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/beam/commit/2b1c084e
Tree: http://git-wip-us.apache.org/repos/asf/beam/tree/2b1c084e
Diff: http://git-wip-us.apache.org/repos/asf/beam/diff/2b1c084e

Branch: refs/heads/master
Commit: 2b1c084efeff863e2dee56fc7243b68b38c43d08
Parents: ff208cc
Author: Rafal Wojdyla <ra...@spotify.com>
Authored: Thu Feb 16 00:22:41 2017 -0500
Committer: Dan Halperin <dh...@google.com>
Committed: Wed Feb 22 16:20:14 2017 -0800

----------------------------------------------------------------------
 .../sdk/io/hdfs/SerializableConfiguration.java  | 67 ++++++++++++++++++++
 1 file changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/2b1c084e/sdks/java/io/hdfs/src/main/java/org/apache/beam/sdk/io/hdfs/SerializableConfiguration.java
----------------------------------------------------------------------
diff --git a/sdks/java/io/hdfs/src/main/java/org/apache/beam/sdk/io/hdfs/SerializableConfiguration.java b/sdks/java/io/hdfs/src/main/java/org/apache/beam/sdk/io/hdfs/SerializableConfiguration.java
new file mode 100644
index 0000000..f7b4bff
--- /dev/null
+++ b/sdks/java/io/hdfs/src/main/java/org/apache/beam/sdk/io/hdfs/SerializableConfiguration.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.sdk.io.hdfs;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Map;
+import javax.annotation.Nullable;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.mapreduce.Job;
+
+/**
+ * A wrapper to allow Hadoop {@link Configuration}s to be serialized using Java's standard
+ * serialization mechanisms.
+ */
+public class SerializableConfiguration implements Externalizable {
+  private static final long serialVersionUID = 0L;
+
+  private Configuration conf;
+
+  public SerializableConfiguration() {
+  }
+
+  public SerializableConfiguration(Configuration conf) {
+    this.conf = conf;
+  }
+
+  public Configuration get() {
+    return conf;
+  }
+
+  @Override
+  public void writeExternal(ObjectOutput out) throws IOException {
+    out.writeInt(conf.size());
+    for (Map.Entry<String, String> entry : conf) {
+      out.writeUTF(entry.getKey());
+      out.writeUTF(entry.getValue());
+    }
+  }
+
+  @Override
+  public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+    conf = new Configuration();
+    int size = in.readInt();
+    for (int i = 0; i < size; i++) {
+      conf.set(in.readUTF(), in.readUTF());
+    }
+  }
+
+}