beam-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lc...@apache.org
Subject [1/3] beam git commit: [BEAM-2060] Use withCharset(Charset) for the user facing API
Date Mon, 24 Apr 2017 16:21:55 GMT
Repository: beam
Updated Branches:
  refs/heads/master 9c396826c -> d6dddee23


[BEAM-2060] Use withCharset(Charset) for the user facing API


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

Branch: refs/heads/master
Commit: 7c7ece300055667a076fee99defd62d1fd749232
Parents: ffc7781
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Mon Apr 24 17:57:03 2017 +0200
Committer: Luke Cwik <lcwik@google.com>
Committed: Mon Apr 24 09:21:20 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/beam/sdk/io/xml/XmlIO.java  | 21 ++++++-----------
 .../apache/beam/sdk/io/xml/XmlSourceTest.java   | 24 +-------------------
 2 files changed, 8 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/beam/blob/7c7ece30/sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/XmlIO.java
----------------------------------------------------------------------
diff --git a/sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/XmlIO.java b/sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/XmlIO.java
index ef07925..f8a9edc 100644
--- a/sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/XmlIO.java
+++ b/sdks/java/io/xml/src/main/java/org/apache/beam/sdk/io/xml/XmlIO.java
@@ -22,6 +22,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import com.google.auto.value.AutoValue;
 import com.google.common.annotations.VisibleForTesting;
 
+import java.nio.charset.Charset;
+
 import javax.annotation.Nullable;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
@@ -79,7 +81,7 @@ public class XmlIO {
    * }</pre>
    *
    * <p>By default, UTF-8 charset is used. If your file is using a different charset,
you have to
-   * specify as follow:
+   * specify the following:
    *
    * <pre>{@code
    * PCollection<String> output = p.apply(XmlIO.<Record>read()
@@ -87,19 +89,10 @@ public class XmlIO {
    *      .withRooElement("root")
    *      .withRecordElement("record")
    *      .withRecordClass(Record.class)
-   *      .withCharset("ISO-8859-1"));
+   *      .withCharset(StandardCharsets.ISO_8859_1));
    * }</pre>
    *
-   * <p>Or:
-   *
-   * <pre>{@code
-   * PCollection<String> output = p.apply(XmlIO.<Record>read()
-   *      .from(file.toPath().toString())
-   *      .withRooElement("root")
-   *      .withRecordElement("record")
-   *      .withRecordClass(Record.class)
-   *      .withCharset(StandardCharsets.ISO_8859_1.name()));
-   * }</pre>
+   * <p>{@link java.nio.charset.StandardCharsets} provides static references to common
charsets.
    *
    * <p>Currently, only XML files that use single-byte characters are supported. Using
a file that
    * contains multi-byte characters may result in data loss or duplication.
@@ -358,8 +351,8 @@ public class XmlIO {
     /**
      * Sets the XML file charset.
      */
-    public Read<T> withCharset(String charset) {
-      return toBuilder().setCharset(charset).build();
+    public Read<T> withCharset(Charset charset) {
+      return toBuilder().setCharset(charset.name()).build();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/beam/blob/7c7ece30/sdks/java/io/xml/src/test/java/org/apache/beam/sdk/io/xml/XmlSourceTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/io/xml/src/test/java/org/apache/beam/sdk/io/xml/XmlSourceTest.java
b/sdks/java/io/xml/src/test/java/org/apache/beam/sdk/io/xml/XmlSourceTest.java
index 9321ac3..3deee3e 100644
--- a/sdks/java/io/xml/src/test/java/org/apache/beam/sdk/io/xml/XmlSourceTest.java
+++ b/sdks/java/io/xml/src/test/java/org/apache/beam/sdk/io/xml/XmlSourceTest.java
@@ -611,29 +611,7 @@ public class XmlSourceTest {
                 .withRecordElement("train")
                 .withRecordClass(Train.class)
                 .withMinBundleSize(1024)
-                .withCharset(StandardCharsets.ISO_8859_1.name()));
-
-    List<Train> expectedResults =
-        ImmutableList.of(new Train("Cédric", 7, "blue", "small"));
-
-    PAssert.that(output).containsInAnyOrder(expectedResults);
-    p.run();
-  }
-
-  @Test
-  public void testReadXMLWithCharsetAsString() throws IOException {
-    File file = tempFolder.newFile("trainXMLISO88591");
-    Files.write(file.toPath(), trainXMLWithISO88591.getBytes(StandardCharsets.ISO_8859_1));
-
-    PCollection<Train> output =
-        p.apply("ReadFileData",
-            XmlIO.<Train>read()
-                .from(file.toPath().toString())
-                .withRootElement("trains")
-                .withRecordElement("train")
-                .withRecordClass(Train.class)
-                .withMinBundleSize(1024)
-                .withCharset("ISO-8859-1"));
+                .withCharset(StandardCharsets.ISO_8859_1));
 
     List<Train> expectedResults =
         ImmutableList.of(new Train("Cédric", 7, "blue", "small"));


Mime
View raw message