aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/main/java/com/yahoo/io
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2020-10-05 15:04:38 +0200
committerGitHub <noreply@github.com>2020-10-05 15:04:38 +0200
commit3f96fe4e1a96b3b21c913a392da87e5ec669b286 (patch)
treebfcfbad0db1a54372fec7e483749706bdc55f6f6 /vespajlib/src/main/java/com/yahoo/io
parent233b521555e240458e38f555430459c3e30f0d64 (diff)
Revert "Remove unused Utf8 methods"
Diffstat (limited to 'vespajlib/src/main/java/com/yahoo/io')
-rw-r--r--vespajlib/src/main/java/com/yahoo/io/IOUtils.java16
-rw-r--r--vespajlib/src/main/java/com/yahoo/io/ReadLine.java11
2 files changed, 15 insertions, 12 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/io/IOUtils.java b/vespajlib/src/main/java/com/yahoo/io/IOUtils.java
index 266b7857363..f2de0ace476 100644
--- a/vespajlib/src/main/java/com/yahoo/io/IOUtils.java
+++ b/vespajlib/src/main/java/com/yahoo/io/IOUtils.java
@@ -1,24 +1,26 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright 2017 Yahoo Holdings. 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;
+
/**
- * Some static I/O convenience methods.
+ * <p>Some static io convenience methods.</p>
*
- * @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;
@@ -327,7 +329,7 @@ public abstract class IOUtils {
* Encodes string as UTF-8 into ByteBuffer
*/
public static ByteBuffer utf8ByteBuffer(String s) {
- return StandardCharsets.UTF_8.encode(s);
+ return utf8Charset.encode(s);
}
/**
@@ -339,7 +341,7 @@ public abstract class IOUtils {
public static String readFile(File file) throws IOException {
try {
if (file == null) return null;
- return Files.readString(file.toPath());
+ return new String(Files.readAllBytes(file.toPath()), "utf-8");
}
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 f8a820a7421..6e7f9f5e50e 100644
--- a/vespajlib/src/main/java/com/yahoo/io/ReadLine.java
+++ b/vespajlib/src/main/java/com/yahoo/io/ReadLine.java
@@ -1,9 +1,10 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright 2017 Yahoo Holdings. 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
@@ -11,10 +12,11 @@ import java.nio.charset.StandardCharsets;
* ByteBuffer abstraction is somewhat clumsy and thus usage of this
* code requires that you understand the semantics clearly.
*
- * @author Bjorn Borud
+ * @author <a href="mailto:borud@yahoo-inc.com">Bjorn Borud</a>
*
*/
public class ReadLine {
+ static private Charset charset = Charset.forName("latin1");
/**
* Extract next line from a byte buffer. Looks for EOL characters
@@ -47,7 +49,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 = StandardCharsets.ISO_8859_1.decode((ByteBuffer) ((Buffer)buffer.slice()).limit(i - start)).toString();
+ String line = charset.decode((ByteBuffer) ((Buffer)buffer.slice()).limit(i - start)).toString();
// skip remaining
for (; (i < buffer.limit()) && isEolChar(buffer.get(i)); i++) {
@@ -78,5 +80,4 @@ public class ReadLine {
static boolean isEolChar(byte b) {
return ((10 == b) || (13 == b));
}
-
}