本文整理汇总了Java中java.nio.file.DirectoryStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java DirectoryStream.close方法的具体用法?Java DirectoryStream.close怎么用?Java DirectoryStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.DirectoryStream
的用法示例。
在下文中一共展示了DirectoryStream.close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteHeapTempFiles
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
public static void deleteHeapTempFiles() {
if (Platform.isWindows()) { // this is workaroud for JDK bug #6359560
try {
File tempDir = new File(System.getProperty("java.io.tmpdir")); // NOI18N
DirectoryStream<Path> files = Files.newDirectoryStream(tempDir.toPath());
try {
for (Path p : files) {
String fname = p.toFile().getName();
if (fname.startsWith("NBProfiler") && (fname.endsWith(".map") || fname.endsWith(".ref") || fname.endsWith(".gc"))) { // NOI18N
Files.delete(p);
}
}
} finally {
files.close();
}
} catch (IOException ex) {
System.err.println("deleteHeapTempFiles failed"); // NOI18N
ex.printStackTrace();
}
}
}
示例2: getJavaFileNames
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
/**
* Finds all pathes to Java files in the root directory recursively and
* writes them to a list
*
* @param fileNames
* list of pathes
* @param dir
* root directory
* @return list of pathes
* @throws IOException
*/
private List<Path> getJavaFileNames(Path dir) throws IOException {
List<Path> fileNames = new ArrayList<>();
DirectoryStream<Path> stream = null;
try {
stream = Files.newDirectoryStream(dir);
for (Path path : stream) {
if (path.toFile().isDirectory()) {
fileNames.addAll(getJavaFileNames(path));
} else if (path.getFileName().toString().endsWith(".java")) {
fileNames.add(path);
}
}
} finally {
if (stream != null) {
stream.close();
}
}
return fileNames;
}
示例3: testDirectoryStreamAllItems
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
public void testDirectoryStreamAllItems() throws IOException {
Path newDirectory = DIRECTORY_STREAM_FILE_DIR;
List<String> dirGlob = new LinkedList<String>();
DirectoryStream<Path> directoryContents = Files.newDirectoryStream(newDirectory);
try {
for (Path path: directoryContents) {
// Just check we aren't getting hidden files
if (path.toString().endsWith("txt")) {
dirGlob.add(path.toString());
}
}
} finally {
directoryContents.close();
}
if(!ReiserSpotter.getIsReiser()){
assertEquals("Checking for correct number of files return (no filter) found " + Arrays.toString(dirGlob.toArray()) +
" actual total list is " + Arrays.toString(files.toArray()),
NUMBER_OF_FILES, dirGlob.size());
}
}
示例4: testDirectoryStreamGlobAllItems
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
public void testDirectoryStreamGlobAllItems() throws IOException {
Path newDirectory = DIRECTORY_STREAM_FILE_DIR;
List<String> dirGlob = new LinkedList<String>();
DirectoryStream<Path> directoryContents = Files.newDirectoryStream(newDirectory, "*");
try {
for (Path path: directoryContents) {
// Just check we aren't getting hidden files
if (path.toString().endsWith("txt")) {
dirGlob.add(path.toString());
}
}
} finally {
directoryContents.close();
}
if(!ReiserSpotter.getIsReiser()){
assertEquals("Checking for correct number of files return (globbed all) found " + Arrays.toString(dirGlob.toArray()) +
" actual total list is " + Arrays.toString(files.toArray()), NUMBER_OF_FILES, dirGlob.size());
}
}
示例5: testDirectoryStreamGlobSomeItems
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
public void testDirectoryStreamGlobSomeItems() throws IOException {
final int EXPECTED_NUMBER_OF_FILES = 1;
Path newDirectory = DIRECTORY_STREAM_FILE_DIR;
List<String> dirGlob = new LinkedList<String>();
DirectoryStream<Path> directoryContents = Files.newDirectoryStream(newDirectory, "*1.txt");
try {
for (Path path: directoryContents) {
dirGlob.add(path.toString());
}
} finally {
directoryContents.close();
}
if(!ReiserSpotter.getIsReiser()){
assertEquals("Checking for correct number of files return (globbed on ends in '1') found " + Arrays.toString(dirGlob.toArray()) +
" actual total list is (from which we expect a subset)" + Arrays.toString(files.toArray()),
EXPECTED_NUMBER_OF_FILES, dirGlob.size());
}
}
示例6: testDirectoryStreamFilterAllItems
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
public void testDirectoryStreamFilterAllItems() throws IOException {
final int EXPECTED_NUMBER_OF_FILES = 10;
Path newDirectory = DIRECTORY_STREAM_FILE_DIR;
List<String> dirGlob = new LinkedList<String>();
DirectoryStream<Path> directoryContents = Files.newDirectoryStream(newDirectory, new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
return true;
}
});
try {
for (Path path: directoryContents) {
dirGlob.add(path.toString());
}
} finally {
directoryContents.close();
}
if(!ReiserSpotter.getIsReiser()){
assertEquals("Checking for correct number of files return (filtered on all) found " + Arrays.toString(dirGlob.toArray()) +
" actual total list is " + Arrays.toString(files.toArray()),
EXPECTED_NUMBER_OF_FILES, dirGlob.size());
}
}
示例7: list
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
static List<File> list(DirectoryStream<Path> stream) throws IOException
{
try
{
return StreamSupport.stream(stream.spliterator(), false)
.map(Path::toFile)
.filter((f) -> !f.isDirectory())
.collect(Collectors.toList());
}
finally
{
stream.close();
}
}
示例8: testDirectoryStreamFilterSomeItems
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
public void testDirectoryStreamFilterSomeItems() throws IOException {
final int EXPECTED_NUMBER_OF_FILES = 1;
Path newDirectory = DIRECTORY_STREAM_FILE_DIR;
List<String> dirGlob = new LinkedList<String>();
DirectoryStream<Path> directoryContents = Files.newDirectoryStream(newDirectory, new DirectoryStream.Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
if (entry.toString().endsWith("1.txt")) {
return true;
}
return false;
}
});
try {
for (Path path: directoryContents) {
dirGlob.add(path.toString());
}
} finally {
directoryContents.close();
}
if(!ReiserSpotter.getIsReiser()){
assertEquals("Checking for correct number of files return (filtered on ends in '1') found " + Arrays.toString(dirGlob.toArray()) +
" actual total list is (from which we expect a subset)" + Arrays.toString(files.toArray()),
EXPECTED_NUMBER_OF_FILES, dirGlob.size());
}
}
示例9: checkCompiledScripts
import java.nio.file.DirectoryStream; //导入方法依赖的package包/类
private static void checkCompiledScripts(final DirectoryStream<Path> stream, final int numberOfScripts) throws IOException {
int n = numberOfScripts;
for (@SuppressWarnings("unused") final Path file : stream) {
n--;
}
stream.close();
assertEquals(n, 0);
}
示例10: 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();
}
};
}