/** * Calls {@link #close} if not already closed, and then resets this object back to its initial * state, for reuse. If data was buffered to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
/** * Calls {@link #close} if not already closed, and then resets this object back to its initial * state, for reuse. If data was buffered to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
/** * Calls {@link #close} if not already closed, and then resets this object back to its initial * state, for reuse. If data was buffered to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
public void testFinalizeDeletesFile() throws Exception { byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(0, true); write(out, data, 0, 100, true); final File file = out.getFile(); assertEquals(100, file.length()); assertTrue(file.exists()); out.close(); // Make sure that finalize deletes the file out = null; // times out and throws RuntimeException on failure GcFinalization.awaitDone( new GcFinalization.FinalizationPredicate() { @Override public boolean isDone() { return !file.exists(); } }); }
public void testReset() throws Exception { byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(Integer.MAX_VALUE); ByteSource source = out.asByteSource(); out.write(data); assertTrue(Arrays.equals(data, source.read())); out.reset(); assertTrue(Arrays.equals(new byte[0], source.read())); out.write(data); assertTrue(Arrays.equals(data, source.read())); out.close(); } }
public void testWriteErrorAfterClose() throws Exception { byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(50); ByteSource source = out.asByteSource(); out.write(data); assertTrue(Arrays.equals(data, source.read())); out.close(); try { out.write(42); fail("expected exception"); } catch (IOException expected) { } // Verify that write had no effect assertTrue(Arrays.equals(data, source.read())); out.reset(); }
assertTrue(file.exists()); out.close();
@Override public void close() throws IOException { if (isClosed) { return; } try { fileBackedOutputStream.close(); reset(); } finally { isClosed = true; } }
@Override public void close() throws IOException { if (this.subEntryOutputStream != null) { this.subEntryOutputStream.reset(); this.subEntryOutputStream.close(); this.subEntryOutputStream = null; } if (this.entryOutputStream != null) { this.entryOutputStream.reset(); this.entryOutputStream.close(); this.entryOutputStream = null; } } }
@Override public void close() throws IOException { if (this.subEntryOutputStream != null) { this.subEntryOutputStream.reset(); this.subEntryOutputStream.close(); this.subEntryOutputStream = null; } if (this.entryOutputStream != null) { this.entryOutputStream.reset(); this.entryOutputStream.close(); this.entryOutputStream = null; } } }
/** * Calls {@link #close} if not already closed, and then resets this * object back to its initial state, for reuse. If data was buffered * to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
/** * Calls {@link #close} if not already closed, and then resets this * object back to its initial state, for reuse. If data was buffered * to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
/** * Calls {@link #close} if not already closed, and then resets this * object back to its initial state, for reuse. If data was buffered * to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
/** * Calls {@link #close} if not already closed, and then resets this * object back to its initial state, for reuse. If data was buffered * to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
/** * Calls {@link #close} if not already closed, and then resets this * object back to its initial state, for reuse. If data was buffered * to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
/** * Calls {@link #close} if not already closed, and then resets this * object back to its initial state, for reuse. If data was buffered * to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
/** * Calls {@link #close} if not already closed, and then resets this object back to its initial * state, for reuse. If data was buffered to a file, it will be deleted. * * @throws IOException if an I/O error occurred while deleting the file buffer */ public synchronized void reset() throws IOException { try { close(); } finally { if (memory == null) { memory = new MemoryOutput(); } else { memory.reset(); } out = memory; if (file != null) { File deleteMe = file; file = null; if (!deleteMe.delete()) { throw new IOException("Could not delete: " + deleteMe); } } } }
public void testFinalizeDeletesFile() throws Exception { byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(0, true); write(out, data, 0, 100, true); final File file = out.getFile(); assertEquals(100, file.length()); assertTrue(file.exists()); out.close(); // Make sure that finalize deletes the file out = null; // times out and throws RuntimeException on failure GcFinalization.awaitDone(new GcFinalization.FinalizationPredicate() { @Override public boolean isDone() { return !file.exists(); } }); }
public void testReset() throws Exception { byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(Integer.MAX_VALUE); ByteSource source = out.asByteSource(); out.write(data); assertTrue(Arrays.equals(data, source.read())); out.reset(); assertTrue(Arrays.equals(new byte[0], source.read())); out.write(data); assertTrue(Arrays.equals(data, source.read())); out.close(); } }
public void testWriteErrorAfterClose() throws Exception { byte[] data = newPreFilledByteArray(100); FileBackedOutputStream out = new FileBackedOutputStream(50); ByteSource source = out.asByteSource(); out.write(data); assertTrue(Arrays.equals(data, source.read())); out.close(); try { out.write(42); fail("expected exception"); } catch (IOException expected) { } // Verify that write had no effect assertTrue(Arrays.equals(data, source.read())); out.reset(); }