public void cleanup() { for (int i=0; i < getNumFilesWritten(); i++) { File f = getFile(i); if (f.exists()) { if (!f.delete()) { LogFactory.getLog(getClass()).debug( "Ignoring failure to delete file " + f); } } } }
@Override public void close() throws IOException { if (closed) return; closed = true; if (os != null) { os.close(); File lastPart = getFile(filesCreated); if (lastPart.length() == 0) { if (!lastPart.delete()) { LogFactory.getLog(getClass()).debug( "Ignoring failure to delete empty file " + lastPart); } } else { // notify about the new file ready for processing observer.onPartCreate(new PartCreationEvent( getFile(filesCreated), filesCreated, true, this)); } } }
/** * Returns the file output stream to be used for writing, blocking if * necessary if running out of disk space. * * @throws InterruptedException if the running thread was interrupted */ private FileOutputStream fos() throws IOException { if (closed) throw new IOException("Output stream is already closed"); if (os == null || currFileBytesWritten >= partSize) { if (os != null) { os.close(); // notify about the new file ready for processing observer.onPartCreate(new PartCreationEvent( getFile(filesCreated), filesCreated, false, this)); } currFileBytesWritten = 0; filesCreated++; blockIfNecessary(); final File file = getFile(filesCreated); os = new FileOutputStream(file); } return os; }
/** * Deletes files. */ public void cleanup() { for (int i = 0; i < getNumFilesWritten(); i++) { final File f = getFile(i); if (f.exists()) { if (!f.delete()) { LogFactory.getLog(getClass()).debug( "Ignoring failure to delete file " + f); } } } }
@Override public void close() throws IOException { if (closed) { return; } closed = true; if (os != null) { os.close(); final File lastPart = getFile(filesCreated); if (lastPart.length() == 0) { if (!lastPart.delete()) { LogFactory.getLog(getClass()).debug( "Ignoring failure to delete empty file " + lastPart); } } else { // notify about the new file ready for processing observer.onPartCreate(new PartCreationEvent( getFile(filesCreated), filesCreated, true, this)); } } }
/** * Returns the file output stream to be used for writing, blocking if * necessary if running out of disk space. * * @throws InterruptedException if the running thread was interrupted */ private FileOutputStream fos() throws IOException { if (closed) { throw new IOException("Output stream is already closed"); } if (os == null || currFileBytesWritten >= partSize) { if (os != null) { os.close(); // notify about the new file ready for processing observer.onPartCreate(new PartCreationEvent( getFile(filesCreated), filesCreated, false, this)); } currFileBytesWritten = 0; filesCreated++; blockIfNecessary(); final File file = getFile(filesCreated); file.deleteOnExit(); os = new FileOutputStream(file); } return os; }
@Test public void testRead() throws IOException { mfos.init(Mockito.mock(UploadObjectObserver.class), 100, Long.MAX_VALUE); int count = 0; while (count < 10000) { mfos.write(count); count++; } Assert.assertNotNull(mfos.getFile(2)); Assert.assertEquals(mfos.getNumFilesWritten(), 100); }
@Test public void testRead2() throws IOException { mfos.init(Mockito.mock(UploadObjectObserver.class), 100, Long.MAX_VALUE); mfos.cleanup(); mfos.flush(); int count = 0; while (count < 200) { final byte[] b = new byte[50]; new Random().nextBytes(b); mfos.write(b); count++; } Assert.assertNotNull(mfos.getFile(2)); Assert.assertEquals(mfos.getNumFilesWritten(), 100); }
@Test public void testRead3() throws IOException { mfos.init(Mockito.mock(UploadObjectObserver.class), 100, Long.MAX_VALUE); mfos.cleanup(); int count = 0; while (count < 200) { final byte[] b = new byte[50]; new Random().nextBytes(b); mfos.write(b, 0, 50); count++; } Assert.assertNotNull(mfos.getFile(2)); Assert.assertEquals(mfos.getNumFilesWritten(), 100); Assert.assertEquals(mfos.getPartSize(), 100); Assert.assertNotNull(mfos.getNamePrefix()); Assert.assertEquals(mfos.getDiskLimit(), Long.MAX_VALUE); Assert.assertEquals(mfos.getTotalBytesWritten(), 10000); Assert.assertNotNull(mfos.getRoot()); }
public void cleanup() { for (int i=0; i < getNumFilesWritten(); i++) { File f = getFile(i); if (f.exists()) { if (!f.delete()) { LogFactory.getLog(getClass()).debug( "Ignoring failure to delete file " + f); } } } }
@Override public void close() throws IOException { if (closed) return; closed = true; if (os != null) { os.close(); File lastPart = getFile(filesCreated); if (lastPart.length() == 0) { if (!lastPart.delete()) { LogFactory.getLog(getClass()).debug( "Ignoring failure to delete empty file " + lastPart); } } else { // notify about the new file ready for processing observer.onPartCreate(new PartCreationEvent( getFile(filesCreated), filesCreated, true, this)); } } }
/** * Deletes files. */ public void cleanup() { for (int i = 0; i < getNumFilesWritten(); i++) { final File f = getFile(i); if (f.exists()) { if (!f.delete()) { LogFactory.getLog(getClass()).debug( "Ignoring failure to delete file " + f); } } } }
@Override public void close() throws IOException { if (closed) { return; } closed = true; if (os != null) { os.close(); final File lastPart = getFile(filesCreated); if (lastPart.length() == 0) { if (!lastPart.delete()) { LogFactory.getLog(getClass()).debug( "Ignoring failure to delete empty file " + lastPart); } } else { // notify about the new file ready for processing observer.onPartCreate(new PartCreationEvent( getFile(filesCreated), filesCreated, true, this)); } } }
/** * Returns the file output stream to be used for writing, blocking if * necessary if running out of disk space. * * @throws InterruptedException if the running thread was interrupted */ private FileOutputStream fos() throws IOException { if (closed) throw new IOException("Output stream is already closed"); if (os == null || currFileBytesWritten >= partSize) { if (os != null) { os.close(); // notify about the new file ready for processing observer.onPartCreate(new PartCreationEvent( getFile(filesCreated), filesCreated, false, this)); } currFileBytesWritten = 0; filesCreated++; blockIfNecessary(); final File file = getFile(filesCreated); os = new FileOutputStream(file); } return os; }
/** * Returns the file output stream to be used for writing, blocking if * necessary if running out of disk space. * * @throws InterruptedException if the running thread was interrupted */ private FileOutputStream fos() throws IOException { if (closed) { throw new IOException("Output stream is already closed"); } if (os == null || currFileBytesWritten >= partSize) { if (os != null) { os.close(); // notify about the new file ready for processing observer.onPartCreate(new PartCreationEvent( getFile(filesCreated), filesCreated, false, this)); } currFileBytesWritten = 0; filesCreated++; blockIfNecessary(); final File file = getFile(filesCreated); file.deleteOnExit(); os = new FileOutputStream(file); } return os; }