Source:
public boolean delete(URI segmentUri, boolean forceDelete) throws IOException { LOGGER.info("Deleting uri force {}", segmentUri, forceDelete); try { if (isDirectory(segmentUri)) { if (!forceDelete) { checkState(isEmptyDirectory(segmentUri), "ForceDelete flag is not set and directory '%s' is not empty", segmentUri); } String prefix = normalizeToDirectoryPrefix(segmentUri); ListObjectsV2Response listObjectsV2Response; ListObjectsV2Request.Builder listObjectsV2RequestBuilder = ListObjectsV2Request.builder() .bucket(segmentUri.getHost()); if (prefix.equals(DELIMITER)) { ListObjectsV2Request listObjectsV2Request = listObjectsV2RequestBuilder.build(); listObjectsV2Response = s3Client.listObjectsV2(listObjectsV2Request); } else { ListObjectsV2Request listObjectsV2Request = listObjectsV2RequestBuilder.prefix(prefix).build(); listObjectsV2Response = s3Client.listObjectsV2(listObjectsV2Request); } boolean deleteSucceeded = true; for (S3Object s3Object : listObjectsV2Response.contents()) { DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder() .bucket(segmentUri.getHost()) .key(s3Object.key()) .build(); DeleteObjectResponse deleteObjectResponse = s3Client.deleteObject(deleteObjectRequest); deleteSucceeded &= deleteObjectResponse.sdkHttpResponse().isSuccessful(); } return deleteSucceeded; } else { String prefix = sanitizePath(segmentUri.getPath()); DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder() .bucket(segmentUri.getHost()) .key(prefix) .build(); DeleteObjectResponse deleteObjectResponse = s3Client.deleteObject(deleteObjectRequest); return deleteObjectResponse.sdkHttpResponse().isSuccessful(); } }catch(NoSuchKeyException e){ return false; } catch (S3Exception e) { throw e; } catch(Throwable t) { throw new IOException(t); } }

Target:
public boolean delete(URI segmentUri, boolean forceDelete) throws IOException { LOGGER.info("Deleting uri force {}", segmentUri, forceDelete); try { if (isDirectory(segmentUri)) { if (!forceDelete) { Preconditions .checkState(isEmptyDirectory(segmentUri), "ForceDelete flag is not set and directory '%s' is not empty", segmentUri); } String prefix = normalizeToDirectoryPrefix(segmentUri); ListObjectsV2Response listObjectsV2Response; ListObjectsV2Request.Builder listObjectsV2RequestBuilder = ListObjectsV2Request.builder().bucket(segmentUri.getHost()); if (prefix.equals(DELIMITER)) { ListObjectsV2Request listObjectsV2Request = listObjectsV2RequestBuilder.build(); listObjectsV2Response = _s3Client.listObjectsV2(listObjectsV2Request); } else { ListObjectsV2Request listObjectsV2Request = listObjectsV2RequestBuilder.prefix(prefix).build(); listObjectsV2Response = _s3Client.listObjectsV2(listObjectsV2Request); } boolean deleteSucceeded = true; for (S3Object s3Object : listObjectsV2Response.contents()) { DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder().bucket(segmentUri.getHost()).key(s3Object.key()).build(); DeleteObjectResponse deleteObjectResponse = _s3Client.deleteObject(deleteObjectRequest); deleteSucceeded &= deleteObjectResponse.sdkHttpResponse().isSuccessful(); } return deleteSucceeded; } else { String prefix = sanitizePath(segmentUri.getPath()); DeleteObjectRequest deleteObjectRequest = DeleteObjectRequest.builder().bucket(segmentUri.getHost()).key(prefix).build(); DeleteObjectResponse deleteObjectResponse = _s3Client.deleteObject(deleteObjectRequest); return deleteObjectResponse.sdkHttpResponse().isSuccessful(); } } catch (NoSuchKeyException e) { return false; } catch (S3Exception e) { throw e; } catch (Exception e) { throw new IOException(e); } }