@Test @SneakyThrows void write() { try (OutputStream os = storageService.write(WithCallback.noCallback(fileWithMsg))) { os.write(MESSAGE.getBytes()); } try (InputStream read = storageService.read(fileWithMsg)) { assertThat(read).hasContent(MESSAGE); } }
@SneakyThrows @Override public OutputStream write(WithCallback<AbsoluteLocation, ? extends ResourceWriteCallback> locationWithCallback) { log.debug("Write file request: {}", locationWithCallback.getWrapped().location()); Path filePath = resolve(locationWithCallback.getWrapped().location().getRawPath(), true); log.debug("Write file: {}", locationWithCallback.getWrapped().location()); return MoreFiles .asByteSink(filePath, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE) .openStream(); }
FileSystemStorageService implements StorageService { @SneakyThrows @Override public OutputStream write(WithCallback<AbsoluteLocation, ? extends ResourceWriteCallback> locationWithCallback) { log.debug("Write file request: {}", locationWithCallback.getWrapped().location()); Path filePath = resolve(locationWithCallback.getWrapped().location().getRawPath(), true); log.debug("Write file: {}", locationWithCallback.getWrapped().location()); return MoreFiles .asByteSink(filePath, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE) .openStream(); } }
FileSystemStorageService implements StorageService { @SneakyThrows @Override public OutputStream write(WithCallback<AbsoluteLocation, ? extends ResourceWriteCallback> locationWithCallback) { log.debug("Write file request: {}", locationWithCallback.getWrapped().location()); Path filePath = resolve(locationWithCallback.getWrapped().location().getRawPath(), true); log.debug("Write file: {}", locationWithCallback.getWrapped().location()); return MoreFiles .asByteSink(filePath, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE) .openStream(); } FileSystemStorageService(Path dir); }
FileSystemStorageService implements StorageService { @SneakyThrows @Override public OutputStream write(WithCallback<AbsoluteLocation, ? extends ResourceWriteCallback> locationWithCallback) { log.debug("Write file request: {}", locationWithCallback.getWrapped().location()); Path filePath = resolve(locationWithCallback.getWrapped().location().getRawPath(), true); log.debug("Write file: {}", locationWithCallback.getWrapped().location()); return MoreFiles .asByteSink(filePath, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE) .openStream(); } FileSystemStorageService(Path dir); @SneakyThrows @Override Stream<AbsoluteLocation<ResolvedResource>> list(AbsoluteLocation path); @SneakyThrows @Override InputStream read(AbsoluteLocation path); @SneakyThrows @Override OutputStream write(WithCallback<AbsoluteLocation, ? extends ResourceWriteCallback> locationWithCallback); @SneakyThrows @Override void remove(AbsoluteLocation location); @Override boolean objectExists(AbsoluteLocation location); }
FileSystemStorageService implements StorageService { @SneakyThrows @Override public OutputStream write(WithCallback<AbsoluteLocation, ? extends ResourceWriteCallback> locationWithCallback) { log.debug("Write file request: {}", locationWithCallback.getWrapped().location()); Path filePath = resolve(locationWithCallback.getWrapped().location().getRawPath(), true); log.debug("Write file: {}", locationWithCallback.getWrapped().location()); return MoreFiles .asByteSink(filePath, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE) .openStream(); } FileSystemStorageService(Path dir); @SneakyThrows @Override Stream<AbsoluteLocation<ResolvedResource>> list(AbsoluteLocation path); @SneakyThrows @Override InputStream read(AbsoluteLocation path); @SneakyThrows @Override OutputStream write(WithCallback<AbsoluteLocation, ? extends ResourceWriteCallback> locationWithCallback); @SneakyThrows @Override void remove(AbsoluteLocation location); @Override boolean objectExists(AbsoluteLocation location);  }