@Test @Tag("S3Test") public void testDeleteAllFilesInFolderExcept() { amazonS3.putObject(BUCKET_NAME, "_unittest/forMove/a.txt", "dummy"); amazonS3.putObject(BUCKET_NAME, "_unittest/forMove/b.txt", "dummy"); amazonS3.putObject(BUCKET_NAME, "_unittest/forMove/c.txt", "dummy"); amazonS3.putObject(BUCKET_NAME, "_unittest/forMove/d.txt", "dummy"); amazonS3.putObject(BUCKET_NAME, "_unittest/forMove/e.txt", "dummy"); handler.deleteAllFilesInFolderExcept(BUCKET_NAME, "_unittest/forMove", List.of("a.txt", "d.txt")); var objectSummaries = amazonS3.listObjects(BUCKET_NAME, "_unittest/forMove").getObjectSummaries(); assertThat(objectSummaries).hasSize(2) .extracting(S3ObjectSummary::getKey) .containsOnly("_unittest/forMove/a.txt", "_unittest/forMove/d.txt"); }
public void deleteAllFilesInFolderExcept(String bucketName, String folderPath, List<String> excludeList) { var searchPath = "s3: try { var files = resolver.getResources(searchPath); for (var file : files) { var shortFileName = new File(file.getFilename()).getName(); if (!excludeList.contains(shortFileName)) { deleteFile(bucketName, file.getFilename()); } } } catch (IOException e) { throw new RuntimeException(e); } }
S3FileHandler { public void deleteAllFilesInFolderExcept(String bucketName, String folderPath, List<String> excludeList) { var searchPath = "s3: try { var files = resolver.getResources(searchPath); for (var file : files) { var shortFileName = new File(file.getFilename()).getName(); if (!excludeList.contains(shortFileName)) { deleteFile(bucketName, file.getFilename()); } } } catch (IOException e) { throw new RuntimeException(e); } } }
S3FileHandler { public void deleteAllFilesInFolderExcept(String bucketName, String folderPath, List<String> excludeList) { var searchPath = "s3: try { var files = resolver.getResources(searchPath); for (var file : files) { var shortFileName = new File(file.getFilename()).getName(); if (!excludeList.contains(shortFileName)) { deleteFile(bucketName, file.getFilename()); } } } catch (IOException e) { throw new RuntimeException(e); } } S3FileHandler(AmazonS3 amazonS3, ApplicationContext context); }
S3FileHandler { public void deleteAllFilesInFolderExcept(String bucketName, String folderPath, List<String> excludeList) { var searchPath = "s3: try { var files = resolver.getResources(searchPath); for (var file : files) { var shortFileName = new File(file.getFilename()).getName(); if (!excludeList.contains(shortFileName)) { deleteFile(bucketName, file.getFilename()); } } } catch (IOException e) { throw new RuntimeException(e); } } S3FileHandler(AmazonS3 amazonS3, ApplicationContext context); Resource[] listFilesInFolder(String bucketName, String folderPath, String filePattern); void deleteFile(String bucketName, String filePath); void copyFile(String fromBucketName, String fromFilePath, String toBucketName, String toFilePath); Resource moveFileToWorkFolder(String bucketName, String filePath, String folderName, String workFolderSuffix); void deleteAllFilesInFolder(String bucketName, String folderPath); void deleteAllFilesInFolderExcept(String bucketName, String folderPath, List<String> excludeList); }
S3FileHandler { public void deleteAllFilesInFolderExcept(String bucketName, String folderPath, List<String> excludeList) { var searchPath = "s3: try { var files = resolver.getResources(searchPath); for (var file : files) { var shortFileName = new File(file.getFilename()).getName(); if (!excludeList.contains(shortFileName)) { deleteFile(bucketName, file.getFilename()); } } } catch (IOException e) { throw new RuntimeException(e); } } S3FileHandler(AmazonS3 amazonS3, ApplicationContext context); Resource[] listFilesInFolder(String bucketName, String folderPath, String filePattern); void deleteFile(String bucketName, String filePath); void copyFile(String fromBucketName, String fromFilePath, String toBucketName, String toFilePath); Resource moveFileToWorkFolder(String bucketName, String filePath, String folderName, String workFolderSuffix); void deleteAllFilesInFolder(String bucketName, String folderPath); void deleteAllFilesInFolderExcept(String bucketName, String folderPath, List<String> excludeList);  }