use of com.google.appengine.tools.cloudstorage.GcsOutputChannel in project pratilipi by Pratilipi.
the class BlobAccessorGcsImpl method createOrUpdateBlob.
@Override
public BlobEntry createOrUpdateBlob(BlobEntry blobEntry) throws UnexpectedServerException {
GcsFilename gcsFileName = new GcsFilename(bucketName, blobEntry.getName());
Builder builder = new GcsFileOptions.Builder();
if (blobEntry.getMimeType() != null)
builder.mimeType(blobEntry.getMimeType());
if (blobEntry.getCacheControl() != null)
builder.cacheControl(blobEntry.getCacheControl());
if (blobEntry.getMetaName() != null)
builder.addUserMetadata(BlobEntry.META_NAME, blobEntry.getMetaName());
GcsFileOptions gcsFileOptions = builder.build();
try {
GcsOutputChannel gcsOutputChannel = gcsService.createOrReplace(gcsFileName, gcsFileOptions);
gcsOutputChannel.write(ByteBuffer.wrap(blobEntry.getData()));
gcsOutputChannel.close();
} catch (IOException ex) {
logger.log(Level.INFO, "Failed to create/update blob with name '" + blobEntry.getName() + "'", ex);
throw new UnexpectedServerException();
}
return null;
}
use of com.google.appengine.tools.cloudstorage.GcsOutputChannel in project iosched by google.
the class CloudFileManager method createOrUpdate.
/**
* Create or update a file in a GCC bucket, using the default ACL for the bucket.
*
* @param filename Name of file to create
* @param contents File contents
* @param shortCache If true, sets cache expiry to 0 sec. Otherwise, cache expiry is set to 6,000 sec.
* @throws IOException
*/
public void createOrUpdate(String filename, JsonElement contents, boolean shortCache) throws IOException {
GcsFilename file = new GcsFilename(defaultBucket, filename);
GcsFileOptions options = new GcsFileOptions.Builder().mimeType("application/json").cacheControl("public, max-age=" + (shortCache ? 0 : 6000)).build();
GcsOutputChannel writeChannel = null;
try {
writeChannel = gcsService.createOrReplace(file, options);
Writer writer = Channels.newWriter(writeChannel, DEFAULT_CHARSET_NAME);
new Gson().toJson(contents, writer);
writer.flush();
} finally {
if (writeChannel != null) {
writeChannel.close();
}
}
}
Aggregations