Package org.akubraproject

Examples of org.akubraproject.Blob


            throws ObjectAlreadyInLowlevelStorageException {
        BlobStoreConnection connection = null;
        try {
            URI blobId = getBlobId(key);
            connection = getConnection(store, hints);
            Blob blob = getBlob(connection, blobId, hints);
            OutputStream out = openOutputStream(blob, -1, false);
            copy(content, out);
            try {
                return blob.getSize();
            } catch (MissingBlobException e) { // should never happen
                throw new RuntimeException("Missing blob after adding the blob: " +e.getMessage(), e);
            } catch (IOException e) { // should also never happen
                throw new RuntimeException("Error reading blob size: " +e.getMessage(), e);
            }
View Full Code Here


            throws ObjectNotInLowlevelStorageException {
        BlobStoreConnection connection = null;
        try {
            URI blobId = getBlobId(key);
            connection = getConnection(store, null);
            Blob blob = getBlob(connection, blobId, null);
            if (exists(blob)) {
                delete(blob);
            } else {
                throw new ObjectNotInLowlevelStorageException("Object not found in low-level storage: " + key);
            }
View Full Code Here

            throws LowlevelStorageException {
        BlobStoreConnection connection = null;
        try {
            URI blobId = getBlobId(key);
            connection = getConnection(store, hints);
            Blob blob = getBlob(connection, blobId, null);
            if (exists(blob)) {
                if (forceSafeOverwrite) {
                    safeOverwrite(blob, content);
                } else {
                    // leave it to the store impl to ensure atomicity
                    OutputStream out = openOutputStream(blob, -1, true);
                    copy(content, out);
                }
            } else {
                throw new ObjectNotInLowlevelStorageException("Object not found in low-level storage: " + key);
            }
            try {
                return blob.getSize();
            } catch (MissingBlobException e) { // should never happen
                throw new RuntimeException("Missing blob after replcaing the blob: " +e.getMessage(), e);
            } catch (IOException e) { // should also never happen
                throw new RuntimeException("Error reading blob size: " +e.getMessage(), e);
            }
View Full Code Here

    private static void safeOverwrite(Blob origBlob, InputStream content) {
        BlobStoreConnection connection = origBlob.getConnection();
        String origId = origBlob.getId().toString();

        // write new content to origId/new
        Blob newBlob = null;
        try {
            newBlob = connection.getBlob(new URI(origId + "/new"), null);
            copy(content, newBlob.openOutputStream(-1, false));
        } catch (Throwable th) {
            // any error or exception here is an unrecoverable fault
            throw new FaultException(th);
        }

        // At this point, we have origId (with old content) and origId/new

        // rename origId to origId/old
        Blob oldBlob = null;
        try {
            oldBlob = rename(origBlob, origId + "/old");
        } finally {
            if (oldBlob == null) {
                // rename failed; attempt recovery before throwing the fault
                try {
                    delete(newBlob);
                } catch (Throwable th) {
                    logger.error("Failed to delete " + newBlob.getId() + " while"
                              + " recovering from rename failure during safe"
                              + " overwrite", th);
                }
            }
        }

        // At this point, we have origId/old and origId/new

        // rename origId/new to origId
        boolean successful = false;
        try {
            rename(newBlob, origId);
            successful = true;
        } finally {
            if (!successful) {
                // rename failed; attempt recovery before throwing the fault
                try {
                    rename(oldBlob, origId);
                } catch (Throwable th) {
                    logger.error("Failed to rename " + oldBlob.getId() + " to "
                              + origId + " while recovering from rename"
                              + " failure during safe overwrite", th);
                }
                try {
                    newBlob.delete();
                } catch (Throwable th) {
                    logger.error("Failed to delete " + newBlob.getId()
                              + " while recovering from rename"
                              + " failure during safe overwrite", th);
                }
            }
        }

        // At this point, we have origId (with new content) and origId/old

        // remove origId/old; we don't need it anymore
        try {
            delete(oldBlob);
        } catch (Throwable th) {
            logger.error("Failed to delete " + oldBlob.getId()
                    + " while cleaning up after committed"
                    + " safe overwrite", th);
        }
    }
View Full Code Here

        InputStream content = null;
        boolean successful = false;
        try {
            URI blobId = getBlobId(key);
            connection = getConnection(store, null);
            Blob blob = getBlob(connection, blobId, null);
            content = openInputStream(blob);
            successful = true;
            return new ConnectionClosingInputStream(connection, content);
        } catch (MissingBlobException e) {
            throw new ObjectNotInLowlevelStorageException("Object not found in low-level storage: " + key);
View Full Code Here

        BlobStoreConnection connection = null;
        boolean successful = false;
        try {
            URI blobId = getBlobId(key);
            connection = getConnection(store, null);
            Blob blob = getBlob(connection, blobId, null);
            return blob.getSize();
        } catch (MissingBlobException e) {
            throw new ObjectNotInLowlevelStorageException("Object not found in low-level storage: " + key);
        } catch (IOException e) { // should never happen
            throw new RuntimeException("Error reading blob size: " +e.getMessage(), e);
        } finally {
View Full Code Here

TOP

Related Classes of org.akubraproject.Blob

Copyright © 2018 www.massapicom. 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.