import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.whispersystems.signalservice.api.NetworkResult;
+import org.whispersystems.signalservice.api.NetworkResultUtil;
import org.whispersystems.signalservice.api.push.ServiceId;
import org.whispersystems.signalservice.api.util.StreamDetails;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
}
public static <T> T handleResponseException(final NetworkResult<T> response) throws IOException {
- final var throwableOptional = response.getCause();
- if (throwableOptional != null) {
- if (throwableOptional instanceof IOException ioException) {
- throw ioException;
- } else {
- throw new IOException(throwableOptional);
- }
- }
- return response.successOrThrow();
+ return NetworkResultUtil.toBasicLegacy(response);
}
public static ByteString firstNonEmpty(ByteString... strings) {
public static String nullIfEmpty(String string) {
return string == null || string.isEmpty() ? null : string;
}
+
+ public static Proxy getHttpsProxy() {
+ final URI uri;
+ try {
+ uri = new URI("https://example");
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ final var proxies = ProxySelector.getDefault().select(uri);
+ if (proxies.isEmpty()) {
+ return Proxy.NO_PROXY;
+ } else {
+ return proxies.getFirst();
+ }
+ }
}