private static String readErrorResponseBodyDoNotDie(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 error; } else { return ""; } }
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 String getWebPageContents() { if (webPageContents == null || webPageContents.isEmpty()) { final String htmlPageLocationInitial = getHtmlPageLocation(); final String pageLocation; pageLocation = htmlPageLocationInitial.startsWith("/") ? htmlPageLocationInitial.substring(1, htmlPageLocationInitial.length()) : htmlPageLocationInitial; webPageContents = IO.read( Thread.currentThread() .getContextClassLoader() .getResourceAsStream(pageLocation) ); } return webPageContents; }
/** * Reads the readConfig file, which can be a classpath or file system resource. * * @param serviceName the name of the service to load * @return service config */ public static MicroserviceConfig readConfig(final String serviceName) { final Logger logger = LoggerFactory.getLogger(MicroserviceConfig.class); if (new File(resourceLocation).exists()) { final String json = IO.read(resourceLocation); return JsonFactory.fromJson(json, MicroserviceConfig.class); } else if (resourceLocationEnv != null && new File(resourceLocationEnv).exists()) { final String json = IO.read(resourceLocationEnv); return JsonFactory.fromJson(json, MicroserviceConfig.class); } else { logger.info("Reading config from classpath as it is not found on file system"); final String qbitEnv = System.getenv("QBIT_ENV"); final String resourceLocationOnClasspath = qbitEnv != null && !qbitEnv.isEmpty() ? serviceName + "_" + qbitEnv + ".json" : serviceName + ".json"; final String json = IO.read(Thread.currentThread().getContextClassLoader() .getResourceAsStream(resourceLocationOnClasspath)); return JsonFactory.fromJson(json, MicroserviceConfig.class); } }
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 String read( InputStream inputStream, Charset charset ) { try ( Reader reader = new InputStreamReader( inputStream, charset ) ) { return read( reader ); } catch ( Exception ex ) { return Exceptions.handle( String.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 String readCharBuffer( InputStream inputStream, Charset charset ) { try ( Reader reader = new InputStreamReader( inputStream, charset ) ) { return read( reader ); } catch ( Exception ex ) { return Exceptions.handle( String.class, ex ); } }
public static CharBuf read( InputStream inputStream, CharBuf charBuf ) { try ( Reader reader = new InputStreamReader( inputStream ) ) { return read( reader, charBuf ); } catch ( Exception ex ) { return Exceptions.handle( CharBuf.class, ex ); } }
public static CharBuf read( InputStream inputStream, CharBuf charBuf, Charset charset ) { try ( Reader reader = new InputStreamReader( inputStream, charset ) ) { return read( reader, charBuf ); } catch ( Exception ex ) { return Exceptions.handle( CharBuf.class, ex ); } }
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 ); } }
@Override public <T> T parse( Class<T> type, InputStream input ) { if (copyBuf==null) { copyBuf = new char[bufSize]; } fileInputBuf = IO.read( input, fileInputBuf, charset, bufSize, copyBuf ); return parse( type, fileInputBuf.readForRecycle() ); }
@Override public <T> T parse( Class<T> type, Reader reader ) { if (copyBuf==null) { copyBuf = new char[bufSize]; } fileInputBuf = IO.read( reader, fileInputBuf, bufSize, copyBuf ); return parse( type, fileInputBuf.readForRecycle() ); }
@Override public <T> T parse( Class<T> type, InputStream input, Charset charset ) { fileInputBuf = IO.read( input, fileInputBuf, charset, bufSize, copyBuf ); return parse( type, fileInputBuf.readForRecycle() ); }
@Override public final <T> T parse( Class<T> type, InputStream input, Charset charset ) { if (copyBuf==null) { copyBuf = new char[bufSize]; } charBuf = IO.read( input, charBuf, charset, bufSize, copyBuf ); return parse( type, charBuf.readForRecycle() ); }
@Override public Object parse( Reader reader ) { if (copyBuf==null) { copyBuf = new char[bufSize]; } fileInputBuf = IO.read ( reader, fileInputBuf, bufSize, copyBuf ); return parse( fileInputBuf.readForRecycle() ); }
@Override public final <T> T parse( Class<T> type, Reader reader ) { if (copyBuf==null) { copyBuf = new char[bufSize]; } charBuf = IO.read( reader, charBuf, bufSize, copyBuf ); return parse( type, charBuf.readForRecycle() ); }
@Override public final <T> T parse( Class<T> type, InputStream input ) { if (copyBuf==null) { copyBuf = new char[bufSize]; } charBuf = IO.read( input, charBuf, this.charset, bufSize, copyBuf ); return parse( type, charBuf.readForRecycle() ); }