4949 * @run testng/othervm CopyProcFile
5050 */
5151public class CopyProcFile {
52- static final String SOURCE = "/proc/cpuinfo " ;
52+ static final String SOURCE = "/proc/version " ;
5353 static final String BUFFERED_COPY = "bufferedCopy" ;
5454 static final String TARGET = "target" ;
5555
@@ -58,7 +58,7 @@ public class CopyProcFile {
5858 static long theSize ;
5959
6060 // 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 {
6262 try (InputStream in = new FileInputStream (src );
6363 OutputStream out = new FileOutputStream (dst )) {
6464 byte [] b = new byte [BUF_SIZE ];
@@ -69,8 +69,6 @@ static long bufferedCopy(String src, String dst) {
6969 total += n ;
7070 }
7171 return total ;
72- } catch (IOException e ) {
73- throw new UncheckedIOException (e );
7472 }
7573 }
7674
@@ -115,17 +113,19 @@ static long transferFrom(String src, String dst) {
115113 }
116114
117115 @ BeforeTest (alwaysRun =true )
118- public void createBufferedCopy () {
116+ public void createBufferedCopy () throws IOException {
119117 System .out .printf ("Using source file \" %s\" %n" , SOURCE );
120118 try {
121119 theSize = bufferedCopy (SOURCE , BUFFERED_COPY );
122120 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 ) {
126122 try {
127123 Files .delete (Path .of (BUFFERED_COPY ));
128124 } 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" );
129129 }
130130 }
131131
@@ -162,13 +162,15 @@ static Object[][] functions() throws IOException {
162162 public static void testCopyAndTransfer (FHolder f ) throws IOException {
163163 try {
164164 long size = f .apply (SOURCE , TARGET );
165- if (size != theSize )
165+ if (size != theSize ) {
166166 throw new RuntimeException ("Size: expected " + theSize +
167167 "; actual: " + size );
168+ }
168169 long mismatch = Files .mismatch (Path .of (BUFFERED_COPY ),
169170 Path .of (TARGET ));
170- if (mismatch != -1 )
171+ if (mismatch != -1 ) {
171172 throw new RuntimeException ("Target does not match copy" );
173+ }
172174 } finally {
173175 try {
174176 Files .delete (Path .of (TARGET ));
0 commit comments