Search in sources :

Example 66 with ByteSource

use of com.google.common.io.ByteSource in project dhis2-core by dhis2.

the class JCloudsFileResourceContentStore method getFileResourceContent.

// -------------------------------------------------------------------------
// FileResourceContentStore implementation
// -------------------------------------------------------------------------
@Override
public ByteSource getFileResourceContent(String key) {
    final Blob blob = getBlob(key);
    if (blob == null) {
        return null;
    }
    final ByteSource byteSource = new ByteSource() {

        @Override
        public InputStream openStream() {
            try {
                return blob.getPayload().openStream();
            } catch (IOException e) {
                return new NullInputStream(0);
            }
        }
    };
    boolean isEmptyOrFailed;
    try {
        isEmptyOrFailed = byteSource.isEmpty();
    } catch (IOException e) {
        isEmptyOrFailed = true;
    }
    return isEmptyOrFailed ? null : byteSource;
}
Also used : Blob(org.jclouds.blobstore.domain.Blob) ByteSource(com.google.common.io.ByteSource) IOException(java.io.IOException) NullInputStream(org.apache.commons.io.input.NullInputStream)

Aggregations

ByteSource (com.google.common.io.ByteSource)66 Test (org.junit.Test)33 IOException (java.io.IOException)29 InputStream (java.io.InputStream)21 ByteArrayInputStream (java.io.ByteArrayInputStream)18 Metacard (ddf.catalog.data.Metacard)15 ContentItem (ddf.catalog.content.data.ContentItem)14 ContentItemImpl (ddf.catalog.content.data.impl.ContentItemImpl)14 File (java.io.File)14 ArrayList (java.util.ArrayList)10 CreateStorageRequestImpl (ddf.catalog.content.operation.impl.CreateStorageRequestImpl)9 URI (java.net.URI)8 HashMap (java.util.HashMap)8 CreateStorageResponse (ddf.catalog.content.operation.CreateStorageResponse)7 Path (java.nio.file.Path)7 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 FileInputStream (java.io.FileInputStream)6 Serializable (java.io.Serializable)6 StringWriter (java.io.StringWriter)6