Package com.volantis.map.common.streams

Examples of com.volantis.map.common.streams.NoFlushSeekableOutputStream


                          HttpServletResponse response) throws Exception {

        Result result = Result.UNSUPPORTED;
        NoCloseSeekableInputStream inputStream = null;
        NoCloseSeekableInputStream watermarkStream = null;
        NoFlushSeekableOutputStream outputData = null;
        final String resourceType = descriptor.getResourceType();
        if ("image".equals(resourceType) || resourceType.startsWith("image.")) {

            try {
                synchronized(lock) {
                    if (config == null) {
                        config = createConfiguration();
                    }
                }
                // merge the parameters in the ICS request with those in the
                // configuration file.
                ICSParamBuilder icsBuilder = new ICSParamBuilder();
                icsBuilder.overlayConfigurationParameters(
                        descriptor.getInputParameters(), config);
                icsBuilder.overlayEnvironmentParameters(
                        descriptor.getInputParameters(), envParams);

                // @todo perform check for supported operation type here.
                ImageProcessor processor =
                    ImageProcessorFactory.getInstance().
                        createImageProcessor(ToolFactory.getInstance(),
                                             ImageWriterFactory.getInstance());

                Representation representation =
                    ImageLoader.load(descriptor.getInputParameters().getParameterValue(ParameterNames.SOURCE_URL),
                            retriever, request, descriptor);
                inputStream = new NoCloseSeekableInputStream(representation.getSeekableInputStream());
                new PreservationParamsBuilder().process(request, descriptor);

                // now get the input stream for the watermark image.
                // @todo later this could probably be cached.
                if (descriptor.getInputParameters().containsName(
                    ParameterNames.WATERMARK_URL)) {
                    Representation watermarkRepresentation =
                        ImageLoader.load(descriptor.getInputParameters().getParameterValue(ParameterNames.WATERMARK_URL),
                                retriever, request, descriptor);
                    watermarkStream =
                        new NoCloseSeekableInputStream(watermarkRepresentation.getSeekableInputStream());
                    descriptor.getInputParameters().setObject(
                        ParameterNames.WATERMARK_INPUT_STREAM, watermarkStream);
                }

                outputData =
                    new NoFlushSeekableOutputStream(response.getOutputStream());

                processor.process(new NoCloseSeekableInputStream(inputStream),
                                  outputData,
                                  descriptor.getInputParameters());

                // Set the expiry header for the cache
                setCacheData(response, representation.getCacheInfo());

                // Set the content type header
                response.setContentType(
                        descriptor.getInputParameters().getParameterValue(
                                ParameterNames.OUTPUT_IMAGE_MIME_TYPE));
                response.setContentLength((int)outputData.getStreamPosition());


                // Now we may safely flush and close the output
                // yes we really do need to flush it AND close it.
                outputData.flushDelegate();
                outputData.closeDelegate();

                return Result.SUCCESS;
            } finally {
                // make sure we close these streams as they could be holding
                // files open
View Full Code Here

TOP

Related Classes of com.volantis.map.common.streams.NoFlushSeekableOutputStream

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.