public static BufferedReader getBufferedReader(File file) throws IllegalStateException { return getBufferedReader(file, DEFAULT_ENCODING); }
public static BufferedReader getBufferedReader(File file) throws IllegalStateException { return getBufferedReader(file, DEFAULT_ENCODING); }
public static void copy(Reader reader, Writer writer) throws IllegalStateException { final BufferedReader bufferedReader = getBufferedReader(reader); try { boolean firstLine = true; for (String line = bufferedReader.readLine(); line != null; line = bufferedReader.readLine()) { if (firstLine) { firstLine = false; } else { writer.write('\n'); } writer.write(line); } } catch (IOException e) { throw new IllegalStateException(e); } }
public static void copy(Reader reader, Writer writer) throws IllegalStateException { final BufferedReader bufferedReader = getBufferedReader(reader); try { boolean firstLine = true; for (String line = bufferedReader.readLine(); line != null; line = bufferedReader.readLine()) { if (firstLine) { firstLine = false; } else { writer.write('\n'); } writer.write(line); } } catch (IOException e) { throw new IllegalStateException(e); } }
public void generateCoreFile() throws IOException { final File coreSiteFile = new File(confFolder, "conf-site.xml"); try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("core-site-template.xml")) { final BufferedReader reader = FileHelper.getBufferedReader(inputStream, FileHelper.UTF_8_ENCODING); try (Writer writer = FileHelper.getWriter(coreSiteFile)) { String line = reader.readLine(); while (line != null) { line = line.replace("${PATH}", path); writer.write(line); line = reader.readLine(); } writer.flush(); } } }
public static String readAsString(Reader reader) throws IllegalStateException { final BufferedReader br = getBufferedReader(reader); try { StringBuilder sb = new StringBuilder(); boolean firstLine = true; for (String line = br.readLine(); line != null; line = br.readLine()) { if (firstLine) { firstLine = false; } else { sb.append('\n'); } sb.append(line); } return sb.toString(); } catch (Exception e) { throw new IllegalStateException(e); } finally { safeClose(br, reader); } }
private Set<String> loadEntries() { Set<String> entries = new HashSet<String>(); BufferedReader reader = null; try { reader = FileHelper.getBufferedReader(getFile(), _encoding); for (String line = reader.readLine(); line != null; line = reader.readLine()) { entries.add(line); } } catch (Exception e) { throw new IllegalStateException(e); } finally { FileHelper.safeClose(reader); } return entries; }
public static String readAsString(Reader reader) throws IllegalStateException { final BufferedReader br = getBufferedReader(reader); try { StringBuilder sb = new StringBuilder(); boolean firstLine = true; for (String line = br.readLine(); line != null; line = br.readLine()) { if (firstLine) { firstLine = false; } else { sb.append('\n'); } sb.append(line); } return sb.toString(); } catch (Exception e) { throw new IllegalStateException(e); } finally { safeClose(br, reader); } }
private void createTemporaryHadoopConfFile(final File hadoopConfDir, final String filename, final String templateName) throws IOException { final File coreSiteFile = new File(hadoopConfDir, filename); try (InputStream inputStream = getClass().getResourceAsStream(templateName)) { final BufferedReader reader = FileHelper.getBufferedReader(inputStream, FileHelper.UTF_8_ENCODING); try (Writer writer = FileHelper.getWriter(coreSiteFile)) { String line = reader.readLine(); while (line != null) { line = StringUtils.replaceAll(line, "${HDFS_HOSTNAME}", _defaultFs.getHost()); line = StringUtils.replaceAll(line, "${HDFS_PORT}", _defaultFs.getPort() + ""); writer.write(line); line = reader.readLine(); } writer.flush(); } } }
@Override public Collection<Synonym> getSynonyms() { BufferedReader reader = FileHelper.getBufferedReader(getFile(), _encoding); try { List<Synonym> synonyms = new ArrayList<Synonym>(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { line = line.trim(); synonyms.add(new TextFileSynonym(line, _caseSensitive)); } return synonyms; } catch (IOException e) { throw new IllegalStateException(e); } finally { FileHelper.safeClose(reader); } }
final BufferedReader reader = FileHelper.getBufferedReader(inputStream, encoding);
final BufferedReader reader = FileHelper.getBufferedReader(inputStream, encoding);
final BufferedReader reader = FileHelper.getBufferedReader(in, _encoding); try { for (String line = reader.readLine(); line != null; line = reader.readLine()) {
@Override public DictionaryConnection openConnection(final DataCleanerConfiguration configuration) { final ResourceConverter rc = new ResourceConverter(configuration); final Resource resource = rc.fromString(Resource.class, _filename); final Set<String> values = resource.read(in -> { final Set<String> values1 = new HashSet<>(); final BufferedReader reader = FileHelper.getBufferedReader(in, getEncoding()); try { String line = reader.readLine(); while (line != null) { if (!_caseSensitive) { line = line.toLowerCase(); } values1.add(line); line = reader.readLine(); } } catch (final IOException e) { logger.error("Failed to read line from resource: {}", resource, e); } finally { FileHelper.safeClose(reader); } return values1; }); final SimpleDictionary simpleDictionary = new SimpleDictionary(getName(), values, _caseSensitive); return simpleDictionary.openConnection(configuration); }
@Override public String getMasterTerm(String term) { if (StringUtils.isNullOrEmpty(term)) { return null; } String masterTerm = getMasterTermCache().getIfPresent(term); if (masterTerm != null) { return masterTerm; } BufferedReader reader = FileHelper.getBufferedReader(getFile(), _encoding); try { for (String line = reader.readLine(); line != null; line = reader.readLine()) { line = line.trim(); TextFileSynonym synonym = new TextFileSynonym(line, _caseSensitive); masterTerm = synonym.getMasterTerm(); if (term.equals(masterTerm) || synonym.getSynonyms().containsValue(term)) { getMasterTermCache().put(term, masterTerm); return masterTerm; } } return null; } catch (IOException e) { throw new IllegalStateException(e); } finally { FileHelper.safeClose(reader); } } }
@Override public DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) { final int lineNumber = _configuration.getColumnNameLineNumber(); final int columnCount = table.getColumnCount(); final BufferedReader reader = FileHelper.getBufferedReader(_resource.read(), _configuration.getEncoding()); try { // skip column header lines for (int i = 0; i < lineNumber; i++) { String line = reader.readLine(); if (line == null) { FileHelper.safeClose(reader); return EmptyDataSet.fromColumns(columns); } } } catch (IOException e) { FileHelper.safeClose(reader); throw new MetaModelException("IOException occurred while reading from CSV resource: " + _resource, e); } final boolean failOnInconsistentRowLength = _configuration.isFailOnInconsistentRowLength(); final Integer maxRowsOrNull = (maxRows > 0 ? maxRows : null); if (_configuration.isMultilineValues()) { final CSVReader csvReader = createCsvReader(reader); return new CsvDataSet(csvReader, columns, maxRowsOrNull, columnCount, failOnInconsistentRowLength); } return new SingleLineCsvDataSet(reader, createParser(), columns, maxRowsOrNull, columnCount, failOnInconsistentRowLength); }
@Override public DataSet materializeMainSchemaTable(Table table, List<Column> columns, int maxRows) { final int lineNumber = _configuration.getColumnNameLineNumber(); final int columnCount = table.getColumnCount(); final BufferedReader reader = FileHelper.getBufferedReader(_resource.read(), _configuration.getEncoding()); try { // skip column header lines for (int i = 0; i < lineNumber; i++) { String line = reader.readLine(); if (line == null) { FileHelper.safeClose(reader); return EmptyDataSet.fromColumns(columns); } } } catch (IOException e) { FileHelper.safeClose(reader); throw new MetaModelException("IOException occurred while reading from CSV resource: " + _resource, e); } final boolean failOnInconsistentRowLength = _configuration.isFailOnInconsistentRowLength(); final Integer maxRowsOrNull = (maxRows > 0 ? maxRows : null); if (_configuration.isMultilineValues()) { final CSVReader csvReader = createCsvReader(reader); return new CsvDataSet(csvReader, columns, maxRowsOrNull, columnCount, failOnInconsistentRowLength); } return new SingleLineCsvDataSet(reader, createParser(), columns, maxRowsOrNull, columnCount, failOnInconsistentRowLength); }