@Test @SuppressWarnings({"unused", "UnusedAssignment"}) public void copy() throws IOException { File a = File.createTempFile("file-1", "tmp"); File b = File.createTempFile("file-2", "tmp"); Assert.assertTrue(a.isFile()); Assert.assertTrue(b.isFile()); try { FileUtils.write(a, "Hello world".getBytes("UTF-8")); FileUtils.copy(a, b); byte[] data = FileUtils.readAllBytes(b); Assert.assertNotNull(data); String s = new String(data, "UTF-8"); Assert.assertEquals("Hello world", s); } finally { boolean ignored = a.delete(); ignored = b.delete(); } }
@SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") public static void copy(File src, File dest) throws IOException { if (dest.delete()) { LOGGER.debug("Removed " + dest.getPath() + " during copying"); } InputStream input = null; FileOutputStream output = null; try { input = new FileInputStream(src); output = new FileOutputStream(dest); byte[] buf = new byte[1024]; int read; while ((read = input.read(buf)) > 0) { output.write(buf, 0, read); } output.flush(); try { output.getFD().sync(); } catch (SyncFailedException ignored) { } } finally { try { if (input != null) { input.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } try { if (output != null) { output.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } } }
FileUtils { @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") public static void copy(File src, File dest) throws IOException { if (dest.delete()) { LOGGER.debug("Removed " + dest.getPath() + " during copying"); } InputStream input = null; FileOutputStream output = null; try { input = new FileInputStream(src); output = new FileOutputStream(dest); byte[] buf = new byte[1024]; int read; while ((read = input.read(buf)) > 0) { output.write(buf, 0, read); } output.flush(); try { output.getFD().sync(); } catch (SyncFailedException ignored) { } } finally { try { if (input != null) { input.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } try { if (output != null) { output.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } } } }
FileUtils { @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") public static void copy(File src, File dest) throws IOException { if (dest.delete()) { LOGGER.debug("Removed " + dest.getPath() + " during copying"); } InputStream input = null; FileOutputStream output = null; try { input = new FileInputStream(src); output = new FileOutputStream(dest); byte[] buf = new byte[1024]; int read; while ((read = input.read(buf)) > 0) { output.write(buf, 0, read); } output.flush(); try { output.getFD().sync(); } catch (SyncFailedException ignored) { } } finally { try { if (input != null) { input.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } try { if (output != null) { output.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } } }  }
FileUtils { @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") public static void copy(File src, File dest) throws IOException { if (dest.delete()) { LOGGER.debug("Removed " + dest.getPath() + " during copying"); } InputStream input = null; FileOutputStream output = null; try { input = new FileInputStream(src); output = new FileOutputStream(dest); byte[] buf = new byte[1024]; int read; while ((read = input.read(buf)) > 0) { output.write(buf, 0, read); } output.flush(); try { output.getFD().sync(); } catch (SyncFailedException ignored) { } } finally { try { if (input != null) { input.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } try { if (output != null) { output.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } } }  static byte[] readAllBytes(File src); static void write(File path, byte[] bytes); @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") static void copy(File src, File dest); }
FileUtils { @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") public static void copy(File src, File dest) throws IOException { if (dest.delete()) { LOGGER.debug("Removed " + dest.getPath() + " during copying"); } InputStream input = null; FileOutputStream output = null; try { input = new FileInputStream(src); output = new FileOutputStream(dest); byte[] buf = new byte[1024]; int read; while ((read = input.read(buf)) > 0) { output.write(buf, 0, read); } output.flush(); try { output.getFD().sync(); } catch (SyncFailedException ignored) { } } finally { try { if (input != null) { input.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } try { if (output != null) { output.close(); } } catch (IOException e) { if (LOGGER.isDebugEnabled()) { StringWriter writer = new StringWriter(); e.printStackTrace(new PrintWriter(writer)); LOGGER.debug(writer.toString()); } } } }  static byte[] readAllBytes(File src); static void write(File path, byte[] bytes); @SuppressFBWarnings("OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE") static void copy(File src, File dest);  }