@Test public void testWriteFile() throws Exception { BasicFileStorage basicFileStorage = new BasicFileStorage(temporaryFolder.getRoot().getAbsolutePath()); byte[] data = "data".getBytes(); String storageId = basicFileStorage.writeFile(CONTAINER, OBJ_1, new ByteArrayInputStream(data), data.length); assertThat(new File(temporaryFolder.getRoot(), "/container/" + storageId)).hasBinaryContent(data); }
public String writeFile(String containerName, String objectName, InputStream inputStream, long size) throws IOException { ensureContainerExists(containerName); String storageId = LocalFileUtils.createStorageId(objectName); Path filePath = getFilePath(containerName, storageId); try (ExtendedFileOutputStream outputStream = new ExtendedFileOutputStream(filePath, true)) { ExactSizeInputStream exactSizeInputStream = new ExactSizeInputStream(inputStream, size); IOUtils.copy(exactSizeInputStream, outputStream); return storageId; } catch (IOException ex) { deleteFile(containerName, storageId); throw ex; } finally { IOUtils.closeQuietly(inputStream); } }
BasicFileStorage { public String writeFile(String containerName, String objectName, InputStream inputStream, long size) throws IOException { ensureContainerExists(containerName); String storageId = LocalFileUtils.createStorageId(objectName); Path filePath = getFilePath(containerName, storageId); try (ExtendedFileOutputStream outputStream = new ExtendedFileOutputStream(filePath, true)) { ExactSizeInputStream exactSizeInputStream = new ExactSizeInputStream(inputStream, size); IOUtils.copy(exactSizeInputStream, outputStream); return storageId; } catch (IOException ex) { deleteFile(containerName, storageId); throw ex; } finally { IOUtils.closeQuietly(inputStream); } } }
BasicFileStorage { public String writeFile(String containerName, String objectName, InputStream inputStream, long size) throws IOException { ensureContainerExists(containerName); String storageId = LocalFileUtils.createStorageId(objectName); Path filePath = getFilePath(containerName, storageId); try (ExtendedFileOutputStream outputStream = new ExtendedFileOutputStream(filePath, true)) { ExactSizeInputStream exactSizeInputStream = new ExactSizeInputStream(inputStream, size); IOUtils.copy(exactSizeInputStream, outputStream); return storageId; } catch (IOException ex) { deleteFile(containerName, storageId); throw ex; } finally { IOUtils.closeQuietly(inputStream); } } BasicFileStorage(String basePath); }
BasicFileStorage { public String writeFile(String containerName, String objectName, InputStream inputStream, long size) throws IOException { ensureContainerExists(containerName); String storageId = LocalFileUtils.createStorageId(objectName); Path filePath = getFilePath(containerName, storageId); try (ExtendedFileOutputStream outputStream = new ExtendedFileOutputStream(filePath, true)) { ExactSizeInputStream exactSizeInputStream = new ExactSizeInputStream(inputStream, size); IOUtils.copy(exactSizeInputStream, outputStream); return storageId; } catch (IOException ex) { deleteFile(containerName, storageId); throw ex; } finally { IOUtils.closeQuietly(inputStream); } } BasicFileStorage(String basePath); String writeFile(String containerName, String objectName, InputStream inputStream, long size); InputStream readFile(String containerName, String storageId); void deleteFile(String containerName, String storageId); Stream<String> listStorageIdsByContainerName(String containerName); }
BasicFileStorage { public String writeFile(String containerName, String objectName, InputStream inputStream, long size) throws IOException { ensureContainerExists(containerName); String storageId = LocalFileUtils.createStorageId(objectName); Path filePath = getFilePath(containerName, storageId); try (ExtendedFileOutputStream outputStream = new ExtendedFileOutputStream(filePath, true)) { ExactSizeInputStream exactSizeInputStream = new ExactSizeInputStream(inputStream, size); IOUtils.copy(exactSizeInputStream, outputStream); return storageId; } catch (IOException ex) { deleteFile(containerName, storageId); throw ex; } finally { IOUtils.closeQuietly(inputStream); } } BasicFileStorage(String basePath); String writeFile(String containerName, String objectName, InputStream inputStream, long size); InputStream readFile(String containerName, String storageId); void deleteFile(String containerName, String storageId); Stream<String> listStorageIdsByContainerName(String containerName);  }