bruno-roustant commented on a change in pull request #108: URL: https://github.com/apache/solr/pull/108#discussion_r650928808
########## File path: solr/contrib/blob-directory/src/java/org/apache/solr/blob/BlobStoreConnection.java ########## @@ -152,11 +180,66 @@ private void createDirectories(URI blobDirUri, String blobDirPath) throws IOExce } } + private void copyStream(IndexInput input, OutputStream output) throws IOException { + byte[] buffer = streamBuffers.get(); + long remaining = input.length(); + while (remaining > 0) { + int length = (int) Math.min(buffer.length, remaining); + input.readBytes(buffer, 0, length, false); + output.write(buffer, 0, length); + remaining -= length; + } + } + private void deleteFiles(String blobDirPath, Collection<String> fileNames) throws IOException { URI blobDirUri = repository.resolve(repositoryLocation, blobDirPath); repository.delete(blobDirUri, fileNames, true); } + /** + * Lists the files in a specific directory of the repository and select them with the provided filter. + */ + private List<BlobFile> list(URI blobDirUri, BlobFileFilter fileFilter) throws IOException { + String[] fileNames = repository.listAll(blobDirUri); + List<BlobFile> blobFiles = new ArrayList<>(fileNames.length); + for (String fileName : fileNames) { + BlobFile blobFile = new BlobFile(fileName, -1, -1); + if (fileFilter.accept(blobFile)) { + blobFiles.add(blobFile); + } + } + return blobFiles; + } + + private List<Callable<Void>> pullFiles( + URI blobDirUri, + Collection<BlobFile> blobFiles, + IOUtils.IOFunction<BlobFile, IndexOutput> outputSupplier) { + return blobFiles.stream() + .map( + (blobFile) -> + (Callable<Void>) + () -> { + try (IndexInput in = repository.openInput(blobDirUri, blobFile.fileName(), IOContext.READ); + IndexOutput out = outputSupplier.apply(blobFile)) { + copyStream(in, out); + } + return null; + }) + .collect(Collectors.toList()); + } + + private void copyStream(IndexInput input, IndexOutput output) throws IOException { Review comment: The second parameter is different: IndexOutput (when writing locally) and OutputStream (when writing remotely). But I'll change with a small interface BytesWriter to have a common method. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org