/** Open an input stream to a file. * If the filename is null or "-", return System.in * If the filename ends in .gz, wrap in GZIPInputStream */ static public InputStream openFile(String filename) { try { return openFileEx(filename) ; } catch (IOException ex) { IO.exception(ex); return null ; } }
/** Open an input stream to a file. * If the filename is null or "-", return System.in * If the filename ends in .gz, wrap in GZIPInputStream */ static public InputStream openFile(String filename) { try { return openFileEx(filename) ; } catch (IOException ex) { IO.exception(ex); return null ; } }
/** * Open an input stream to a file and buffer it. If the filename is null or "-", * return System.in If the filename ends in .gz, wrap in GZIPInputStream. * If using this {@code InputStream} with an {@code InputStreamReader} * (e.g. to get UTF-8), there is no need to buffer the {@code InputStream}. * Instead, buffer the {@code Reader}. */ static public InputStream openFileBuffered(String filename) { try { InputStream in = openFileEx(filename) ; return new BufferedInputStream(in, BUFFER_SIZE) ; } catch (IOException ex) { IO.exception(ex); return null ; } }
/** Open an input stream to a file. * If the filename is null or "-", return System.in * If the filename ends in .gz, wrap in GZIPInputStream */ static public InputStream openFile(String filename) { try { return openFileEx(filename) ; } catch (Exception ex) { throw new AtlasException(ex) ; } }
/** * Open an input stream to a file and buffer it. If the filename is null or "-", * return System.in If the filename ends in .gz, wrap in GZIPInputStream. * If using this {@code InputStream} with an {@code InputStreamReader} * (e.g. to get UTF-8), there is no need to buffer the {@code InputStream}. * Instead, buffer the {@code Reader}. */ static public InputStream openFileBuffered(String filename) { try { InputStream in = openFileEx(filename) ; return new BufferedInputStream(in, BUFFER_SIZE) ; } catch (IOException ex) { IO.exception(ex); return null ; } }
/** Read a JSON object from a file */ public static JsonObject read(String filename) { try { InputStream in = IO.openFileEx(filename) ; try { return JSON.parse(in) ; } finally { in.close() ; } } catch (FileNotFoundException ex) { throw new RuntimeException("File not found: "+filename, ex) ; } catch (IOException ex) { IO.exception("IOException: "+filename, ex); return null ; } }
/** Read any JSON value, not just an object, from a file */ public static JsonValue readAny(String filename) { try { try (InputStream in = IO.openFileEx(filename)) { return JSON.parseAny(in) ; } } catch (FileNotFoundException ex) { throw new RuntimeException("File not found: " + filename, ex) ; } catch (IOException ex) { IO.exception("IOException: " + filename, ex) ; return null ; } }
/** Read any JSON value, not just an object, from a file */ public static JsonValue readAny(String filename) { try { InputStream in = IO.openFileEx(filename) ; try { return JSON.parseAny(in) ; } finally { in.close() ; } } catch (FileNotFoundException ex) { throw new RuntimeException("File not found: "+filename, ex) ; } catch (IOException ex) { IO.exception("IOException: "+filename, ex); return null ; } }
InputStream in = IO.openFileEx(fn) ;
InputStream in = IO.openFileEx(fn) ;
/** Read a JSON object from a file */ public static JsonObject read(String filename) { try (InputStream in = IO.openFileEx(filename)) { return JSON.parse(in) ; } catch (FileNotFoundException ex) { IO.exception("File not found: " + filename, ex) ; return null ; } catch (IOException ex) { IO.exception("IOException: " + filename, ex) ; return null ; } }
/** * Read from a file if possible. * Return null if the file is not found or has a syntax error. */ public static StoreParams read(String filename) { try { InputStream in = IO.openFileEx(filename); if ( in == null ) return null; JsonObject obj = JSON.parse(in) ; return StoreParamsCodec.decode(obj) ; } catch (FileNotFoundException ex) { return null; } catch (JsonParseException ex) { FmtLog.warn(StoreParamsCodec.class, "Ignoring store params : Syntax error in '%s': [line:%d, col:%d] %s", filename, ex.getLine(), ex.getColumn(), ex.getMessage()); return null ; } catch (IOException e) { IO.exception(e); return null; } }
/** * Read from a file if possible. * Return null if the file is not found or has a syntax error. */ public static StoreParams read(String filename) { try { InputStream in = IO.openFileEx(filename); if ( in == null ) return null; JsonObject obj = JSON.parse(in) ; return StoreParamsCodec.decode(obj) ; } catch (FileNotFoundException ex) { return null; } catch (JsonParseException ex) { FmtLog.warn(StoreParamsCodec.class, "Ignoring store params : Syntax error in '%s': [line:%d, col:%d] %s", filename, ex.getLine(), ex.getColumn(), ex.getMessage()); return null ; } catch (IOException e) { IO.exception(e); return null; } }