use of org.jclouds.blobstore.BlobStore in project legacy-jclouds-examples by jclouds.
the class BlobStoreServiceImpl method read.
public Object read(String bucket, String blobName) {
Object result = null;
ObjectInputStream ois = null;
context = new BlobStoreContextFactory().createContext(provider, accessKeyId, secretKey);
if (context != null) {
BlobStore blobStore = context.getBlobStore();
blobStore.createContainerInLocation(null, bucket);
InputStream is = blobStore.getBlob(bucket, blobName).getPayload().getInput();
try {
ois = new ObjectInputStream(is);
result = ois.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
}
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
}
}
}
} else
logger.warn("Blob store context is null.");
return result;
}
use of org.jclouds.blobstore.BlobStore in project qi4j-sdk by Qi4j.
the class JCloudsMapEntityStoreMixin method applyChanges.
@Override
public void applyChanges(MapChanges changes) throws IOException {
final BlobStore blobStore = storeContext.getBlobStore();
changes.visitMap(new MapChanger() {
@Override
public Writer newEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
return new StringWriter() {
@Override
public void close() throws IOException {
super.close();
Blob blob = blobStore.blobBuilder(ref.identity()).payload(ByteSource.wrap(toString().getBytes(UTF_8))).build();
blobStore.putBlob(container, blob);
}
};
}
@Override
public Writer updateEntity(final EntityReference ref, EntityDescriptor entityDescriptor) throws IOException {
if (!blobStore.blobExists(container, ref.identity())) {
throw new EntityNotFoundException(ref);
}
return new StringWriter() {
@Override
public void close() throws IOException {
super.close();
Blob blob = blobStore.blobBuilder(ref.identity()).payload(ByteSource.wrap(toString().getBytes(UTF_8))).build();
blobStore.putBlob(container, blob);
}
};
}
@Override
public void removeEntity(EntityReference ref, EntityDescriptor entityDescriptor) throws EntityNotFoundException {
if (!blobStore.blobExists(container, ref.identity())) {
throw new EntityNotFoundException(ref);
}
blobStore.removeBlob(container, ref.identity());
}
});
}
Aggregations