From a3829e8ed303e6a672a9bfd93317f992cb32b918 Mon Sep 17 00:00:00 2001 From: jonmv Date: Mon, 30 Jan 2023 09:20:25 +0100 Subject: Revert "Merge pull request #25776 from vespa-engine/jonmv/revert-private-endpoints" This reverts commit 350b36dd88baef7548c0066b01ea1e328eb78f3f, reversing changes made to 8a006bc9ca202713ec54c7961a9256790c87d10d. --- vespajlib/src/main/java/ai/vespa/http/HttpURL.java | 2 +- vespajlib/src/main/java/com/yahoo/text/Utf8.java | 23 +++++++++++----------- .../src/main/java/com/yahoo/yolean/Exceptions.java | 9 +++++++++ 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'vespajlib/src/main') diff --git a/vespajlib/src/main/java/ai/vespa/http/HttpURL.java b/vespajlib/src/main/java/ai/vespa/http/HttpURL.java index 9641ea2a8fd..ba1a8e08740 100644 --- a/vespajlib/src/main/java/ai/vespa/http/HttpURL.java +++ b/vespajlib/src/main/java/ai/vespa/http/HttpURL.java @@ -239,7 +239,7 @@ public class HttpURL { return parse(raw, HttpURL::requirePathSegment); } - /** Parses the given raw, normalized path string; this ignores whether the path is absolute or relative.) */ + /** Parses the given raw, normalized path string; this ignores whether the path is absolute or relative. */ public static Path parse(String raw, Consumer validator) { Path path = new Path(null, 0, raw.endsWith("/"), segmentValidator(validator)); if (raw.startsWith("/")) raw = raw.substring(1); diff --git a/vespajlib/src/main/java/com/yahoo/text/Utf8.java b/vespajlib/src/main/java/com/yahoo/text/Utf8.java index 2a42cb5cdee..3a7ecaa727a 100644 --- a/vespajlib/src/main/java/com/yahoo/text/Utf8.java +++ b/vespajlib/src/main/java/com/yahoo/text/Utf8.java @@ -10,7 +10,8 @@ import java.nio.ReadOnlyBufferException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; import java.nio.charset.CodingErrorAction; -import java.nio.charset.StandardCharsets; + +import static java.nio.charset.StandardCharsets.UTF_8; /** * Utility class with functions for handling UTF-8 @@ -23,16 +24,16 @@ public final class Utf8 { private static final byte [] TRUE = {(byte) 't', (byte) 'r', (byte) 'u', (byte) 'e'}; private static final byte [] FALSE = {(byte) 'f', (byte) 'a', (byte) 'l', (byte) 's', (byte) 'e'}; - private static final byte[] LONG_MIN_VALUE_BYTES = String.valueOf(Long.MIN_VALUE).getBytes(StandardCharsets.UTF_8); + private static final byte[] LONG_MIN_VALUE_BYTES = String.valueOf(Long.MIN_VALUE).getBytes(UTF_8); /** Returns the Charset instance for UTF-8 */ public static Charset getCharset() { - return StandardCharsets.UTF_8; + return UTF_8; } /** To be used instead of String.String(byte[] bytes) */ public static String toStringStd(byte[] data) { - return new String(data, StandardCharsets.UTF_8); + return new String(data, UTF_8); } /** @@ -60,7 +61,7 @@ public final class Utf8 { * @return a decoded String */ public static String toString(ByteBuffer data) { - CharBuffer c = StandardCharsets.UTF_8.decode(data); + CharBuffer c = UTF_8.decode(data); return c.toString(); } @@ -68,7 +69,7 @@ public final class Utf8 { * Uses String.getBytes directly. */ public static byte[] toBytesStd(String str) { - return str.getBytes(StandardCharsets.UTF_8); + return str.getBytes(UTF_8); } /** @@ -112,7 +113,7 @@ public final class Utf8 { */ public static byte[] toBytes(String string) { // This is just wrapper for String::getBytes. Pre-Java 9 this had a more efficient approach for ASCII-only strings. - return string.getBytes(StandardCharsets.UTF_8); + return string.getBytes(UTF_8); } /** * Decode a UTF-8 string. @@ -122,7 +123,7 @@ public final class Utf8 { */ public static String toString(byte[] utf8) { // This is just wrapper for String::new. Pre-Java 9 this had a more efficient approach for ASCII-onlu strings. - return new String(utf8, StandardCharsets.UTF_8); + return new String(utf8, UTF_8); } /** @@ -138,7 +139,7 @@ public final class Utf8 { */ public static byte[] toBytes(String str, int offset, int length) { CharBuffer c = CharBuffer.wrap(str, offset, offset + length); - ByteBuffer b = StandardCharsets.UTF_8.encode(c); + ByteBuffer b = UTF_8.encode(c); byte[] result = new byte[b.remaining()]; b.get(result); return result; @@ -161,7 +162,7 @@ public final class Utf8 { */ public static int toBytes(String str, int srcOffset, int srcLen, byte[] dst, int dstOffset) { CharBuffer c = CharBuffer.wrap(str, srcOffset, srcOffset + srcLen); - ByteBuffer b = StandardCharsets.UTF_8.encode(c); + ByteBuffer b = UTF_8.encode(c); int encoded = b.remaining(); b.get(dst, dstOffset, encoded); return encoded; @@ -206,7 +207,7 @@ public final class Utf8 { * @see Utf8#toBytes(String, int, int, ByteBuffer, CharsetEncoder) */ public static CharsetEncoder getNewEncoder() { - return StandardCharsets.UTF_8.newEncoder().onMalformedInput(CodingErrorAction.REPLACE) + return UTF_8.newEncoder().onMalformedInput(CodingErrorAction.REPLACE) .onUnmappableCharacter(CodingErrorAction.REPLACE); } diff --git a/vespajlib/src/main/java/com/yahoo/yolean/Exceptions.java b/vespajlib/src/main/java/com/yahoo/yolean/Exceptions.java index 89b4e76368b..4f3f048eb0c 100644 --- a/vespajlib/src/main/java/com/yahoo/yolean/Exceptions.java +++ b/vespajlib/src/main/java/com/yahoo/yolean/Exceptions.java @@ -4,6 +4,7 @@ package com.yahoo.yolean; import java.io.IOException; import java.io.UncheckedIOException; import java.util.Optional; +import java.util.function.Function; /** * Helper methods for handling exceptions @@ -128,6 +129,14 @@ public class Exceptions { @FunctionalInterface public interface RunnableThrowingInterruptedException { void run() throws InterruptedException; } + /** + * Wraps any IOException thrown from a function in an UncheckedIOException. + */ + public static Function uncheck(FunctionThrowingIOException function) { + return t -> uncheck(() -> function.map(t)); + } + @FunctionalInterface public interface FunctionThrowingIOException { R map(T t) throws IOException; } + /** * Wraps any IOException thrown from a supplier in an UncheckedIOException. */ -- cgit v1.2.3