/** * Returns an Iterator for the lines in a <code>File</code> using the default encoding for the VM. * * @param file the file to open for input, must not be {@code null} * @return an Iterator of the lines in the file, never {@code null} * @throws IOException in case of an I/O error (file closed) * @see #lineIterator(File, String) * @since 1.3 */ public static LineIterator lineIterator(final File file) throws IOException { return lineIterator(file, null); }
/** * Return an Iterator for the lines in a <code>File</code> using the default encoding for the VM. * * @param file the file to open for input, must not be <code>null</code> * @return an Iterator of the lines in the file, never <code>null</code> * @throws IOException in case of an I/O error (file closed) * @since Commons IO 1.3 * @see #lineIterator(File, String) */ public static LineIterator lineIterator(File file) throws IOException { return lineIterator(file, null); }
INDArray newArr = Nd4j.zeros(2, 2); try { LineIterator it = FileUtils.lineIterator(jsonFile); try { while (it.hasNext()) {
@Test public void testNextLineOnlyNullEncoding() throws Exception { final String encoding = null; final File testFile = new File(getTestDirectory(), "LineIterator-nextOnly.txt"); final List<String> lines = createLinesFile(testFile, encoding, 3); final LineIterator iterator = FileUtils.lineIterator(testFile, encoding); assertLines(lines, iterator); }
@Test public void testNextLineOnlyDefaultEncoding() throws Exception { final File testFile = new File(getTestDirectory(), "LineIterator-nextOnly.txt"); final List<String> lines = createLinesFile(testFile, 3); final LineIterator iterator = FileUtils.lineIterator(testFile); assertLines(lines, iterator); }
@Test public void testNextLineOnlyUtf8Encoding() throws Exception { final String encoding = "UTF-8"; final File testFile = new File(getTestDirectory(), "LineIterator-nextOnly.txt"); final List<String> lines = createLinesFile(testFile, encoding, 3); final LineIterator iterator = FileUtils.lineIterator(testFile, encoding); assertLines(lines, iterator); }
@Test public void testMissingFile() throws Exception { final File testFile = new File(getTestDirectory(), "dummy-missing-file.txt"); LineIterator iterator = null; try { iterator = FileUtils.lineIterator(testFile, "UTF-8"); fail("Expected FileNotFoundException"); } catch (final FileNotFoundException expected) { // ignore, expected result } finally { LineIterator.closeQuietly(iterator); } }
@Test public void testInvalidEncoding() throws Exception { final String encoding = "XXXXXXXX"; final File testFile = new File(getTestDirectory(), "LineIterator-invalidEncoding.txt"); createLinesFile(testFile, "UTF-8", 3); LineIterator iterator = null; try { iterator = FileUtils.lineIterator(testFile, encoding); fail("Expected UnsupportedCharsetException"); } catch (final UnsupportedCharsetException expected) { // ignore, expected result } finally { LineIterator.closeQuietly(iterator); } }
@Test public void testNextOnly() throws Exception { final String encoding = null; final File testFile = new File(getTestDirectory(), "LineIterator-nextOnly.txt"); final List<String> lines = createLinesFile(testFile, encoding, 3); final LineIterator iterator = FileUtils.lineIterator(testFile, encoding); try { for (int i = 0; i < lines.size(); i++) { final String line = iterator.next(); assertEquals("next() line " + i, lines.get(i), line); } assertEquals("No more expected", false, iterator.hasNext()); } finally { LineIterator.closeQuietly(iterator); } }
@Test public void testValidEncoding() throws Exception { final String encoding = "UTF-8"; final File testFile = new File(getTestDirectory(), "LineIterator-validEncoding.txt"); createLinesFile(testFile, encoding, 3); final LineIterator iterator = FileUtils.lineIterator(testFile, encoding); try { int count = 0; while (iterator.hasNext()) { assertNotNull(iterator.next()); count++; } assertEquals(3, count); } finally { LineIterator.closeQuietly(iterator); } }
final List<String> lines = createLinesFile(testFile, encoding, lineCount); final LineIterator iterator = FileUtils.lineIterator(testFile, encoding); try { try {
createLinesFile(testFile, encoding, 3); final LineIterator iterator = FileUtils.lineIterator(testFile, encoding); try {
/** * Returns an Iterator for the lines in a <code>File</code> using the default encoding for the VM. * * @param file the file to open for input, must not be <code>null</code> * @return an Iterator of the lines in the file, never <code>null</code> * @throws IOException in case of an I/O error (file closed) * @since Commons IO 1.3 * @see #lineIterator(File, String) */ public static LineIterator lineIterator(File file) throws IOException { return lineIterator(file, null); }
/** * Returns an Iterator for the lines in a <code>File</code> using the default encoding for the VM. * * @param file the file to open for input, must not be <code>null</code> * @return an Iterator of the lines in the file, never <code>null</code> * @throws IOException in case of an I/O error (file closed) * @since Commons IO 1.3 * @see #lineIterator(File, String) */ public static LineIterator lineIterator(File file) throws IOException { return lineIterator(file, null); }
/** * Returns an Iterator for the lines in a <code>File</code> using the default encoding for the VM. * * @param file the file to open for input, must not be {@code null} * @return an Iterator of the lines in the file, never {@code null} * @throws IOException in case of an I/O error (file closed) * @see #lineIterator(File, String) * @since 1.3 */ public static LineIterator lineIterator(final File file) throws IOException { return lineIterator(file, null); }
public FileLineDifferenceIterator(File marked, File available, @Nullable Function<String, String> transformer) throws IOException { this(FileUtils.lineIterator(marked, UTF_8.toString()), FileUtils.lineIterator(available, UTF_8.toString()), transformer); }
public FileLineDifferenceIterator(File marked, File available, @Nullable Function<String, String> transformer) throws IOException { this(FileUtils.lineIterator(marked, UTF_8.toString()), FileUtils.lineIterator(available, UTF_8.toString()), transformer); }
/** * Returns a file throwing a UserException if the file cannot be read. * @param file File * @return LineIterator */ public static LineIterator lineIterator(File file) { try { return FileUtils.lineIterator(file); } catch (IOException e) { throw new UserException.CouldNotReadInputFile(file, e); } }
@Override public void processAll() throws Exception { File listFile = new File(fileListPath); File dataFolder = new File(listFile.getParent(),"data"); LineIterator iterator = FileUtils.lineIterator(listFile); while(iterator.hasNext()){ File f = new File(dataFolder,iterator.nextLine()+".sgm"); String text = FileUtils.readFileToString(f); processDoc(text); } iterator.close(); }
@Test public void fileIteratorBurnTest() throws Exception { Set<String> added = newHashSet("a", "z", "e", "b"); File f = assertWrite(added.iterator(), false, added.size()); BurnOnCloseFileIterator iterator = BurnOnCloseFileIterator.wrap(FileUtils.lineIterator(f, UTF_8.toString()), f); assertEquals(added, Sets.newHashSet(iterator)); assertTrue(!f.exists()); }