Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions test/jdk/ProblemList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,6 @@ java/nio/channels/AsynchronousSocketChannel/StressLoopback.java 8211851 aix-ppc6

java/nio/channels/DatagramChannel/ManySourcesAndTargets.java 8264385 macosx-aarch64

java/nio/file/Files/CopyProcFile.java 8294519 linux-all

############################################################################

# jdk_rmi
Expand Down
22 changes: 12 additions & 10 deletions test/jdk/java/nio/file/Files/CopyProcFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* @run testng/othervm CopyProcFile
*/
public class CopyProcFile {
static final String SOURCE = "/proc/cpuinfo";
static final String SOURCE = "/proc/version";
static final String BUFFERED_COPY = "bufferedCopy";
static final String TARGET = "target";

Expand All @@ -58,7 +58,7 @@ public class CopyProcFile {
static long theSize;

// copy src to dst via Java buffers
static long bufferedCopy(String src, String dst) {
static long bufferedCopy(String src, String dst) throws IOException {
try (InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst)) {
byte[] b = new byte[BUF_SIZE];
Expand All @@ -69,8 +69,6 @@ static long bufferedCopy(String src, String dst) {
total += n;
}
return total;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

Expand Down Expand Up @@ -115,17 +113,19 @@ static long transferFrom(String src, String dst) {
}

@BeforeTest(alwaysRun=true)
public void createBufferedCopy() {
public void createBufferedCopy() throws IOException {
System.out.printf("Using source file \"%s\"%n", SOURCE);
try {
theSize = bufferedCopy(SOURCE, BUFFERED_COPY);
System.out.printf("Copied %d bytes from %s%n", theSize, SOURCE);
if (Files.mismatch(Path.of(BUFFERED_COPY), Path.of(SOURCE)) != -1)
throw new RuntimeException("Copy does not match source");
} catch (Exception e) {
} catch (IOException e) {
try {
Files.delete(Path.of(BUFFERED_COPY));
} catch (IOException ignore) {}
throw e;
}
if (Files.mismatch(Path.of(BUFFERED_COPY), Path.of(SOURCE)) != -1) {
throw new RuntimeException("Copy does not match source");
}
}

Expand Down Expand Up @@ -162,13 +162,15 @@ static Object[][] functions() throws IOException {
public static void testCopyAndTransfer(FHolder f) throws IOException {
try {
long size = f.apply(SOURCE, TARGET);
if (size != theSize)
if (size != theSize) {
throw new RuntimeException("Size: expected " + theSize +
"; actual: " + size);
}
long mismatch = Files.mismatch(Path.of(BUFFERED_COPY),
Path.of(TARGET));
if (mismatch != -1)
if (mismatch != -1) {
throw new RuntimeException("Target does not match copy");
}
} finally {
try {
Files.delete(Path.of(TARGET));
Expand Down