private static void readGridConfig(int rowCount, int numRecords, int[] reducedColumnCount, double[] latitudePoints, int[] reducedFirstBinIndexes) throws IOException { InputStream is = GaussianGridConfig.class.getResourceAsStream(String.format("N%d.txt", rowCount)); reducedFirstBinIndexes[0] = 0; try (CsvReader csvReader = new CsvReader(new InputStreamReader(is), new char[]{'\t'}, true, "#")) { for (int i = 0; i < numRecords; i++) { String[] record = csvReader.readRecord(); reducedColumnCount[i] = Integer.parseInt(record[0]); latitudePoints[i] = Double.parseDouble(record[2]); if (i > 0) { reducedFirstBinIndexes[i] = reducedFirstBinIndexes[i - 1] + reducedColumnCount[i - 1]; } } } }
@SuppressWarnings("unchecked") private static Map<String, ScanLineLayout> readScanLineLayoutMap() throws IOException { final InputStream inputStream = ChrisFile.class.getResourceAsStream("scanLineLayout.csv"); final InputStreamReader inputStreamReader = new InputStreamReader(inputStream); final CsvReader csvReader = new CsvReader(inputStreamReader, new char[]{','}, true, "#"); try { final List<String[]> recordList = csvReader.readStringRecords(); final Map<String, ScanLineLayout> scanLineLayoutMap = new HashMap<String, ScanLineLayout>( recordList.size()); for (final String[] record : recordList) { final int leadingPixelCount = Integer.parseInt(record[1]); final int imagePixelCount = Integer.parseInt(record[2]); final int trailingPixelCount = Integer.parseInt(record[3]); scanLineLayoutMap.put(record[0], new ScanLineLayout(leadingPixelCount, imagePixelCount, trailingPixelCount)); } return scanLineLayoutMap; } finally { try { csvReader.close(); } catch (IOException ignored) { // ignore } } } }
EqualizationLUT(Reader[] bandCoefficientReaders) throws IOException { coefficientsMapList = new ArrayList<>(bandCoefficientReaders.length); for (Reader bandCoefficientReader : bandCoefficientReaders) { final HashMap<Integer, double[]> coefMap = new HashMap<>(); try (CsvReader csvReader = new CsvReader(bandCoefficientReader, new char[]{' '})) { double[] coefs = csvReader.readDoubleRecord(); while (coefs != null) { coefMap.put(csvReader.getLineNumber() - 1, coefs); coefs = csvReader.readDoubleRecord(); } } coefficientsMapList.add(coefMap); } }
private SimpleFeatureType readFeatureType() throws IOException { String[] tokens = reader.readRecord(); if (tokens == null || tokens.length <= 1) { throw new IOException("Missing feature type definition in first line."); } reader.mark(1024 * 1024 * 10); return createFeatureType(tokens); }
/** * Loads the list of supported product types. */ private void loadProductTypes() throws IOException { _productTypes = new HashMap<String, String>(); final CsvReader reader = getCsvReader("products.dd"); for (String[] records = reader.readRecord(); records != null; records = reader.readRecord()) { if (records.length == 2) { _productTypes.put(records[0], records[1]); } else { logger.severe( "Invalid number of records in MODISDB - please check the resources for correctness."); } } reader.close(); }
private VectorDataNodeReader(String sourceName, Product product, Reader reader, FeatureUtils.FeatureCrsProvider crsProvider, PlacemarkDescriptorProvider placemarkDescriptorProvider, boolean convertToVertices, char delimiterChar) throws IOException { this.product = product; this.crsProvider = crsProvider; this.placemarkDescriptorProvider = placemarkDescriptorProvider; this.convertToVertices = convertToVertices; this.sourceName = sourceName; this.reader = new CsvReader(reader, new char[]{delimiterChar}, true, "#"); }
protected static HashMap<String, String> readTwoColumnTable(String resourceName) { final InputStream stream = SeadasProductReader.class.getResourceAsStream(resourceName); if (stream != null) { try { HashMap<String, String> validExpressionMap = new HashMap<String, String>(32); final CsvReader csvReader = new CsvReader(new InputStreamReader(stream), new char[]{';'}); final List<String[]> table = csvReader.readStringRecords(); for (String[] strings : table) { if (strings.length == 2) { validExpressionMap.put(strings[0], strings[1]); } } return validExpressionMap; } catch (IOException e) { // ? } finally { try { stream.close(); } catch (IOException e) { // ok } } } return new HashMap<String, String>(0); }
static FeatureCollection<SimpleFeatureType, SimpleFeature> readTrack(Reader reader, GeoCoding geoCoding) throws IOException { CsvReader csvReader = new CsvReader(reader, new char[]{'\t', ' '}, true, "#"); SimpleFeatureType trackFeatureType = createTrackFeatureType(geoCoding); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = new ListFeatureCollection(trackFeatureType); double[] record; int pointIndex = 0; while ((record = csvReader.readDoubleRecord()) != null) { if (record.length < 3) { throw new IOException("Illegal track file format.\n" +
public double[] readDoubleRecord() throws IOException { String[] stringRecord = readRecord(); if (stringRecord == null) { return null; } double[] doubleRecord = new double[stringRecord.length]; for (int i = 0; i < doubleRecord.length; i++) { try { doubleRecord[i] = Double.parseDouble(stringRecord[i]); } catch (NumberFormatException e) { throw new IOException(e); } } return doubleRecord; }
@Test public void testGetSeparators() { Reader reader = new StringReader("mem"); assertArrayEquals(new char[]{'|'}, new CsvReader(reader, new char[]{'|'}).getSeparators()); assertArrayEquals(new char[]{'|', ','}, new CsvReader(reader, new char[]{'|', ','}).getSeparators()); }
private InterpretationStrategy createInterpretationStrategy() throws IOException { reader.reset(); String[] tokens = reader.readRecord(); reader.reset();
@Test public void testReadAllRecords() throws IOException { CsvReader reader = createReader(CSV_DATA, '|'); List<String[]> records = reader.readStringRecords(); assertEquals(EXPECTED_RECORDS.length, records.size()); for (int i = 0; i < records.size(); i++) { assertArrayEquals(EXPECTED_RECORDS[i], records.get(i)); } }
private static void closeCsvReader(CsvReader csvReader, URL url) { Debug.assertNotNull(csvReader); Debug.assertNotNull(url); try { csvReader.close(); } catch (IOException e) { Debug.trace("DDDB: I/O warning: failed to close DDDB file: " /*I18N*/ + url + ": " + e.getMessage()); } }
public List<double[]> readDoubleRecords() throws IOException { ArrayList<double[]> vector = new ArrayList<double[]>(256); double[] record; while ((record = readDoubleRecord()) != null) { vector.add(record); } vector.trimToSize(); return vector; }
private void raiseSyntaxError(CsvReader csvReader, URL url, String message) throws DDDBException { StringBuffer sb = new StringBuffer(); sb.append(message); sb.append(": file "); sb.append(url); sb.append(", "); sb.append("line "); sb.append(csvReader.getLineNumber()); throw new DDDBException(sb.toString()); }
private static CsvReader openCsvReader(URL url) throws DDDBException { Debug.assertNotNull(url); try { return new CsvReader(new InputStreamReader(url.openStream()), FIELD_SEPARATORS); } catch (IOException e) { StringBuffer sb = new StringBuffer(); sb.append("failed to open DDDB resource: "); /*I18N*/ sb.append(e.getMessage()); sb.append(": file "); sb.append(url); throw new DDDBException(sb.toString()); } }
/** * Reads the complete file from the current position on. If the <code>readLineRecord</code> has not previously been * called the method reads all records from the beginning of the file. For empty files, the method returns an vector * having a zero size. * * @return an vector of <code>String[]</code> records containing the tokens delimitted by the separator character * passed to the constructor * @throws IOException if an I/O error occurs */ public List<String[]> readStringRecords() throws IOException { ArrayList<String[]> vector = new ArrayList<String[]>(256); String[] record; while ((record = readRecord()) != null) { vector.add(record); } vector.trimToSize(); return vector; }
while ((records = reader.readRecord()) != null) { reader.close();
JavaTypeConverter jtc = new JavaTypeConverter(); String[] firstRecord = reader.readRecord(); if (firstRecord != null && firstRecord.length != tokens.length) { throw new IOException("First record and header have different column count."); reader.reset();
@Test public void testMultipleSeparators() throws Exception { CsvReader reader = createReader("a$b|c\nd$$\n|$i", '|', '$'); List<String[]> records = reader.readStringRecords(); assertEquals(3, records.size()); assertArrayEquals(new String[]{"a", "b", "c"}, records.get(0)); assertArrayEquals(new String[]{"d", "", ""}, records.get(1)); assertArrayEquals(new String[]{"", "", "i"}, records.get(2)); }