@Override public Iterable<String> valueMulti() { /* We could support this. */ //noinspection unchecked return die(Iterable.class, "NOT SUPPORTED"); }
private static byte[] readResponseBodyAsBytes(HttpURLConnection http) { try { return IO.input(http.getInputStream()); } catch (IOException e) { return Exceptions.handle(byte[].class, e); } }
public static Response jsonRestCall( final String url ) { return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() { @Override public Response tryIt() throws Exception { URLConnection connection; connection = doGet(url, null, APPLICATION_JSON, null); return extractResponseObject(connection); } }); }
public Pair(Pair<K, V> impl) { requireNonNull( impl ); requireNonNull( impl.k ); this.k = impl.k; this.v = impl.v; }
public static Map asMap(Exception ex) { StackTraceElement[] stackTrace = getFilteredStackTrace(ex.getStackTrace()); List stackTraceList = Lists.list(stackTrace); List fullStackTrace = Lists.list(ex.getStackTrace()); return map( "message", ex.getMessage(), "causeMessage", ex.getCause()!=null ? ex.getCause().getMessage() : "none", "stackTrace", stackTraceList, "fullStackTrace", fullStackTrace ); }
/** * @param array array * @return array */ public static int[] array( final int... array ) { Exceptions.requireNonNull( array ); return array; }
@SuppressWarnings("NullableProblems") @Override public Collection<String> values() { //noinspection unchecked return die(Collection.class, "Not supported"); }
public static void write( Path file, byte[] contents ) { try { Files.write( file, contents ); } catch ( Exception ex ) { Exceptions.handle( ex ); } }
public static Response postBodyTextWithContentTypeReturnResponse(final String url, final String contentType, final String body) { return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() { @Override public Response tryIt() throws Exception { URLConnection connection; connection = doPost(url, null, contentType, null, body); return extractResponseObject(connection); } }); }
/** * @param array array * @return array */ public static double[] array( final double... array ) { Exceptions.requireNonNull( array ); return array; }
@Override public Map<? extends String, ? extends Collection<String>> baseMap() { //noinspection unchecked return die(Map.class, "NOT SUPPORTED"); }
public static void createDirectories(Path path) { try { Files.createDirectories(path); } catch (IOException e) { Exceptions.handle(e); } }
public static Response putBodyTextWithContentTypeReturnResponse(final String url, final String contentType, final String body) { return Exceptions.tryIt(Response.class, new Exceptions.TrialWithReturn<Response>() { @Override public Response tryIt() throws Exception { URLConnection connection; connection = doPut(url, null, contentType, null, body); return extractResponseObject(connection); } }); }
public static double[] shrink( double[] array, int size ) { Exceptions.requireNonNull( array ); double[] newArray = new double[ array.length - size ]; System.arraycopy( array, 0, newArray, 0, array.length - size ); return newArray; }
private static String readErrorResponseBody(HttpURLConnection http, int status, String charset) { InputStream errorStream = http.getErrorStream(); if (errorStream != null) { String error = charset == null ? IO.read(errorStream) : IO.read(errorStream, charset); return Exceptions.die(String.class, "STATUS CODE =" + status + "\n\n" + error); } else { return Exceptions.die(String.class, "STATUS CODE =" + status); } }
public static char[] readCharBuffer( Reader reader, int size ) { char[] buffer = new char[ size ]; try ( Reader r = reader ) { reader.read( buffer ); } catch ( Exception ex ) { return Exceptions.handle( char[].class, ex ); } return buffer; }
public static String postForm(final String url, final Map<String, ?> headers, final Map<String, Object> formData ) { return Exceptions.tryIt(String.class, new Exceptions.TrialWithReturn<String>() { @Override public String tryIt() throws Exception { URLConnection connection; connection = doPostFormData(url, headers, formData); return extractResponseString(connection); } }); }
public static float[] grow( float[] array, final int size ) { Exceptions.requireNonNull(array); float[] newArray = new float[ array.length + size ]; System.arraycopy( array, 0, newArray, 0, array.length ); return newArray; }
private Message<Object> parseMessageFromChars(final String returnAddress, char[] chars) { final char messageType = chars[PROTOCOL_MESSAGE_TYPE_POSITION]; if (messageType == PROTOCOL_MESSAGE_TYPE_METHOD) { return handleFastBodySubmissionVersion1Chars(returnAddress, chars); } else if (messageType == PROTOCOL_MESSAGE_TYPE_RESPONSE) { return parseResponseFromChars(chars, returnAddress); } else { die("Unsupported method call", new String(chars)); return null; } }
@Override public Object invokeStatic(Object... args) { try { return method.invoke(null, args); } catch ( Throwable ex ) { return Exceptions.handle(Object.class, ex, "unable to invoke method", method, " with arguments", args); } }