Skip to content

Commit

Permalink
complete output writer
Browse files Browse the repository at this point in the history
  • Loading branch information
aozarov committed May 7, 2015
1 parent 6d4ac35 commit d2c6344
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
8 changes: 7 additions & 1 deletion src/main/java/com/google/gcloud/examples/StorageExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
* An example of using the Google Cloud Storage.
Expand Down Expand Up @@ -194,12 +195,17 @@ private static class UploadAction extends StorageAction<Tuple<Path, Blob>> {
@Override
public void run(StorageService storage, Tuple<Path, Blob> tuple) throws Exception {
if (Files.size(tuple.x()) > 1024) {
Random rnd = new Random();
try (BlobWriteChannel writer = storage.writer(tuple.y())) {
byte[] buffer = new byte[1024];
try (InputStream input = Files.newInputStream(tuple.x())) {
int limit;
while ((limit = input.read(buffer)) >= 0) {
writer.write(ByteBuffer.wrap(buffer, 0, limit));
try {
writer.write(ByteBuffer.wrap(buffer, 0, limit));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
Expand Down
Loading

0 comments on commit d2c6344

Please sign in to comment.