Search in sources :

Example 1 with InputStreamMap

use of org.jclouds.blobstore.InputStreamMap in project qi4j-sdk by Qi4j.

the class JCloudsMapEntityStoreMixin method get.

@Override
public Reader get(EntityReference entityReference) throws EntityStoreException {
    InputStreamMap isMap = storeContext.createInputStreamMap(container);
    InputStream input = isMap.get(entityReference.identity());
    if (input == null) {
        throw new EntityNotFoundException(entityReference);
    }
    try {
        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 {
        try {
            input.close();
        } catch (IOException ignored) {
        }
    }
}
Also used : InputStreamMap(org.jclouds.blobstore.InputStreamMap) InputStream(java.io.InputStream) StringReader(java.io.StringReader) EntityNotFoundException(org.qi4j.spi.entitystore.EntityNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) EntityStoreException(org.qi4j.spi.entitystore.EntityStoreException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StringReader (java.io.StringReader)1 InputStreamMap (org.jclouds.blobstore.InputStreamMap)1 EntityNotFoundException (org.qi4j.spi.entitystore.EntityNotFoundException)1 EntityStoreException (org.qi4j.spi.entitystore.EntityStoreException)1