/** * Return a <code>BufferedReader</code> for the location indicated using the platform default encoding. */ public static final BufferedReader getBufferedReader(String location) throws IOException { return getBufferedReader(location, null); }
/** * Return a <code>BufferedReader</code> that reads from <code>file</code> using the indicated encoding. <code>null</code> means use the platform's default encoding. */ public static final BufferedReader getBufferedReader(File file, String encoding) throws IOException { return getBufferedReader(FileUtils.openInputStream(file), encoding); }
public static final List<String> readLinesAndClose(InputStream in, String encoding) { Reader reader = null; try { reader = getBufferedReader(in, encoding); return readLinesAndClose(reader); } catch (IOException e) { throw new IllegalStateException("Unexpected IO error", e); } finally { IOUtils.closeQuietly(reader); } }
protected SqlMetaData getMetaData(File file, SqlReader reader, String encoding) { BufferedReader in = null; try { in = LocationUtils.getBufferedReader(file, encoding); return reader.getMetaData(in); } catch (IOException e) { throw new IllegalStateException("Unexpected IO error"); } finally { IOUtils.closeQuietly(in); } }
@Override public void open() throws IOException { this.table = getTable(location, database, extension); this.reader = LocationUtils.getBufferedReader(location, encoding); }
/** * Return a <code>BufferedReader</code> for the location indicated using the encoding indicated. */ public static final BufferedReader getBufferedReader(String location, String encoding) throws IOException { try { InputStream in = getInputStream(location); return getBufferedReader(in, encoding); } catch (IOException e) { throw new IOException("Unexpected IO error", e); } }
/** * Get the contents of <code>location</code> as a list of <code>String's</code> one entry per line using the encoding indicated. */ public static final List<String> readLines(String location, String encoding) { Reader reader = null; try { reader = getBufferedReader(location, encoding); return readLinesAndClose(reader); } catch (IOException e) { throw new IllegalStateException("Unexpected IO error", e); } finally { IOUtils.closeQuietly(reader); } }
private BufferedReader getLocationReader() throws IOException { return LocationUtils.getBufferedReader(LocationSupplierUtils.getLocationFromContextLocation(location), encoding); }
/** * Count the lines of text in the location. * * @param location * The location to read lines of text from * @return A count representing the number of lines of text * @throws IllegalStateException * If there is an i/o exception reading the file * @see BufferedReader */ public static long getLineCount(String location, String encoding) { long count = 0; BufferedReader in = null; try { in = getBufferedReader(location, encoding); while (in.readLine() != null) { count++; } return count; } catch (IOException e) { throw new IllegalStateException("Unexpected IO error", e); } finally { IOUtils.closeQuietly(in); } }
public static TextMetaData getTextMetaData(String location) { long lines = 0; long size = 0; BufferedReader in = null; try { in = getBufferedReader(location); String s = in.readLine(); while (s != null) { lines++; size += s.length(); s = in.readLine(); } return new TextMetaData(lines, size); } catch (IOException e) { throw new IllegalStateException(e); } finally { IOUtils.closeQuietly(in); } }
@Override public synchronized void open() throws IOException { Assert.isFalse(open, "Already open"); this.open = true; this.done = false; this.in = LocationUtils.getBufferedReader(location, context.getEncoding()); }
public static SqlMetaData getSqlMetaData(String location, SqlLocationContext context) { BufferedReader in = null; try { logger.debug("Getting metadata for [{}] - encoding {}", location, context.getEncoding()); in = LocationUtils.getBufferedReader(location, context.getEncoding()); return getSqlMetaData(in, context.getReader()); } catch (IOException e) { throw new IllegalStateException(e); } finally { IOUtils.closeQuietly(in); } }
logger.info("Loading properties - [{}] encoding={}", location, StringUtils.defaultIfBlank(encoding, DEFAULT_ENCODING)); reader = LocationUtils.getBufferedReader(location, encoding); properties.load(reader);
@Override public ConversionResult convert(ConversionContext context) { logger.debug("Converting {}", LocationUtils.getCanonicalPath(context.getOldFile())); File newFile = context.getNewFile(); File oldFile = context.getOldFile(); DefaultSqlReader reader = new DefaultSqlReader(context.getDelimiter()); BufferedReader in = null; OutputStream out = null; try { in = LocationUtils.getBufferedReader(oldFile, context.getEncoding()); out = FileUtils.openOutputStream(newFile); return convert(context, reader, in, out); } catch (IOException e) { throw new IllegalStateException("Unexpected IO error"); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }