本文整理匯總了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();
}
};
}