aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2023-01-30 09:20:25 +0100
committerjonmv <venstad@gmail.com>2023-01-30 09:20:25 +0100
commita3829e8ed303e6a672a9bfd93317f992cb32b918 (patch)
treee64e1c19e7d3ee4474749beb791cff858d83c1c7 /vespajlib
parente4b6486d0a3768a722ba43d0d64166d4b2393b9c (diff)
Revert "Merge pull request #25776 from vespa-engine/jonmv/revert-private-endpoints"
This reverts commit 350b36dd88baef7548c0066b01ea1e328eb78f3f, reversing changes made to 8a006bc9ca202713ec54c7961a9256790c87d10d.
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/abi-spec.json14
-rw-r--r--vespajlib/src/main/java/ai/vespa/http/HttpURL.java2
-rw-r--r--vespajlib/src/main/java/com/yahoo/text/Utf8.java23
-rw-r--r--vespajlib/src/main/java/com/yahoo/yolean/Exceptions.java9
4 files changed, 36 insertions, 12 deletions
diff --git a/vespajlib/abi-spec.json b/vespajlib/abi-spec.json
index 418f3ed5911..c3b87278345 100644
--- a/vespajlib/abi-spec.json
+++ b/vespajlib/abi-spec.json
@@ -3646,6 +3646,19 @@
],
"fields" : [ ]
},
+ "com.yahoo.yolean.Exceptions$FunctionThrowingIOException" : {
+ "superClass" : "java.lang.Object",
+ "interfaces" : [ ],
+ "attributes" : [
+ "public",
+ "interface",
+ "abstract"
+ ],
+ "methods" : [
+ "public abstract java.lang.Object map(java.lang.Object)"
+ ],
+ "fields" : [ ]
+ },
"com.yahoo.yolean.Exceptions$RunnableThrowingIOException" : {
"superClass" : "java.lang.Object",
"interfaces" : [ ],
@@ -3700,6 +3713,7 @@
"public static void uncheckInterruptedAndRestoreFlag(com.yahoo.yolean.Exceptions$RunnableThrowingInterruptedException)",
"public static varargs void uncheck(com.yahoo.yolean.Exceptions$RunnableThrowingIOException, java.lang.String, java.lang.String[])",
"public static void uncheckAndIgnore(com.yahoo.yolean.Exceptions$RunnableThrowingIOException, java.lang.Class)",
+ "public static java.util.function.Function uncheck(com.yahoo.yolean.Exceptions$FunctionThrowingIOException)",
"public static java.lang.Object uncheck(com.yahoo.yolean.Exceptions$SupplierThrowingIOException)",
"public static varargs java.lang.Object uncheck(com.yahoo.yolean.Exceptions$SupplierThrowingIOException, java.lang.String, java.lang.String[])",
"public static java.lang.Object uncheckAndIgnore(com.yahoo.yolean.Exceptions$SupplierThrowingIOException, java.lang.Class)",
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<String> 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
@@ -129,6 +130,14 @@ public class Exceptions {
@FunctionalInterface public interface RunnableThrowingInterruptedException { void run() throws InterruptedException; }
/**
+ * Wraps any IOException thrown from a function in an UncheckedIOException.
+ */
+ public static <T, R> Function<T, R> uncheck(FunctionThrowingIOException<T, R> function) {
+ return t -> uncheck(() -> function.map(t));
+ }
+ @FunctionalInterface public interface FunctionThrowingIOException<T, R> { R map(T t) throws IOException; }
+
+ /**
* Wraps any IOException thrown from a supplier in an UncheckedIOException.
*/
public static <T> T uncheck(SupplierThrowingIOException<T> supplier) {