Package io.fathom.cloud.image

Source Code of io.fathom.cloud.image.DirectImageDataService

package io.fathom.cloud.image;

import io.fathom.cloud.blobs.BlobData;
import io.fathom.cloud.blobs.BlobStore;
import io.fathom.cloud.blobs.BlobStoreFactory;

import java.io.IOException;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.fathomdb.utils.Hex;
import com.google.inject.persist.Transactional;
import com.google.protobuf.ByteString;

@Singleton
@Transactional
public class DirectImageDataService implements ImageDataService {
    @Inject
    BlobStoreFactory blobStoreFactory;

    @Override
    public String storeImageFile(BlobData data) throws IOException {
        BlobStore blobStore = getBlobStore();

        blobStore.put(data);

        return Hex.toHex(data.getHash().toByteArray());
    }

    BlobStore getBlobStore() throws IOException {
        return blobStoreFactory.get("images");
    }

    @Override
    public BlobData getImageFile(String cookie) throws IOException {
        BlobStore blobStore = getBlobStore();

        ByteString key = ByteString.copyFrom(Hex.fromHex(cookie));

        BlobData blobData = blobStore.find(key);

        return blobData;
    }
}
TOP

Related Classes of io.fathom.cloud.image.DirectImageDataService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.