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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()关闭Readerprotected Stringprotected booleanisValidLine(String line) 重写此方法来判断是否每一行都被返回,默认全部为trueMethods inherited from class com.luna.common.math.ComputeIter
finish, hasNext, nextMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface com.luna.common.utils.IterableIter
iteratorMethods inherited from interface java.util.Iterator
forEachRemaining, hasNext, next, remove
-
Constructor Details
-
LineIter
构造- Parameters:
in-InputStreamcharset- 编码- Throws:
IllegalArgumentException- reader为null抛出此异常
-
LineIter
构造- Parameters:
reader-Reader对象,不能为null- Throws:
IllegalArgumentException- reader为null抛出此异常
-
-
Method Details
-
computeNext
Description copied from class:ComputeIter- Specified by:
computeNextin classComputeIter<String>- Returns:
- 节点值
-
close
public void close()关闭Reader- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isValidLine
重写此方法来判断是否每一行都被返回,默认全部为true- Parameters:
line- 需要验证的行- Returns:
- 是否通过验证
-