Package com.emc.vipr.transform

Examples of com.emc.vipr.transform.OutputTransform


        revFactories.addAll(factories);
        Collections.reverse(revFactories);
       
        try {
            for(TransformFactory<?, ?> t : revFactories) {
                OutputTransform ot = t.getOutputTransform(in, mMeta);
                appliedTransforms.add(ot);
                in = ot.getEncodedInputStream();
            }
        } catch(TransformException e) {
            throw new AtmosException("Could not transform data: " + e, e);
        } catch (IOException e) {
            throw new AtmosException("Error transforming data: " + e, e);
        }
       
        // Create the object
        int c = 0;
        int pos = 0;
        byte[] buffer = new byte[bufferSize];
       
        // Read the first chunk and send it with the create request.
        try {
            c = fillBuffer(buffer, in);
        } catch (IOException e) {
            throw new AtmosException("Error reading input data: " + e, e);
        }
        if(c == -1) {
            // EOF already
            request.setContent(null);
           
            // Optmization -- send metadata now with create request and return
            try {
                in.close();
            } catch (IOException e) {
                throw new AtmosException("Error closing input: " + e, e);
            }
            for(OutputTransform ot : appliedTransforms) {
                mMeta.putAll(ot.getEncodedMetadata());
            }
            Set<Metadata> metadata = request.getUserMetadata();
            if(metadata == null) {
                metadata = new HashSet<Metadata>();
            }
            updateMetadata(mMeta, metadata);
            request.setUserMetadata(metadata);
           
            return delegate.createObject(request);
        } else {
            request.setContent(new BufferSegment(buffer, 0, c));
        }
        CreateObjectResponse resp = delegate.createObject(request);
       
        pos = c;
       
        // Append until EOF.
        try {
            while((c = fillBuffer(buffer, in)) != -1) {
                UpdateObjectRequest uor = new UpdateObjectRequest();
                uor.setIdentifier(resp.getObjectId());
                uor.setContentType(request.getContentType());
                uor.setRange(new Range(pos, pos+c-1));
                uor.setContent(new BufferSegment(buffer, 0, c));
                pos += c;
                delegate.updateObject(uor);
            }
        } catch (IOException e) {
            throw new AtmosException("Error reading input data: " + e, e);
        }
       
        try {
            in.close();
        } catch (IOException e) {
            throw new AtmosException("Error closing stream: " + e, e);
        }
       
        String transformConfig = "";
        // Update the object with the transformed metadata.
        for(OutputTransform ot : appliedTransforms) {
            mMeta.putAll(ot.getEncodedMetadata());
            if(transformConfig.length() != 0) {
                transformConfig += "|";
            }
            transformConfig += ot.getTransformConfig();
        }
        mMeta.put(TransformConstants.META_TRANSFORM_MODE, transformConfig);
       
        Set<Metadata> metadata = request.getUserMetadata();
        if(metadata == null) {
View Full Code Here


        revFactories.addAll(factories);
        Collections.reverse(revFactories);
       
        try {
            for(TransformFactory<?, ?> t : revFactories) {
                OutputTransform ot = t.getOutputTransform(in, mMeta);
                appliedTransforms.add(ot);
                in = ot.getEncodedInputStream();
            }
        } catch(TransformException e) {
            throw new AtmosException("Could not transform data: " + e, e);
        } catch (IOException e) {
            throw new AtmosException("Error transforming data: " + e, e);
        }

        // Overwrite the object
        int c = 0;
        int pos = 0;
        byte[] buffer = new byte[bufferSize];
       
        // Read the first chunk and send it with the create request.
        try {
            c = fillBuffer(buffer, in);
        } catch (IOException e) {
            throw new AtmosException("Error reading input data: " + e, e);
        }
        if(c == -1) {
            // EOF already
            request.setContent(null);
           
            // Optmization -- send metadata now with create request and return
            try {
                in.close();
            } catch (IOException e) {
                throw new AtmosException("Error closing input: " + e, e);
            }
            for(OutputTransform ot : appliedTransforms) {
                mMeta.putAll(ot.getEncodedMetadata());
            }
            Set<Metadata> metadata = request.getUserMetadata();
            if(metadata == null) {
                metadata = new HashSet<Metadata>();
            }
            updateMetadata(mMeta, metadata);
            request.setUserMetadata(metadata);
           
            return delegate.updateObject(request);
        } else {
            request.setContent(new BufferSegment(buffer, 0, c));
        }
        BasicResponse resp = delegate.updateObject(request);
       
        pos = c;
       
        // Append until EOF.
        try {
            while((c = fillBuffer(buffer, in)) != -1) {
                UpdateObjectRequest uor = new UpdateObjectRequest();
                uor.setIdentifier(request.getIdentifier());
                uor.setContentType(request.getContentType());
                uor.setRange(new Range(pos, pos+c-1));
                uor.setContent(new BufferSegment(buffer, 0, c));
                pos += c;
                delegate.updateObject(uor);
            }
        } catch (IOException e) {
            throw new AtmosException("Error reading input data: " + e, e);
        }
       
        try {
            in.close();
        } catch (IOException e) {
            throw new AtmosException("Error closing stream: " + e, e);
        }
       
        String transformConfig = "";
        // Update the object with the transformed metadata.
        for(OutputTransform ot : appliedTransforms) {
            mMeta.putAll(ot.getEncodedMetadata());
            if(transformConfig.length() != 0) {
                transformConfig += "|";
            }
            transformConfig += ot.getTransformConfig();
        }
        mMeta.put(TransformConstants.META_TRANSFORM_MODE, transformConfig);
       
        Set<Metadata> metadata = request.getUserMetadata();
        if(metadata == null) {
View Full Code Here

TOP

Related Classes of com.emc.vipr.transform.OutputTransform

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.