You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/01/17 07:16:42 UTC

[avro] branch branch-1.11 updated: Use StandardCharsets and try-with-resources

This is an automated email from the ASF dual-hosted git repository.

mgrigorov pushed a commit to branch branch-1.11
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/branch-1.11 by this push:
     new 02a0b72  Use StandardCharsets and try-with-resources
02a0b72 is described below

commit 02a0b72889579e391b74f06709f0b4e9d4616ef3
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
AuthorDate: Mon Jan 17 09:11:41 2022 +0200

    Use StandardCharsets and try-with-resources
    
    Signed-off-by: Martin Tzvetanov Grigorov <mg...@apache.org>
    (cherry picked from commit 9ea105c793af3459c6aa492ff9898f37defd70e1)
---
 .../avro/src/main/java/org/apache/avro/util/RandomData.java | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java b/lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java
index e4623fc..8806920 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/RandomData.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -143,7 +144,7 @@ public class RandomData implements Iterable<Object> {
     }
   }
 
-  private static final Charset UTF8 = Charset.forName("UTF-8");
+  private static final Charset UTF8 = StandardCharsets.UTF_8;
 
   private Object randomString(Random random, int maxLength) {
     int length = random.nextInt(maxLength);
@@ -167,15 +168,13 @@ public class RandomData implements Iterable<Object> {
       System.exit(-1);
     }
     Schema sch = new Schema.Parser().parse(new File(args[0]));
-    DataFileWriter<Object> writer = new DataFileWriter<>(new GenericDatumWriter<>());
-    writer.setCodec(CodecFactory.fromString(args.length >= 4 ? args[3] : "null"));
-    writer.create(sch, new File(args[1]));
-    try {
+    try (DataFileWriter<Object> writer = new DataFileWriter<>(new GenericDatumWriter<>())) {
+      writer.setCodec(CodecFactory.fromString(args.length >= 4 ? args[3] : "null"));
+      writer.create(sch, new File(args[1]));
+
       for (Object datum : new RandomData(sch, Integer.parseInt(args[2]))) {
         writer.append(datum);
       }
-    } finally {
-      writer.close();
     }
   }
 }