diff options
Diffstat (limited to 'vespajlib/src/main/java/com')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/io/IOUtils.java | 16 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/io/ReadLine.java | 11 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/text/StringUtilities.java | 14 |
3 files changed, 18 insertions, 23 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/io/IOUtils.java b/vespajlib/src/main/java/com/yahoo/io/IOUtils.java index f2de0ace476..266b7857363 100644 --- a/vespajlib/src/main/java/com/yahoo/io/IOUtils.java +++ b/vespajlib/src/main/java/com/yahoo/io/IOUtils.java @@ -1,26 +1,24 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.io; import java.io.*; import java.nio.channels.FileChannel; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.NoSuchFileException; import java.util.List; import java.nio.charset.Charset; import java.nio.ByteBuffer; - /** - * <p>Some static io convenience methods.</p> + * Some static I/O convenience methods. * - * @author bratseth - * @author Bjorn Borud + * @author bratseth + * @author Bjorn Borud */ public abstract class IOUtils { - static private final Charset utf8Charset = Charset.forName("utf-8"); - /** Closes a writer, or does nothing if the writer is null */ public static void closeWriter(Writer writer) { if (writer == null) return; @@ -329,7 +327,7 @@ public abstract class IOUtils { * Encodes string as UTF-8 into ByteBuffer */ public static ByteBuffer utf8ByteBuffer(String s) { - return utf8Charset.encode(s); + return StandardCharsets.UTF_8.encode(s); } /** @@ -341,7 +339,7 @@ public abstract class IOUtils { public static String readFile(File file) throws IOException { try { if (file == null) return null; - return new String(Files.readAllBytes(file.toPath()), "utf-8"); + return Files.readString(file.toPath()); } catch (NoSuchFileException e) { throw new NoSuchFileException("Could not find file '" + file.getAbsolutePath() + "'"); diff --git a/vespajlib/src/main/java/com/yahoo/io/ReadLine.java b/vespajlib/src/main/java/com/yahoo/io/ReadLine.java index 6e7f9f5e50e..f8a820a7421 100644 --- a/vespajlib/src/main/java/com/yahoo/io/ReadLine.java +++ b/vespajlib/src/main/java/com/yahoo/io/ReadLine.java @@ -1,10 +1,9 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.io; import java.nio.Buffer; -import java.nio.charset.Charset; import java.nio.ByteBuffer; - +import java.nio.charset.StandardCharsets; /** * Conventient utility for reading lines from ByteBuffers. Please @@ -12,11 +11,10 @@ import java.nio.ByteBuffer; * ByteBuffer abstraction is somewhat clumsy and thus usage of this * code requires that you understand the semantics clearly. * - * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a> + * @author Bjorn Borud * */ public class ReadLine { - static private Charset charset = Charset.forName("latin1"); /** * Extract next line from a byte buffer. Looks for EOL characters @@ -49,7 +47,7 @@ public class ReadLine { // The downcast to Buffer is done to avoid "redundant cast" warning on Java 9. // TODO: when Java 8 is gone, remove the casts and above comments. // extract string between start and i. - String line = charset.decode((ByteBuffer) ((Buffer)buffer.slice()).limit(i - start)).toString(); + String line = StandardCharsets.ISO_8859_1.decode((ByteBuffer) ((Buffer)buffer.slice()).limit(i - start)).toString(); // skip remaining for (; (i < buffer.limit()) && isEolChar(buffer.get(i)); i++) { @@ -80,4 +78,5 @@ public class ReadLine { static boolean isEolChar(byte b) { return ((10 == b) || (13 == b)); } + } diff --git a/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java b/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java index 370d079b3ec..74458be4584 100644 --- a/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java +++ b/vespajlib/src/main/java/com/yahoo/text/StringUtilities.java @@ -1,9 +1,9 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.text; import com.google.common.collect.ImmutableSet; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; import java.io.ByteArrayOutputStream; @@ -19,8 +19,6 @@ import java.util.Set; // TODO: Text utilities should which are still needed should move to Text. This should be deprecated. public class StringUtilities { - private static Charset UTF8 = Charset.forName("utf8"); - private static byte toHex(int val) { return (byte) (val < 10 ? '0' + val : 'a' + (val - 10)); } private static class ReplacementCharacters { @@ -65,7 +63,7 @@ public class StringUtilities { * @return The escaped string */ public static String escape(String source, char delimiter) { - byte bytes[] = source.getBytes(UTF8); + byte bytes[] = source.getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream result = new ByteArrayOutputStream(); for (byte b : bytes) { int val = b; @@ -86,11 +84,11 @@ public class StringUtilities { result.write(replacementCharacters.replacement2[val]); } } - return new String(result.toByteArray(), UTF8); + return new String(result.toByteArray(), StandardCharsets.UTF_8); } public static String unescape(String source) { - byte bytes[] = source.getBytes(UTF8); + byte bytes[] = source.getBytes(StandardCharsets.UTF_8); ByteArrayOutputStream result = new ByteArrayOutputStream(); for (int i=0; i<bytes.length; ++i) { if (bytes[i] != '\\') { @@ -120,7 +118,7 @@ public class StringUtilities { result.write((byte) Integer.parseInt(hexdigits, 16)); i += 3; } - return new String(result.toByteArray(), UTF8); + return new String(result.toByteArray(), StandardCharsets.UTF_8); } /** |