Skip to content

Commit c328614

Browse files
committed
Fixing formatting to match existing conventions.
1 parent 81f32c9 commit c328614

2 files changed

Lines changed: 83 additions & 85 deletions

File tree

src/main/java/com/cloudapp/impl/CloudAppInputStream.java

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,57 +30,57 @@
3030

3131
public class CloudAppInputStream extends InputStreamBody {
3232

33-
private final long length;
34-
private final CloudAppProgressListener listener;
33+
private final long length;
34+
private final CloudAppProgressListener listener;
3535

36-
public CloudAppInputStream(InputStream in, String filename, long length, CloudAppProgressListener listener) {
37-
super(in, filename);
38-
this.length = length;
39-
this.listener = (listener == null) ? CloudAppProgressListener.NO_OP : listener;
40-
}
36+
public CloudAppInputStream(InputStream in, String filename, long length, CloudAppProgressListener listener) {
37+
super(in, filename);
38+
this.length = length;
39+
this.listener = (listener == null) ? CloudAppProgressListener.NO_OP : listener;
40+
}
41+
42+
protected CloudAppInputStream(File file, CloudAppProgressListener listener) throws FileNotFoundException {
43+
this(new FileInputStream(file), file.getName(), file.length(), listener);
44+
}
45+
46+
@Override
47+
public void writeTo(OutputStream out) throws IOException {
48+
super.writeTo( new ListeningOutputStream(out) );
49+
}
50+
51+
@Override
52+
public long getContentLength() {
53+
return length;
54+
}
4155

42-
protected CloudAppInputStream(File file, CloudAppProgressListener listener) throws FileNotFoundException {
43-
this(new FileInputStream(file), file.getName(), file.length(), listener);
56+
private class ListeningOutputStream extends FilterOutputStream {
57+
58+
private long bytesWritten;
59+
60+
public ListeningOutputStream(OutputStream out) {
61+
super(out);
62+
bytesWritten = 0L;
4463
}
4564

4665
@Override
47-
public void writeTo(OutputStream out) throws IOException {
48-
super.writeTo( new ListeningOutputStream(out) );
66+
public void write(int b) throws IOException {
67+
out.write(b);
68+
listener.transferred(++bytesWritten, length);
4969
}
5070

5171
@Override
52-
public long getContentLength() {
53-
return length;
72+
public void write(byte[] b) throws IOException {
73+
out.write(b);
74+
bytesWritten += b.length;
75+
listener.transferred(bytesWritten, length);
5476
}
55-
56-
private class ListeningOutputStream extends FilterOutputStream {
57-
58-
private long bytesWritten;
59-
60-
public ListeningOutputStream(OutputStream out) {
61-
super(out);
62-
bytesWritten = 0L;
63-
}
64-
65-
@Override
66-
public void write(int b) throws IOException {
67-
out.write(b);
68-
listener.transferred(++bytesWritten, length);
69-
}
70-
71-
@Override
72-
public void write(byte[] b) throws IOException {
73-
out.write(b);
74-
bytesWritten += b.length;
75-
listener.transferred(bytesWritten, length);
76-
}
77-
78-
@Override
79-
public void write(byte[] b, int off, int len) throws IOException {
80-
out.write(b, off, len);
81-
bytesWritten += (len - off);
82-
listener.transferred(bytesWritten, length);
83-
}
77+
78+
@Override
79+
public void write(byte[] b, int off, int len) throws IOException {
80+
out.write(b, off, len);
81+
bytesWritten += (len - off);
82+
listener.transferred(bytesWritten, length);
8483
}
84+
}
8585

8686
}

src/main/java/com/cloudapp/impl/CloudAppItemsImpl.java

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -156,60 +156,58 @@ public List<CloudAppItem> getItems(int page, int perPage, CloudAppItem.Type type
156156
}
157157
}
158158

159-
/**
160-
*
161-
* {@inheritDoc}
162-
*
163-
* @see com.cloudapp.api.CloudAppItems#upload(java.io.File)
164-
*/
165-
public CloudAppItem upload(File file) throws CloudAppException {
166-
return upload( file, CloudAppProgressListener.NO_OP );
167-
}
159+
/**
160+
*
161+
* {@inheritDoc}
162+
*
163+
* @see com.cloudapp.api.CloudAppItems#upload(java.io.File)
164+
*/
165+
public CloudAppItem upload(File file) throws CloudAppException {
166+
return upload( file, CloudAppProgressListener.NO_OP );
167+
}
168168

169-
public CloudAppItem upload(File file, CloudAppProgressListener listener) throws CloudAppException {
170-
try {
171-
// Do a GET request so we have the S3 endpoint
172-
HttpGet req = new HttpGet(NEW_ITEM_URL);
173-
req.addHeader("Accept", "application/json");
174-
HttpResponse response = client.execute(req);
175-
int status = response.getStatusLine().getStatusCode();
176-
String responseBody = EntityUtils.toString(response.getEntity());
177-
if (status != 200)
178-
throw new CloudAppException(status, responseBody, null);
169+
public CloudAppItem upload(File file, CloudAppProgressListener listener) throws CloudAppException {
170+
try {
171+
// Do a GET request so we have the S3 endpoint
172+
HttpGet req = new HttpGet(NEW_ITEM_URL);
173+
req.addHeader("Accept", "application/json");
174+
HttpResponse response = client.execute(req);
175+
int status = response.getStatusLine().getStatusCode();
176+
String responseBody = EntityUtils.toString(response.getEntity());
177+
if (status != 200)
178+
throw new CloudAppException(status, responseBody, null);
179179

180-
JSONObject json = new JSONObject(responseBody);
181-
if (!json.has("params")) {
182-
// Something went wrong, maybe we crossed the treshold?
183-
if (json.getInt("uploads_remaining") == 0) {
184-
throw new CloudAppException(200, "Uploads remaining is 0", null);
185-
}
186-
throw new CloudAppException(500, "Missing params object from the CloudApp API.",
187-
null);
188-
}
180+
JSONObject json = new JSONObject(responseBody);
181+
if (!json.has("params")) {
182+
// Something went wrong, maybe we crossed the treshold?
183+
if (json.getInt("uploads_remaining") == 0) {
184+
throw new CloudAppException(200, "Uploads remaining is 0", null);
185+
}
186+
throw new CloudAppException(500, "Missing params object from the CloudApp API.",
187+
null);
188+
}
189189

190-
return uploadToAmazon(json, file, listener);
190+
return uploadToAmazon(json, file, listener);
191191

192-
} catch (ClientProtocolException e) {
193-
LOGGER.error("Something went wrong trying to contact the CloudApp API.", e);
194-
throw new CloudAppException(500,
195-
"Something went wrong trying to contact the CloudApp API", e);
196-
} catch (IOException e) {
197-
LOGGER.error("Something went wrong trying to contact the CloudApp API.", e);
198-
throw new CloudAppException(500,
199-
"Something went wrong trying to contact the CloudApp API.", e);
200-
} catch (JSONException e) {
201-
LOGGER.error("Something went wrong trying to handle JSON.", e);
202-
throw new CloudAppException(500, "Something went wrong trying to handle JSON.", e);
203-
}
192+
} catch (ClientProtocolException e) {
193+
LOGGER.error("Something went wrong trying to contact the CloudApp API.", e);
194+
throw new CloudAppException(500,
195+
"Something went wrong trying to contact the CloudApp API", e);
196+
} catch (IOException e) {
197+
LOGGER.error("Something went wrong trying to contact the CloudApp API.", e);
198+
throw new CloudAppException(500,
199+
"Something went wrong trying to contact the CloudApp API.", e);
200+
} catch (JSONException e) {
201+
LOGGER.error("Something went wrong trying to handle JSON.", e);
202+
throw new CloudAppException(500, "Something went wrong trying to handle JSON.", e);
204203
}
204+
}
205205

206206
/**
207207
* Uploads a file to S3
208208
*
209-
*
210209
* @param json
211210
* @param file
212-
* @param listener
213211
* @return
214212
* @throws JSONException
215213
* @throws CloudAppException

0 commit comments

Comments
 (0)