private static byte[] readResponseBodyAsBytes(HttpURLConnection http) { try { return IO.input(http.getInputStream()); } catch (IOException e) { return Exceptions.handle(byte[].class, e); } }
public static Class<?> toClass(String str) { try { return Class.forName(str); } catch (ClassNotFoundException ex) { return (Class<?>) Exceptions.handle(Object.class, ex); } }
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 void move(Path source, Path target) { try { Files.move(source, target); } catch (IOException e) { Exceptions.handle(e); } }
@Override public void setStaticValue(Object newValue) { try { field.set(null, newValue); } catch (IllegalAccessException e) { Exceptions.handle(e); } }
public static void write( OutputStream out, String content, Charset charset ) { try ( OutputStream o = out ) { o.write( content.getBytes( charset ) ); } catch ( Exception ex ) { Exceptions.handle( ex ); } }
public static void writeNoClose( OutputStream out, String content ) { try { out.write( content.getBytes( DEFAULT_CHARSET ) ); } catch ( Exception ex ) { Exceptions.handle( ex ); } }
public static void _idx( final byte[] output, int ouputStartIndex, byte[] input, int inputOffset, int length ) { try { System.arraycopy( input, inputOffset, output, ouputStartIndex, length ); } catch ( Exception ex ) { Exceptions.handle( String.format( "array size %d, startIndex %d, input length %d", output.length, ouputStartIndex, input.length ), ex ); } }
@Override public void serialize(CharBuf builder, Object obj) { level = 0; try { serializeObject( obj, builder ); } catch ( Exception ex ) { Exceptions.handle("unable to serializeObject", ex); } }
public static void getFields( Class<? extends Object> theClass, List<Field> list ) { try { List<Field> more = getFields( theClass ); list.addAll( more ); }catch (Exception ex) { Exceptions.handle(ex, "getFields", theClass, list); } }
public static CharBuf read( InputStream inputStream, CharBuf charBuf, Charset charset, int bufSize, char[] copyBuf ) { try ( Reader reader = new InputStreamReader( inputStream, charset ) ) { return read( reader, charBuf, bufSize, copyBuf ); } catch ( Exception ex ) { return Exceptions.handle( CharBuf.class, ex ); } }
public static String read( File file ) { try ( Reader reader = new FileReader( file ) ) { return read( reader ); } catch ( Exception ex ) { return Exceptions.handle( String.class, ex ); } }
public static void eachLine( Reader reader, EachLine eachLine ) { try ( BufferedReader bufferedReader = new BufferedReader( reader ) ) { eachLine( bufferedReader, eachLine ); } catch ( Exception ex ) { Exceptions.handle( List.class, ex ); } }
public static List<String> readLines( InputStream is ) { try ( Reader reader = new InputStreamReader( is, DEFAULT_CHARSET ) ) { return readLines( reader ); } catch ( Exception ex ) { return Exceptions.handle( List.class, ex ); } }
public static void eachLine( BufferedReader reader, EachLine eachLine ) { try ( BufferedReader bufferedReader = reader ) { String line; int lineNumber = 0; while ( ( line = bufferedReader.readLine() ) != null && eachLine.line( line, lineNumber++ ) ) { // // no op } } catch ( Exception ex ) { Exceptions.handle( ex ); } }
public static void createDirectories(String path) { try { Files.createDirectories(path(path)); } catch (IOException e) { Exceptions.handle(e); } }
@Override public void toJson( Object value, Appendable appendable ) { try { appendable.append ( this.writeValueAsString ( value ) ); } catch ( IOException e ) { Exceptions.handle ( e ); } }
public static void writeChild( Path parentDir, String childFileName, String childContents ) { try { final Path newFilePath = path( parentDir.toString(), childFileName ); write( newFilePath, childContents ); } catch ( Exception ex ) { Exceptions.handle( ex ); } }
public final CharBuf serialize( Object obj ) { builder.readForRecycle (); try { serializeObject( obj, builder ); } catch ( Exception ex ) { return Exceptions.handle(CharBuf.class, "unable to serializeObject", ex); } return builder; }
public final boolean getBoolean( Object obj ) { try { return ( Boolean ) this.getObject ( obj ); } catch ( Exception e ) { return Exceptions.handle( boolean.class, Str.sputs("unable to call getObject for property", this.name), e ); } }