Package com.luna.common.file
Class LineIter
- All Implemented Interfaces:
IterableIter<String>
,Closeable
,Serializable
,AutoCloseable
,Iterable<String>
,Iterator<String>
public class LineIter
extends ComputeIter<String>
implements IterableIter<String>, Closeable, Serializable
将Reader包装为一个按照行读取的Iterator
此对象遍历结束后,应关闭之,推荐使用方式:
此对象遍历结束后,应关闭之,推荐使用方式:
LineIterator it = null; try { it = new LineIterator(reader); while (it.hasNext()) { String line = it.nextLine(); // do something with line } } finally { it.close(); }此类来自于Apache Commons io
- Since:
- 4.1.1
- Author:
- looly
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
关闭Readerprotected String
protected boolean
isValidLine
(String line) 重写此方法来判断是否每一行都被返回,默认全部为trueMethods inherited from class com.luna.common.math.ComputeIter
finish, hasNext, next
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface com.luna.common.utils.IterableIter
iterator
Methods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Constructor Details
-
LineIter
构造- Parameters:
in
-InputStream
charset
- 编码- Throws:
IllegalArgumentException
- reader为null抛出此异常
-
LineIter
构造- Parameters:
reader
-Reader
对象,不能为null- Throws:
IllegalArgumentException
- reader为null抛出此异常
-
-
Method Details
-
computeNext
Description copied from class:ComputeIter
- Specified by:
computeNext
in classComputeIter<String>
- Returns:
- 节点值
-
close
public void close()关闭Reader- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
isValidLine
重写此方法来判断是否每一行都被返回,默认全部为true- Parameters:
line
- 需要验证的行- Returns:
- 是否通过验证
-