public static void main(String... args) { if ( args.length == 0 ) args = new String[] {"-"} ; try { for ( String fn : args ) { JsonValue json =null ; try { json = JSON.readAny(fn) ; } catch (JsonParseException ex) { String name = fn.equals("-") ? "<stdin>" : fn ; System.err.println(name+": "+JsonParseException.formatMessage(ex.getMessage(), ex.getLine(), ex.getColumn())) ; continue ; } JSON.write(IndentedWriter.stdout, json) ; IndentedWriter.stdout.ensureStartOfLine() ; } } finally { IndentedWriter.stdout.flush() ; } }
public static void main(String... args) { if ( args.length == 0 ) args = new String[] {"-"} ; try { for ( String fn : args ) { JsonValue json =null ; try { json = JSON.readAny(fn) ; } catch (JsonParseException ex) { String name = fn.equals("-") ? "<stdin>" : fn ; System.err.println(name+": "+JsonParseException.formatMessage(ex.getMessage(), ex.getLine(), ex.getColumn())) ; continue ; } JSON.write(IndentedWriter.stdout, json) ; IndentedWriter.stdout.ensureStartOfLine() ; } } finally { IndentedWriter.stdout.flush() ; } }
public static void main(String... args) { if ( args.length == 0 ) args = new String[] {"-"} ; try { for ( String fn : args ) { JsonValue json =null ; try { json = JSON.readAny(fn) ; } catch (JsonParseException ex) { String name = fn.equals("-") ? "<stdin>" : fn ; System.err.println(name+": "+JsonParseException.formatMessage(ex.getMessage(), ex.getLine(), ex.getColumn())) ; continue ; } JSON.write(IndentedWriter.stdout, json) ; IndentedWriter.stdout.ensureStartOfLine() ; } } finally { IndentedWriter.stdout.flush() ; } }
/** * 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; } }