You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by dk...@apache.org on 2018/11/08 19:08:46 UTC

[avro] 01/02: Since we will no longer support java6 and 7, remove the "optimizations" for those

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

dkulp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git

commit 207d4ff95d4dd48a4267e3d2577f86b304d0b11b
Author: Daniel Kulp <dk...@apache.org>
AuthorDate: Thu Nov 8 13:10:44 2018 -0500

    Since we will no longer support java6 and 7, remove the "optimizations" for those
---
 .../src/main/java/org/apache/avro/util/Utf8.java   | 37 ++--------------------
 1 file changed, 2 insertions(+), 35 deletions(-)

diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java b/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
index 6f4ec58..dd359dd 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/Utf8.java
@@ -18,7 +18,6 @@
 package org.apache.avro.util;
 
 import java.nio.charset.Charset;
-import java.io.UnsupportedEncodingException;
 
 import org.apache.avro.io.BinaryData;
 
@@ -92,43 +91,11 @@ public class Utf8 implements Comparable<Utf8>, CharSequence {
     return this;
   }
 
-  private abstract static class Utf8Converter {
-    public abstract String fromUtf8(byte[] bytes, int length);
-    public abstract byte[] toUtf8(String str);
-  }
-
-  private static final Utf8Converter UTF8_CONVERTER =
-    System.getProperty("java.version").startsWith("1.6.")
-    ? new Utf8Converter() {                       // optimized for Java 6
-        public String fromUtf8(byte[] bytes, int length) {
-          try {
-            return new String(bytes, 0, length, "UTF-8");
-          } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException(e);
-          }
-        }
-        public byte[] toUtf8(String str) {
-          try {
-            return str.getBytes("UTF-8");
-          } catch (UnsupportedEncodingException e) {
-            throw new RuntimeException(e);
-          }
-        }
-      }
-    : new Utf8Converter() {                       // faster in Java 7 & 8
-        public String fromUtf8(byte[] bytes, int length) {
-          return new String(bytes, 0, length, UTF8);
-        }
-        public byte[] toUtf8(String str) {
-          return str.getBytes(UTF8);
-        }
-      };
-
   @Override
   public String toString() {
     if (this.length == 0) return "";
     if (this.string == null) {
-      this.string = UTF8_CONVERTER.fromUtf8(bytes, length);
+      this.string = new String(bytes, 0, length, UTF8);
     }
     return this.string;
   }
@@ -169,7 +136,7 @@ public class Utf8 implements Comparable<Utf8>, CharSequence {
 
   /** Gets the UTF-8 bytes for a String */
   public static final byte[] getBytesFor(String str) {
-    return UTF8_CONVERTER.toUtf8(str);
+    return str.getBytes(UTF8);
   }
 
 }