Skip to content

Commit

Permalink
Improving multipart upload semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
fkautz committed Jun 14, 2015
1 parent 7ef81d8 commit 8d0cf23
Showing 1 changed file with 5 additions and 23 deletions.
28 changes: 5 additions & 23 deletions src/main/java/io/minio/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ public void setBucketACL(String bucket, Acl acl) throws IOException, ClientExcep
* @param contentType Content type to set this object to
* @param size Size of all the data that will be uploaded.
* @param body Data to upload
*
* @throws IOException upon connection error
* @throws ClientException upon failure from server
* @see #listAllUnfinishedUploads(String)
Expand Down Expand Up @@ -938,14 +939,12 @@ public void putObject(String bucket, String key, String contentType, long size,
long objectLength = 0;
List<Part> parts = new LinkedList<Part>();
int partNumber = 1;
Iterator<Part> skipParts = listObjectParts(bucket, key, uploadID);
Iterator<Part> existingParts = listObjectParts(bucket, key, uploadID);
while (true) {
Data data = readData(partSize, body);
if (iteratorSize(skipParts) > 0) {
Part part = new Part();
part.setPartNumber(partNumber);
part.seteTag(DatatypeConverter.printHexBinary(data.getMD5()));
if (isPartUploaded(part, skipParts)) {
if (existingParts.hasNext()) {
Part existingPart = existingParts.next();
if (existingPart.getPartNumber() == partNumber && existingPart.geteTag().toLowerCase().equals(Arrays.toString(data.getMD5()).toLowerCase())) {
partNumber++;
continue;
}
Expand All @@ -968,23 +967,6 @@ public void putObject(String bucket, String key, String contentType, long size,
}
}

private int iteratorSize(Iterator<?> it) {
if (it instanceof Collection) {
return ((Collection<?>)it).size();
}
return 0;
}

private Boolean isPartUploaded(Part part, Iterator<Part> skipParts) {
while (skipParts.hasNext()) {
Part p = skipParts.next();
String etag = p.geteTag().replaceAll("\"", "").toLowerCase().trim();
if (etag.equals(part.geteTag()) && p.getPartNumber() == part.getPartNumber()) {
return true;
}
}
return false;
}
/**
* Lists all active multipart uploads in a bucket
*
Expand Down

0 comments on commit 8d0cf23

Please sign in to comment.