本文整理汇总了Java中java.nio.file.DirectoryStream.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java DirectoryStream.iterator方法的具体用法?Java DirectoryStream.iterator怎么用?Java DirectoryStream.iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.DirectoryStream
的用法示例。
在下文中一共展示了DirectoryStream.iterator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DirectoryEntry
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
DirectoryEntry(DirectoryStream<Path> stream) {
this.stream = stream;
this.iterator = stream.iterator();
}
示例2: wrap
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
private DirectoryStream<Path> wrap(final DirectoryStream<Path> stream) {
return new DirectoryStream<Path>() {
@Override
public Iterator<Path> iterator() {
final Iterator<Path> itr = stream.iterator();
return new Iterator<Path>() {
private Path next = null;
@Override
public boolean hasNext() {
if (next == null) {
if (itr.hasNext()) {
next = itr.next();
} else {
return false;
}
}
if (next != null) {
try {
triggerEx(next, "DirectoryIteratorException");
} catch (IOException ioe) {
throw new DirectoryIteratorException(ioe);
} catch (SecurityException se) {
// ??? Does DS throw SecurityException during iteration?
next = null;
return hasNext();
}
}
return (next != null);
}
@Override
public Path next() {
try {
if (next != null || hasNext()) {
return new PassThroughFileSystem.PassThroughPath(delegate, next);
} else {
throw new NoSuchElementException();
}
} finally {
next = null;
}
}
@Override
public void remove() {
itr.remove();
}
};
}
@Override
public void close() throws IOException {
stream.close();
}
};
}