Search in sources :

Example 11 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 12 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)

Example 13 with Payload

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

the class CloudFilesObjectApiProxy method get.

public CloudFilesObject get(String path, long start) {
    final SwiftObject swiftObject;
    if (start == 0) {
        swiftObject = objectApi.get(path);
    } else {
        swiftObject = objectApi.get(path, new GetOptions().startAt(start));
    }
    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) GetOptions(org.jclouds.http.options.GetOptions)

Aggregations

Payload (org.jclouds.io.Payload)13 Test (org.junit.Test)7 InputStream (java.io.InputStream)4 SwiftObject (org.jclouds.openstack.swift.v1.domain.SwiftObject)4 IOException (java.io.IOException)3 ObjectApi (org.jclouds.openstack.swift.v1.features.ObjectApi)3 CloudFilesApi (org.jclouds.rackspace.cloudfiles.v1.CloudFilesApi)3 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)1 DataSegment (io.druid.timeline.DataSegment)1 File (java.io.File)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 Blob (org.jclouds.blobstore.domain.Blob)1 HdfsPayload (org.jclouds.examples.blobstore.hdfs.io.payloads.HdfsPayload)1 GetOptions (org.jclouds.http.options.GetOptions)1 ByteSourcePayload (org.jclouds.io.payloads.ByteSourcePayload)1