/** * Reads an input stream, containing lines of ascii in fixed width format. * Breaks each line into a set of Fields (space or comma delimited) which may be String, integer or double. * * @param ios the input stream * @param format describe format of each line. * @param maxLines maximum number of lines to parse, set to < 0 to read all * @return List of TableParser.Record * @throws IOException on read error * @throws NumberFormatException on parse number error */ static public List<Record> readTable(InputStream ios, String format, int maxLines) throws IOException, NumberFormatException { TableParser parser = new TableParser(format); List<Record> result = parser.readAllRecords(ios, maxLines); ios.close(); return result; }
/** * Reads an input stream, containing lines of ascii in fixed width format. * Breaks each line into a set of Fields (space or comma delimited) which may be String, integer or double. * * @param ios the input stream, will be closed * @param format describe format of each line. * @param maxLines maximum number of lines to parse, set to < 0 to read all * @return List of TableParser.Record * @throws IOException on read error * @throws NumberFormatException on parse number error */ static public List<Record> readTable(InputStream ios, String format, int maxLines) throws IOException, NumberFormatException { List<Record> result; try { TableParser parser = new TableParser(format); result = parser.readAllRecords(ios, maxLines); } finally { ios.close(); } return result; }
/** * Reads an input stream, containing lines of ascii in fixed width format. * Breaks each line into a set of Fields (space or comma delimited) which may be String, integer or double. * * @param ios the input stream, will be closed * @param format describe format of each line. * @param maxLines maximum number of lines to parse, set to < 0 to read all * @return List of TableParser.Record * @throws IOException on read error * @throws NumberFormatException on parse number error */ static public List<Record> readTable(InputStream ios, String format, int maxLines) throws IOException, NumberFormatException { List<Record> result; try { TableParser parser = new TableParser(format); result = parser.readAllRecords(ios, maxLines); } finally { ios.close(); } return result; }
private Map<Integer, Grib2Parameter> initLocalTable(String resourcePath, Formatter f) { Map<Integer, Grib2Parameter> result = new HashMap<>(100); try (InputStream is = GribResourceReader.getInputStream(resourcePath)) { if (is == null) throw new IllegalStateException("Cant find " + resourcePath); if (f != null) f.format("%s, %-20s, %-20s, %-20s%n", "id", "name", "units", "gname"); TableParser parser = new TableParser("3i,7i,11i,15i,49,69,74,"); parser.setComment("!"); List<TableParser.Record> recs = parser.readAllRecords(is, 50000); for (TableParser.Record record : recs) { int disc = (Integer) record.get(0); int cat = (Integer) record.get(1); int id = (Integer) record.get(2); int template = (Integer) record.get(3); // LOOK - 19, 29, 39 ??? String name = ((String) record.get(4)).trim(); String units = ((String) record.get(5)).trim(); String gname = ((String) record.get(6)).trim(); String ids = disc+"-"+cat+"-"+id; if (f != null) f.format("%s == %-20s, %-20s, %-20s%n", ids, name, units, gname); Grib2Parameter gp = new Grib2Parameter(disc, cat, id, gname, units, null, name); result.put(Grib2Customizer.makeParamId(disc, cat, id), gp); } } catch (IOException ioe) { throw new RuntimeException(ioe); } return result; }