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;
}
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;
}
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);
}
Aggregations