@Test public void consumeData() throws IOException { try(OutputStream os = Files.newOutputStream(file1)) { IOUtils.write("abcdefghijkl", os, "ASCII"); } StringResult result = new StringResult(); fsStorage.consumeData(file1Asset, is -> consume(is, result), false ); Assert.assertEquals("abcdefghijkl" ,result.getData()); }
@Override public void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ) throws IOException { final Path path = asset.getFilePath(); try { if (readLock) { consumeDataLocked( path, consumerFunction ); } else { try ( InputStream is = Files.newInputStream( path ) ) { consumerFunction.accept( is ); } catch ( IOException e ) { log.error("Could not read the input stream from file {}", path); throw e; } } } catch (RuntimeException e) { log.error( "Runtime exception during data consume from artifact {}. Error: {}", path, e.getMessage() ); throw new IOException( e ); } }
FilesystemStorage implements RepositoryStorage { @Override public void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ) throws IOException { final Path path = asset.getFilePath(); try { if (readLock) { consumeDataLocked( path, consumerFunction ); } else { try ( InputStream is = Files.newInputStream( path ) ) { consumerFunction.accept( is ); } catch ( IOException e ) { log.error("Could not read the input stream from file {}", path); throw e; } } } catch (RuntimeException e) { log.error( "Runtime exception during data consume from artifact {}. Error: {}", path, e.getMessage() ); throw new IOException( e ); } } }
FilesystemStorage implements RepositoryStorage { @Override public void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ) throws IOException { final Path path = asset.getFilePath(); try { if (readLock) { consumeDataLocked( path, consumerFunction ); } else { try ( InputStream is = Files.newInputStream( path ) ) { consumerFunction.accept( is ); } catch ( IOException e ) { log.error("Could not read the input stream from file {}", path); throw e; } } } catch (RuntimeException e) { log.error( "Runtime exception during data consume from artifact {}. Error: {}", path, e.getMessage() ); throw new IOException( e ); } } FilesystemStorage(Path basePath, FileLockManager fileLockManager); }
FilesystemStorage implements RepositoryStorage { @Override public void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ) throws IOException { final Path path = asset.getFilePath(); try { if (readLock) { consumeDataLocked( path, consumerFunction ); } else { try ( InputStream is = Files.newInputStream( path ) ) { consumerFunction.accept( is ); } catch ( IOException e ) { log.error("Could not read the input stream from file {}", path); throw e; } } } catch (RuntimeException e) { log.error( "Runtime exception during data consume from artifact {}. Error: {}", path, e.getMessage() ); throw new IOException( e ); } } FilesystemStorage(Path basePath, FileLockManager fileLockManager); @Override void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ); @Override void consumeDataFromChannel( StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock ); @Override void writeData( StorageAsset asset, Consumer<OutputStream> consumerFunction, boolean writeLock ); @Override void writeDataToChannel( StorageAsset asset, Consumer<WritableByteChannel> consumerFunction, boolean writeLock ); @Override URI getLocation(); @Override void updateLocation(URI newLocation); @Override StorageAsset getAsset( String path ); @Override StorageAsset getRoot( ); @Override StorageAsset addAsset( String path, boolean container ); @Override void removeAsset( StorageAsset asset ); @Override StorageAsset moveAsset( StorageAsset origin, String destination, CopyOption... copyOptions ); @Override void moveAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions ); @Override StorageAsset copyAsset( StorageAsset origin, String destination, CopyOption... copyOptions ); @Override void copyAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions ); FileLockManager getFileLockManager(); }
FilesystemStorage implements RepositoryStorage { @Override public void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ) throws IOException { final Path path = asset.getFilePath(); try { if (readLock) { consumeDataLocked( path, consumerFunction ); } else { try ( InputStream is = Files.newInputStream( path ) ) { consumerFunction.accept( is ); } catch ( IOException e ) { log.error("Could not read the input stream from file {}", path); throw e; } } } catch (RuntimeException e) { log.error( "Runtime exception during data consume from artifact {}. Error: {}", path, e.getMessage() ); throw new IOException( e ); } } FilesystemStorage(Path basePath, FileLockManager fileLockManager); @Override void consumeData( StorageAsset asset, Consumer<InputStream> consumerFunction, boolean readLock ); @Override void consumeDataFromChannel( StorageAsset asset, Consumer<ReadableByteChannel> consumerFunction, boolean readLock ); @Override void writeData( StorageAsset asset, Consumer<OutputStream> consumerFunction, boolean writeLock ); @Override void writeDataToChannel( StorageAsset asset, Consumer<WritableByteChannel> consumerFunction, boolean writeLock ); @Override URI getLocation(); @Override void updateLocation(URI newLocation); @Override StorageAsset getAsset( String path ); @Override StorageAsset getRoot( ); @Override StorageAsset addAsset( String path, boolean container ); @Override void removeAsset( StorageAsset asset ); @Override StorageAsset moveAsset( StorageAsset origin, String destination, CopyOption... copyOptions ); @Override void moveAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions ); @Override StorageAsset copyAsset( StorageAsset origin, String destination, CopyOption... copyOptions ); @Override void copyAsset( StorageAsset origin, StorageAsset destination, CopyOption... copyOptions ); FileLockManager getFileLockManager();  }