Search in sources :

Example 6 with BlobStore

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;
}
Also used : BlobStoreContextFactory(org.jclouds.blobstore.BlobStoreContextFactory) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) BlobStore(org.jclouds.blobstore.BlobStore) ObjectInputStream(java.io.ObjectInputStream)

Example 7 with BlobStore

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());
        }
    });
}
Also used : EntityDescriptor(org.qi4j.api.entity.EntityDescriptor) Blob(org.jclouds.blobstore.domain.Blob) StringWriter(java.io.StringWriter) EntityReference(org.qi4j.api.entity.EntityReference) EntityReference.parseEntityReference(org.qi4j.api.entity.EntityReference.parseEntityReference) IOException(java.io.IOException) EntityNotFoundException(org.qi4j.spi.entitystore.EntityNotFoundException) BlobStore(org.jclouds.blobstore.BlobStore) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

BlobStore (org.jclouds.blobstore.BlobStore)7 BlobStoreContext (org.jclouds.blobstore.BlobStoreContext)4 Blob (org.jclouds.blobstore.domain.Blob)4 IOException (java.io.IOException)3 BlobStoreContextFactory (org.jclouds.blobstore.BlobStoreContextFactory)3 InputStream (java.io.InputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Properties (java.util.Properties)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1 AtmosClient (org.jclouds.atmos.AtmosClient)1 AzureBlobAsyncClient (org.jclouds.azureblob.AzureBlobAsyncClient)1 AzureBlobClient (org.jclouds.azureblob.AzureBlobClient)1 StorageMetadata (org.jclouds.blobstore.domain.StorageMetadata)1 HdfsPayload (org.jclouds.examples.blobstore.hdfs.io.payloads.HdfsPayload)1 SwiftClient (org.jclouds.openstack.swift.SwiftClient)1