Skip to content

Commit

Permalink
Implement listObjectParts and abortMultipart
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed May 13, 2015
1 parent 22031c4 commit 3f5cf2f
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
*.class

# Mobile Tools for Java (J2ME)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Minimal object storage library in Java

[![Build Status](https://travis-ci.org/minio/objectstorage-java.svg)](https://travis-ci.org/minio/objectstorage-java)

## Install

```sh
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/io/minio/objectstorage/client/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,47 @@ private void completeMultipart(String bucket, String key, String uploadID, List<
response.disconnect();
}

private ListPartsResult listObjectParts(String bucket, String key, String uploadID) throws IOException, XmlPullParserException {
GenericUrl url = getGenericUrlOfKey(bucket, key);
url.set("uploadId", uploadID);

HttpRequest request = getHttpRequest("GET", url);
HttpHeaders headers = request.getHeaders();
headers.setAccept(this.contentType);

HttpResponse response = request.execute();

try {
XmlPullParser parser = Xml.createParser();
InputStreamReader reader = new InputStreamReader(response.getContent(), "UTF-8");
parser.setInput(reader);

ListPartsResult result = new ListPartsResult();

Xml.parseElement(parser, result, new XmlNamespaceDictionary(), null);
return result;
} finally {
response.disconnect();
}
}

private boolean abortMultipart(String bucket, String key, String uploadID) throws IOException {
GenericUrl url = getGenericUrlOfKey(bucket, key);
url.set("uploadId", uploadID);

HttpRequest request = getHttpRequest("DELETE", url);
try {
HttpResponse response = request.execute();
try {
return response.getStatusCode() == 200;
} finally {
response.disconnect();
}
} catch (HttpResponseException e) {
return false;
}
}

private int computePartSize(long size) {
int minimumPartSize = PART_SIZE; // 5MB
int partSize = (int) (size / 9999);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Minimal Object Storage Library, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.minio.objectstorage.client.messages;

import com.google.api.client.util.Key;

public class Initiator extends XmlEntity {
@Key
private String ID;
@Key
private String DisplayName;

public Initiator() {
super();
this.name = "Initiator";
}

public String getID() {
return ID;
}

public void setID(String ID) {
this.ID = ID;
}

public String getDisplayName() {
return DisplayName;
}

public void setDisplayName(String displayName) {
DisplayName = displayName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Minimal Object Storage Library, (C) 2015 Minio, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.minio.objectstorage.client.messages;

import com.google.api.client.util.Key;

import java.util.List;

public class ListPartsResult extends XmlEntity {
@Key("Bucket")
private String Bucket;
@Key("Key")
private String Key;
@Key("Initiator")
private Initiator initiator;
@Key("Owner")
private Owner owner;
@Key("StorageClass")
private String storageClass;
@Key("PartNumberMarker")
private int PartNumberMarker;
@Key("NextPartNumberMarker")
private int NextPartNumberMarker;
@Key("MaxParts")
private int MaxParts;
@Key("IsTruncated")
private boolean IsTruncated;
@Key("Part")
private List<Part> Part;

public ListPartsResult() {
super();
this.name = "ListPartsResult";
}

public String getBucket() {
return Bucket;
}

public void setBucket(String bucket) {
Bucket = bucket;
}

public String getKey() {
return Key;
}

public void setKey(String key) {
Key = key;
}

public String getStorageClass() {
return storageClass;
}

public void setStorageClass(String storageClass) {
this.storageClass = storageClass;
}

public Owner getOwner() {
return owner;
}

public void setOwner(Owner owner) {
this.owner = owner;
}

public int getMaxParts() {
return MaxParts;
}

public void setMaxParts(int maxParts) {
MaxParts = maxParts;
}

public boolean isTruncated() {
return IsTruncated;
}

public void setIsTruncated(boolean isTruncated) {
IsTruncated = isTruncated;
}

public int getPartNumberMarker() {
return PartNumberMarker;
}

public void setPartNumberMarker(int partNumberMarker) {
PartNumberMarker = partNumberMarker;
}

public int getNextPartNumberMarker() {
return NextPartNumberMarker;
}

public void setNextPartNumberMarker(int nextPartNumberMarker) {
NextPartNumberMarker = nextPartNumberMarker;
}

public List<Part> getParts() {
return Part;
}

public void setParts(List<Part> parts) {
Part = parts;
}

}
32 changes: 32 additions & 0 deletions src/main/java/io/minio/objectstorage/client/messages/Part.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@

import com.google.api.client.util.Key;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class Part extends XmlEntity {
@Key("PartNumber")
private int partNumber;
@Key("ETag")
private String eTag;
@Key("LastModified")
private String lastModified;
@Key("Size")
private long size;

public Part() {
super();
Expand All @@ -44,4 +53,27 @@ public String geteTag() {
public void seteTag(String eTag) {
this.eTag = eTag;
}

public String getLastModified() {
return lastModified;
}

public void setLastModified(String lastModified) {
this.lastModified = lastModified;
}

public Date getParsedLastModified() throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
formatter.setTimeZone(TimeZone.getTimeZone("UTC"));
return formatter.parse(this.getLastModified());
}

public long getSize() {
return size;
}

public void setSize(long size) {
this.size = size;
}

}

0 comments on commit 3f5cf2f

Please sign in to comment.