@Test public void testAddStream() throws IOException, CancelledException { FileCache cache = new FileCache(cacheDir); FileCacheEntry fce = cache.addStream(toIS("This is a test1"), monitor); Assert.assertTrue(fce.file.exists()); Assert.assertEquals("10428da10f5aa2793cb73c0b680e1621", fce.md5); Assert.assertEquals(1, cache.getFileAddCount()); }
public FileCacheEntry addStream(InputStream is, TaskMonitor monitor) throws IOException, CancelledException { File tmpFile = new File(newDir, UUID.randomUUID().toString()); try (FileOutputStream fos = new FileOutputStream(tmpFile)) { StreamCopyResult copyResults = FSUtilities.streamCopy(is, fos, monitor); fos.close(); String md5 = NumericUtilities.convertBytesToString(copyResults.md5); return addTmpFileToCache(tmpFile, md5, copyResults.bytesCopied); } finally { if (tmpFile.exists()) { Msg.debug(this, "Removing left-over temp file " + tmpFile); tmpFile.delete(); } } }
FileCache { public FileCacheEntry addStream(InputStream is, TaskMonitor monitor) throws IOException, CancelledException { File tmpFile = new File(newDir, UUID.randomUUID().toString()); try (FileOutputStream fos = new FileOutputStream(tmpFile)) { StreamCopyResult copyResults = FSUtilities.streamCopy(is, fos, monitor); fos.close(); String md5 = NumericUtilities.convertBytesToString(copyResults.md5); return addTmpFileToCache(tmpFile, md5, copyResults.bytesCopied); } finally { if (tmpFile.exists()) { Msg.debug(this, "Removing left-over temp file " + tmpFile); tmpFile.delete(); } } } }
FileCache { public FileCacheEntry addStream(InputStream is, TaskMonitor monitor) throws IOException, CancelledException { File tmpFile = new File(newDir, UUID.randomUUID().toString()); try (FileOutputStream fos = new FileOutputStream(tmpFile)) { StreamCopyResult copyResults = FSUtilities.streamCopy(is, fos, monitor); fos.close(); String md5 = NumericUtilities.convertBytesToString(copyResults.md5); return addTmpFileToCache(tmpFile, md5, copyResults.bytesCopied); } finally { if (tmpFile.exists()) { Msg.debug(this, "Removing left-over temp file " + tmpFile); tmpFile.delete(); } } } FileCache(File cacheDir); }
FileCache { public FileCacheEntry addStream(InputStream is, TaskMonitor monitor) throws IOException, CancelledException { File tmpFile = new File(newDir, UUID.randomUUID().toString()); try (FileOutputStream fos = new FileOutputStream(tmpFile)) { StreamCopyResult copyResults = FSUtilities.streamCopy(is, fos, monitor); fos.close(); String md5 = NumericUtilities.convertBytesToString(copyResults.md5); return addTmpFileToCache(tmpFile, md5, copyResults.bytesCopied); } finally { if (tmpFile.exists()) { Msg.debug(this, "Removing left-over temp file " + tmpFile); tmpFile.delete(); } } } FileCache(File cacheDir); synchronized void purge(); FileCacheEntry addFile(File f, TaskMonitor monitor); FileCacheEntry getFile(String md5); FileCacheEntry addStream(InputStream is, TaskMonitor monitor); FileCacheEntry pushStream(DerivedFilePushProducer pusher, TaskMonitor monitor); @Override String toString(); int getFileAddCount(); int getFileReUseCount(); long getStorageEstimateBytes(); long getMaxFileAgeMS(); }
FileCache { public FileCacheEntry addStream(InputStream is, TaskMonitor monitor) throws IOException, CancelledException { File tmpFile = new File(newDir, UUID.randomUUID().toString()); try (FileOutputStream fos = new FileOutputStream(tmpFile)) { StreamCopyResult copyResults = FSUtilities.streamCopy(is, fos, monitor); fos.close(); String md5 = NumericUtilities.convertBytesToString(copyResults.md5); return addTmpFileToCache(tmpFile, md5, copyResults.bytesCopied); } finally { if (tmpFile.exists()) { Msg.debug(this, "Removing left-over temp file " + tmpFile); tmpFile.delete(); } } } FileCache(File cacheDir); synchronized void purge(); FileCacheEntry addFile(File f, TaskMonitor monitor); FileCacheEntry getFile(String md5); FileCacheEntry addStream(InputStream is, TaskMonitor monitor); FileCacheEntry pushStream(DerivedFilePushProducer pusher, TaskMonitor monitor); @Override String toString(); int getFileAddCount(); int getFileReUseCount(); long getStorageEstimateBytes(); long getMaxFileAgeMS(); static final int MD5_HEXSTR_LEN; }