IOUtils { public static IOException wrapException(final String path, final String methodName, final IOException exception) { if (exception instanceof InterruptedIOException || exception instanceof PathIOException) { return exception; } else { String msg = String .format("Failed with %s while processing file/directory :[%s] in " + "method:[%s]", exception.getClass().getName(), path, methodName); try { return wrapWithMessage(exception, msg); } catch (Exception ex) { return new PathIOException(path, exception); } } }  static void copyBytes(InputStream in, OutputStream out,
                               int buffSize, boolean close); static void copyBytes(InputStream in, OutputStream out, int buffSize); static void copyBytes(InputStream in, OutputStream out, Configuration conf); static void copyBytes(InputStream in, OutputStream out, Configuration conf, boolean close); static void copyBytes(InputStream in, OutputStream out, long count,
      boolean close); static int wrappedReadForCompressedData(InputStream is, byte[] buf,
      int off, int len); static void readFully(InputStream in, byte[] buf,
      int off, int len); static void skipFully(InputStream in, long len); @Deprecated static void cleanup(Log log, java.io.Closeable... closeables); static void cleanupWithLogger(Logger logger,
      java.io.Closeable... closeables); static void closeStream(java.io.Closeable stream); static void closeStreams(java.io.Closeable... streams); static void closeSocket(Socket sock); static void writeFully(WritableByteChannel bc, ByteBuffer buf); static void writeFully(FileChannel fc, ByteBuffer buf,
      long offset); static List<String> listDirectory(File dir, FilenameFilter filter); static void fsync(File fileToSync); static void fsync(FileChannel channel, boolean isDir); static IOException wrapException(final String path,
      final String methodName, final IOException exception); static byte[] readFullyToByteArray(DataInput in); static final Logger LOG; }
@Test public void testWrapException() throws Exception { LambdaTestUtils.intercept(EOFException.class, "Failed with java.io.EOFException while processing file/directory " + ":[/tmp/abc.txt] in method:[testWrapException]", () -> { throw IOUtils.wrapException("/tmp/abc.txt", "testWrapException", new EOFException("EOFException ")); }); PathIOException returnedEx = LambdaTestUtils .intercept(PathIOException.class, "Input/output error:", () -> { throw IOUtils.wrapException("/tmp/abc.txt", "testWrapEx", new CharacterCodingException()); }); assertEquals("/tmp/abc.txt", returnedEx.getPath().toString()); }