Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit fa89ddb

Browse files
committed
Ignore IOException when walking through the temp folder
Change-Id: I65cdbce2fc837259320c237eb90a8520ac223b5f
1 parent 5537bd6 commit fa89ddb

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

tests/integration/jersey-2794/src/test/java/org/glassfish/jersey/tests/integration/jersey2794/Jersey2794ITCase.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2015-2017 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2015-2018 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -44,8 +44,13 @@
4444
import java.io.OutputStream;
4545
import java.net.HttpURLConnection;
4646
import java.net.URL;
47+
import java.nio.file.FileVisitResult;
4748
import java.nio.file.Files;
49+
import java.nio.file.Path;
4850
import java.nio.file.Paths;
51+
import java.nio.file.SimpleFileVisitor;
52+
import java.nio.file.attribute.BasicFileAttributes;
53+
import java.util.concurrent.atomic.AtomicInteger;
4954

5055
import javax.ws.rs.core.Application;
5156

@@ -122,9 +127,26 @@ public void mimeTempFileRemoved() throws Exception {
122127
}
123128

124129
private int matchingTempFiles(final String tempDir) throws IOException {
125-
return (int) Files.walk(Paths.get(tempDir)).filter(path -> {
126-
final String name = path.getFileName().toString();
127-
return name.startsWith("MIME") && name.endsWith("tmp");
128-
}).count();
130+
AtomicInteger count = new AtomicInteger(0);
131+
Files.walkFileTree(Paths.get(tempDir), new SimpleFileVisitor<Path>() {
132+
@Override
133+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
134+
if (file.getFileName().startsWith("MIME") && file.getFileName().endsWith("tmp")) {
135+
count.incrementAndGet();
136+
}
137+
return FileVisitResult.CONTINUE;
138+
}
139+
140+
@Override
141+
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
142+
return FileVisitResult.CONTINUE;
143+
}
144+
145+
@Override
146+
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
147+
return FileVisitResult.CONTINUE;
148+
}
149+
});
150+
return count.get();
129151
}
130152
}

tests/integration/jersey-2846/src/test/java/org/glassfish/jersey/tests/integration/jersey2846/Jersey2846ITCase.java

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2015-2017 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2015-2018 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -41,10 +41,14 @@
4141
package org.glassfish.jersey.tests.integration.jersey2846;
4242

4343
import java.io.IOException;
44+
import java.nio.file.FileVisitResult;
4445
import java.nio.file.Files;
46+
import java.nio.file.Path;
4547
import java.nio.file.Paths;
48+
import java.nio.file.SimpleFileVisitor;
49+
import java.nio.file.attribute.BasicFileAttributes;
4650
import java.util.Arrays;
47-
import java.util.function.Predicate;
51+
import java.util.concurrent.atomic.AtomicInteger;
4852

4953
import javax.ws.rs.client.Entity;
5054
import javax.ws.rs.core.Application;
@@ -143,10 +147,27 @@ public void _test(final String path, final int status, final Object entity) thro
143147
}
144148

145149
private int matchingTempFiles(final String tempDir) throws IOException {
146-
return (int) Files.walk(Paths.get(tempDir)).filter(path -> {
147-
final String name = path.getFileName().toString();
148-
return (name.startsWith("rep") || name.startsWith("MIME"))
149-
&& name.endsWith("tmp");
150-
}).count();
150+
AtomicInteger count = new AtomicInteger(0);
151+
Files.walkFileTree(Paths.get(tempDir), new SimpleFileVisitor<Path>() {
152+
@Override
153+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
154+
Path name = file.getFileName();
155+
if ((name.startsWith("rep") || name.startsWith("MIME")) && name.endsWith("tmp")) {
156+
count.incrementAndGet();
157+
}
158+
return FileVisitResult.CONTINUE;
159+
}
160+
161+
@Override
162+
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
163+
return FileVisitResult.CONTINUE;
164+
}
165+
166+
@Override
167+
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
168+
return FileVisitResult.CONTINUE;
169+
}
170+
});
171+
return count.get();
151172
}
152173
}

0 commit comments

Comments
 (0)