49
49
* @run testng/othervm CopyProcFile
50
50
*/
51
51
public class CopyProcFile {
52
- static final String SOURCE = "/proc/cpuinfo " ;
52
+ static final String SOURCE = "/proc/version " ;
53
53
static final String BUFFERED_COPY = "bufferedCopy" ;
54
54
static final String TARGET = "target" ;
55
55
@@ -58,7 +58,7 @@ public class CopyProcFile {
58
58
static long theSize ;
59
59
60
60
// copy src to dst via Java buffers
61
- static long bufferedCopy (String src , String dst ) {
61
+ static long bufferedCopy (String src , String dst ) throws IOException {
62
62
try (InputStream in = new FileInputStream (src );
63
63
OutputStream out = new FileOutputStream (dst )) {
64
64
byte [] b = new byte [BUF_SIZE ];
@@ -69,8 +69,6 @@ static long bufferedCopy(String src, String dst) {
69
69
total += n ;
70
70
}
71
71
return total ;
72
- } catch (IOException e ) {
73
- throw new UncheckedIOException (e );
74
72
}
75
73
}
76
74
@@ -115,17 +113,19 @@ static long transferFrom(String src, String dst) {
115
113
}
116
114
117
115
@ BeforeTest (alwaysRun =true )
118
- public void createBufferedCopy () {
116
+ public void createBufferedCopy () throws IOException {
119
117
System .out .printf ("Using source file \" %s\" %n" , SOURCE );
120
118
try {
121
119
theSize = bufferedCopy (SOURCE , BUFFERED_COPY );
122
120
System .out .printf ("Copied %d bytes from %s%n" , theSize , SOURCE );
123
- if (Files .mismatch (Path .of (BUFFERED_COPY ), Path .of (SOURCE )) != -1 )
124
- throw new RuntimeException ("Copy does not match source" );
125
- } catch (Exception e ) {
121
+ } catch (IOException e ) {
126
122
try {
127
123
Files .delete (Path .of (BUFFERED_COPY ));
128
124
} catch (IOException ignore ) {}
125
+ throw e ;
126
+ }
127
+ if (Files .mismatch (Path .of (BUFFERED_COPY ), Path .of (SOURCE )) != -1 ) {
128
+ throw new RuntimeException ("Copy does not match source" );
129
129
}
130
130
}
131
131
@@ -162,13 +162,15 @@ static Object[][] functions() throws IOException {
162
162
public static void testCopyAndTransfer (FHolder f ) throws IOException {
163
163
try {
164
164
long size = f .apply (SOURCE , TARGET );
165
- if (size != theSize )
165
+ if (size != theSize ) {
166
166
throw new RuntimeException ("Size: expected " + theSize +
167
167
"; actual: " + size );
168
+ }
168
169
long mismatch = Files .mismatch (Path .of (BUFFERED_COPY ),
169
170
Path .of (TARGET ));
170
- if (mismatch != -1 )
171
+ if (mismatch != -1 ) {
171
172
throw new RuntimeException ("Target does not match copy" );
173
+ }
172
174
} finally {
173
175
try {
174
176
Files .delete (Path .of (TARGET ));
0 commit comments