Search in sources :

Example 6 with Payload

use of org.jclouds.io.Payload in project qi4j-sdk by Qi4j.

the class JCloudsMapEntityStoreMixin method get.

@Override
public Reader get(EntityReference entityReference) throws EntityStoreException {
    Blob blob = storeContext.getBlobStore().getBlob(container, entityReference.identity());
    if (blob == null) {
        throw new EntityNotFoundException(entityReference);
    }
    Payload payload = blob.getPayload();
    if (payload == null) {
        throw new EntityNotFoundException(entityReference);
    }
    InputStream input = null;
    try {
        input = payload.openStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Inputs.byteBuffer(input, 4096).transferTo(Outputs.byteBuffer(baos));
        return new StringReader(baos.toString("UTF-8"));
    } catch (IOException ex) {
        throw new EntityStoreException("Unable to read entity state for: " + entityReference, ex);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException ignored) {
            }
        }
    }
}
Also used : Blob(org.jclouds.blobstore.domain.Blob) InputStream(java.io.InputStream) StringReader(java.io.StringReader) Payload(org.jclouds.io.Payload) EntityNotFoundException(org.qi4j.spi.entitystore.EntityNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) EntityStoreException(org.qi4j.spi.entitystore.EntityStoreException)

Example 7 with Payload

use of org.jclouds.io.Payload in project legacy-jclouds-examples by jclouds.

the class HdfsPayloadSlicer method slice.

@Override
public Payload slice(Payload input, long offset, long length) {
    checkNotNull(input);
    checkArgument(offset >= 0, "offset is negative");
    checkArgument(length >= 0, "length is negative");
    Payload returnVal;
    if (input instanceof HdfsPayload) {
        returnVal = doSlice((FSDataInputStream) ((HdfsPayload) input).getInput(), offset, length);
        return copyMetadataAndSetLength(input, returnVal, length);
    } else {
        return super.slice(input, offset, length);
    }
}
Also used : HdfsPayload(org.jclouds.examples.blobstore.hdfs.io.payloads.HdfsPayload) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) InputStreamSupplierPayload(org.jclouds.io.payloads.InputStreamSupplierPayload) Payload(org.jclouds.io.Payload) HdfsPayload(org.jclouds.examples.blobstore.hdfs.io.payloads.HdfsPayload)

Example 8 with Payload

use of org.jclouds.io.Payload in project druid by druid-io.

the class CloudFilesObjectApiProxy method get.

public CloudFilesObject get(String path) {
    SwiftObject swiftObject = objectApi.get(path);
    Payload payload = swiftObject.getPayload();
    return new CloudFilesObject(payload, this.region, this.container, path);
}
Also used : SwiftObject(org.jclouds.openstack.swift.v1.domain.SwiftObject) Payload(org.jclouds.io.Payload)

Example 9 with Payload

use of org.jclouds.io.Payload in project camel by apache.

the class JcloudsPayloadConverter method convertTo.

@FallbackConverter
@SuppressWarnings("unchecked")
public static <T extends Payload> T convertTo(Class<T> type, Exchange exchange, Object value, TypeConverterRegistry registry) throws IOException {
    Class<?> sourceType = value.getClass();
    if (GenericFile.class.isAssignableFrom(sourceType)) {
        GenericFile<?> genericFile = (GenericFile<?>) value;
        if (genericFile.getFile() != null) {
            Class<?> genericFileType = genericFile.getFile().getClass();
            TypeConverter converter = registry.lookup(Payload.class, genericFileType);
            if (converter != null) {
                return (T) converter.convertTo(Payload.class, genericFile.getFile());
            }
        }
    }
    return null;
}
Also used : TypeConverter(org.apache.camel.TypeConverter) InputStreamPayload(org.jclouds.io.payloads.InputStreamPayload) ByteSourcePayload(org.jclouds.io.payloads.ByteSourcePayload) Payload(org.jclouds.io.Payload) GenericFile(org.apache.camel.component.file.GenericFile) FallbackConverter(org.apache.camel.FallbackConverter)

Example 10 with Payload

use of org.jclouds.io.Payload in project jackrabbit-oak by apache.

the class CloudBlobStore method readBlockFromBackend.

/**
     * Reads the data from the actual cloud service.
     */
@Override
protected byte[] readBlockFromBackend(BlockId blockId) throws Exception {
    Preconditions.checkNotNull(context);
    String id = StringUtils.convertBytesToHex(blockId.getDigest());
    byte[] data = cache.get(id);
    if (data == null) {
        Blob cloudBlob = context.getBlobStore().getBlob(cloudContainer, id);
        if (cloudBlob == null) {
            String message = "Did not find block " + id;
            LOG.error(message);
            throw new IOException(message);
        }
        Payload payload = cloudBlob.getPayload();
        try {
            data = ByteStreams.toByteArray(payload.getInput());
            cache.put(id, data);
        } finally {
            payload.close();
        }
    }
    if (blockId.getPos() == 0) {
        return data;
    }
    int len = (int) (data.length - blockId.getPos());
    if (len < 0) {
        return new byte[0];
    }
    byte[] d2 = new byte[len];
    System.arraycopy(data, (int) blockId.getPos(), d2, 0, len);
    return d2;
}
Also used : Blob(org.jclouds.blobstore.domain.Blob) Payload(org.jclouds.io.Payload) IOException(java.io.IOException)

Aggregations

Payload (org.jclouds.io.Payload)10 Test (org.junit.Test)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Blob (org.jclouds.blobstore.domain.Blob)2 SwiftObject (org.jclouds.openstack.swift.v1.domain.SwiftObject)2 ObjectApi (org.jclouds.openstack.swift.v1.features.ObjectApi)2 CloudFilesApi (org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi)2 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 DataSegment (io.druid.timeline.DataSegment)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 StringReader (java.io.StringReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FallbackConverter (org.apache.camel.FallbackConverter)1 TypeConverter (org.apache.camel.TypeConverter)1 GenericFile (org.apache.camel.component.file.GenericFile)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 HdfsPayload (org.jclouds.examples.blobstore.hdfs.io.payloads.HdfsPayload)1