use of com.pratilipi.data.type.gcs.BlobEntryGcsImpl in project pratilipi by Pratilipi.
the class BlobAccessorGcsImpl method getBlob.
@Override
public BlobEntry getBlob(String fileName) throws UnexpectedServerException {
GcsFilename gcsFileName = new GcsFilename(bucketName, fileName);
try {
GcsFileMetadata gcsFileMetadata = gcsService.getMetadata(gcsFileName);
if (gcsFileMetadata == null)
return null;
if (gcsFileMetadata.getLength() == 0)
return null;
GcsInputChannel gcsInputChannel = gcsService.openReadChannel(gcsFileName, 0);
ByteBuffer byteBuffer = ByteBuffer.allocate((int) gcsFileMetadata.getLength());
gcsInputChannel.read(byteBuffer);
if (byteBuffer.position() != gcsFileMetadata.getLength()) {
logger.log(Level.SEVERE, "Byte buffer size of " + byteBuffer.position() + " is not same as content lenght of " + gcsFileMetadata.getLength());
throw new UnexpectedServerException();
}
return new BlobEntryGcsImpl(byteBuffer, gcsFileMetadata);
} catch (IOException ex) {
logger.log(Level.INFO, "Failed to fetch blob with name '" + fileName + "'", ex);
throw new UnexpectedServerException();
}
}
use of com.pratilipi.data.type.gcs.BlobEntryGcsImpl in project pratilipi by Pratilipi.
the class BlobAccessorGcsImpl2 method createOrUpdateBlob.
@Override
public BlobEntry createOrUpdateBlob(BlobEntry blobEntry) {
BlobId blobId = BlobId.of(bucketName, blobEntry.getName());
Builder blobInfoBuilder = BlobInfo.newBuilder(blobId);
if (blobEntry.getMimeType() != null)
blobInfoBuilder.setContentType(blobEntry.getMimeType());
if (blobEntry.getCacheControl() != null)
blobInfoBuilder.setCacheControl(blobEntry.getCacheControl());
if (blobEntry.getMetaName() != null) {
Map<String, String> metadata = new HashMap<>();
metadata.put(BlobEntry.META_NAME, blobEntry.getMetaName());
blobInfoBuilder.setMetadata(metadata);
}
return new BlobEntryGcsImpl(gcsService.create(blobInfoBuilder.build(), blobEntry.getData()));
}
Aggregations