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