@Test @PrepareForTest(KodoOutputStream.class) public void testClose() throws Exception { PowerMockito.whenNew(File.class).withArguments(Mockito.anyString()).thenReturn(mFile); FileOutputStream outputStream = PowerMockito.mock(FileOutputStream.class); PowerMockito.whenNew(FileOutputStream.class).withArguments(mFile).thenReturn(outputStream); FileInputStream inputStream = PowerMockito.mock(FileInputStream.class); PowerMockito.whenNew(FileInputStream.class).withArguments(mFile).thenReturn(inputStream); KodoOutputStream stream = new KodoOutputStream("testKey", mKodoClient, sTmpDirs); stream.close(); Mockito.verify(mFile).delete(); }
@Override public void close() { if (mClosed.getAndSet(true)) { return; } try { mLocalOutputStream.close(); mKodoClient.uploadFile(mKey, mFile); } catch (Exception e) { LOG.error("Failed to upload {}.", mKey, e); } finally { if (!mFile.delete()) { LOG.error("Failed to delete temporary file @ {}", mFile.getPath()); } } }
KodoOutputStream extends OutputStream { @Override public void close() { if (mClosed.getAndSet(true)) { return; } try { mLocalOutputStream.close(); mKodoClient.uploadFile(mKey, mFile); } catch (Exception e) { LOG.error("Failed to upload {}.", mKey, e); } finally { if (!mFile.delete()) { LOG.error("Failed to delete temporary file @ {}", mFile.getPath()); } } } }
KodoOutputStream extends OutputStream { @Override public void close() { if (mClosed.getAndSet(true)) { return; } try { mLocalOutputStream.close(); mKodoClient.uploadFile(mKey, mFile); } catch (Exception e) { LOG.error("Failed to upload {}.", mKey, e); } finally { if (!mFile.delete()) { LOG.error("Failed to delete temporary file @ {}", mFile.getPath()); } } } KodoOutputStream(String key, KodoClient kodoClient, List<String> tmpDirs); }
KodoOutputStream extends OutputStream { @Override public void close() { if (mClosed.getAndSet(true)) { return; } try { mLocalOutputStream.close(); mKodoClient.uploadFile(mKey, mFile); } catch (Exception e) { LOG.error("Failed to upload {}.", mKey, e); } finally { if (!mFile.delete()) { LOG.error("Failed to delete temporary file @ {}", mFile.getPath()); } } } KodoOutputStream(String key, KodoClient kodoClient, List<String> tmpDirs); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); @Override void flush(); @Override void close(); }
KodoOutputStream extends OutputStream { @Override public void close() { if (mClosed.getAndSet(true)) { return; } try { mLocalOutputStream.close(); mKodoClient.uploadFile(mKey, mFile); } catch (Exception e) { LOG.error("Failed to upload {}.", mKey, e); } finally { if (!mFile.delete()) { LOG.error("Failed to delete temporary file @ {}", mFile.getPath()); } } } KodoOutputStream(String key, KodoClient kodoClient, List<String> tmpDirs); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); @Override void flush(); @Override void close();  }