boolean triedToClose = false, success = false; try { flush(); ((FileOutputStream) out).getFD().sync();
boolean triedToClose = false, success = false; try { flush(); ((FileOutputStream) out).getChannel().force(true);
bw.flush(); out.flush();
bw.flush(); out.flush(); } catch (IOException e) { LOG.error("Failed to write new file " + file, e);
/** * Ensure the tmp file is cleaned up and dstFile is not created when * aborting a new file. */ @Test public void testAbortNewFileAfterFlush() throws IOException { AtomicFileOutputStream fos = new AtomicFileOutputStream(dstFile); fos.write(TEST_STRING.getBytes()); fos.flush(); fos.abort(); assertEquals(0, testDir.list().length); }
/** * Ensure the tmp file is cleaned up and dstFile is untouched when * aborting an existing file overwrite. */ @Test public void testAbortExistingFileAfterFlush() throws IOException { FileOutputStream fos1 = new FileOutputStream(dstFile); fos1.write(TEST_STRING.getBytes()); fos1.close(); AtomicFileOutputStream fos2 = new AtomicFileOutputStream(dstFile); fos2.write(TEST_STRING_2.getBytes()); fos2.flush(); fos2.abort(); // Should not have touched original file assertEquals(TEST_STRING, ClientBase.readFile(dstFile)); assertEquals(1, testDir.list().length); } }
bw.flush(); out.flush(); } catch (IOException e) { LOG.error("Failed to write new file " + file, e);