Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
djalova committed Apr 7, 2016
1 parent bc34c88 commit cd05a0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/ibm/stocator/fs/swift/SwiftAPIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public class SwiftAPIClient implements IStoreClient {
*/
private final int pageListSize = 100;

/*
* Maximum size for a Swift Object
* Default is 5GB
*/
private long maxObjectSize;
private static final long DEFAULT_MAX_OBJECT_SIZE = 5L * 1024 * 1024 * 1024;

Expand Down
29 changes: 10 additions & 19 deletions src/main/java/com/ibm/stocator/fs/swift/SwiftOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public class SwiftOutputStream extends OutputStream {
*/
private HttpURLConnection mHttpCon;

/*
* Maximum size to be written to a Swift object before a new object is created.
*/
private long maxSplitSize;
private long totalBytesWritten = 0L;
private int splitCount = 0;
Expand Down Expand Up @@ -152,31 +155,20 @@ private void splitFileUpload() throws IOException {
mOutputStream.close();
URL oldURL = mHttpCon.getURL();
String prevSplitName = oldURL.getPath();

StringBuilder currSplitName = new StringBuilder();

if (!prevSplitName.contains("split")) {
currSplitName = new StringBuilder(prevSplitName.substring(0,
prevSplitName.lastIndexOf('-') + 1));
currSplitName.append("split-" + String.format("%05d", ++splitCount));
currSplitName.append(prevSplitName.substring(prevSplitName.lastIndexOf('-')));
String currSplitName;
if (splitCount == 0) {
currSplitName = new StringBuilder(prevSplitName).insert(prevSplitName.lastIndexOf('-') + 1,
"split-" + String.format("%05d", ++splitCount) + "-").toString();
} else {
String[] nameComponents = prevSplitName.split("split-\\d\\d\\d\\d\\d");
currSplitName.append(nameComponents[0]);
currSplitName.append("split-" + String.format("%05d", ++splitCount));
currSplitName.append(nameComponents[1]);
currSplitName = prevSplitName.replaceAll("split-\\d\\d\\d\\d\\d",
"split-" + String.format("%05d", ++splitCount));
}

URL newURL = new URL(oldURL.getProtocol() + "://" + oldURL.getAuthority()
+ currSplitName.toString());

URL newURL = new URL(oldURL.getProtocol() + "://" + oldURL.getAuthority() + currSplitName);
try {
mHttpCon.disconnect();
HttpURLConnection newConn = (HttpURLConnection) newURL.openConnection();

newConn.setDoInput(true);
newConn.setRequestMethod("PUT");

newConn.setReadTimeout(READ_TIMEOUT);
newConn.setChunkedStreamingMode(STREAMING_CHUNK);

Expand All @@ -189,7 +181,6 @@ private void splitFileUpload() throws IOException {
}
}
newConn.setDoOutput(true);

mOutputStream = newConn.getOutputStream();
mHttpCon = newConn;
} catch (IOException e) {
Expand Down

0 comments on commit cd05a0d

Please sign in to comment.