public InputStream copyFiles(String containerId, String folderName) { try { return dockerClient.archiveContainer(containerId, folderName); } catch (DockerException | InterruptedException e) { logger.warn(nodeId + " Something happened while copying the folder " + folderName + ", " + "most of the time it is an issue while closing the input/output stream, which is usually OK.", e); } return null; }
private static InputStream createReader( final DockerClient dockerClient, final Container container, final Path file) throws IOException { // Fetch the file from the container final InputStream fileArchiveStream; try { fileArchiveStream = dockerClient.archiveContainer(container.id(), file.toString()); } catch (final DockerException | InterruptedException e) { throw new IOException( String.format( "Docker client failed to archive file from container: %s", file), e); } // Create a buffered reader of the first file in the tar stream final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(fileArchiveStream); @Nullable final TarArchiveEntry tarArchive = tarInputStream.getNextTarEntry(); if (tarArchive == null || !tarArchive.isFile()) { throw new IOException( String.format( "Docker client return unsupported archive for: %s", file)); } return tarInputStream; } }