Package org.apache.olio.webapp.util.fs

Examples of org.apache.olio.webapp.util.fs.FileSystem


        // set proper contentType
        String mimeType = context.getMimeType(pathInfo);
        response.setContentType(mimeType);

        // Modified for DFS support
        FileSystem fs = ServiceLocator.getInstance().getFileSystem();
        /*
         * Shanti: Do not try and get image path here. Delegate to filesystem
        // look for file in default location such as WEB-INF
        String imagePath = WebappUtil.getArtifactLocalionDir() + pathInfo;
         */
        // Strip leading slash from pathInfo
        String imagePath;
        if (pathInfo.charAt(0) == '/')
            imagePath = pathInfo.substring(1);
        else
            imagePath = pathInfo;

        logger.finer("Image path = " + imagePath);
        File imageFile = new File(imagePath);

        /* Assume image exists -- This was done to reduce FileSystem interaction
        if(!fs.exists(imagePath)) {
        System.out.println ("Could not find file - " + imagePath);
        // not in default location, look in upload location
        imageFile=new File(context.getRealPath("artifacts/" + pathInfo));
        if (!fs.exists(imageFile.getCanonicalPath())) {
        WebappUtil.getLogger().log(Level.SEVERE, "image_does_not_exist", imageFile.getCanonicalPath());
        return null;
        }
        }
         ** End mod */

        FileInputStream fis = null;
        FileChannel in = null;
        WritableByteChannel out = null;

        // serve up image from proper location
        // Use local file system if the image is in default location.
        logger.finer("AcessArtifact -- imagePath = " + imagePath);
        InputStream is = null;
        try {
            is = fs.open(imagePath);
        } catch (FileNotFoundException nfe) {
            logger.severe("File not found - imagePath = " + imagePath);
        } catch (IOException ioe) {
            logger.severe("IOException - imagePath = " + imagePath);
        }
        if (is == null) {
            logger.severe("Could not open image: " + imagePath);
        } else {
            if (is instanceof FileInputStream) {
                logger.finer("Streaming from file --");
                try {
                    // NIO transferTo takes the slow route since we are passing along a wrapped
                    // buffer rather than the Socket output stream.
                    // From experiments we did, it looks like
                    // Using traditional I/O is more efficient than using NIO in our case - for
                    // small files.
                    /*
                    fis = (FileInputStream) (is);
                    in = fis.getChannel();
                    out = Channels.newChannel(response.getOutputStream());
                    in.transferTo(0, in.size(), out);
                     * */
                    byte[] buf = tlBuf.get();
                    int count;
                    while ((count = is.read(buf)) != -1) {
                        response.getOutputStream().write(buf, 0, count);
                    }
                } finally {
                    WebappUtil.closeIgnoringException(in);
                    WebappUtil.closeIgnoringException(fis);
                    WebappUtil.closeIgnoringException(out);
                }
            } else {
                if (bDebug) {
                    System.out.println("Not a FileInputStream");
                }
                InputStream iStream = null;
                try {
                    OutputStream oStream = response.getOutputStream();
                    iStream = fs.open(imageFile.getCanonicalPath());
                    // With the current implementation, we only support FS, so this is a plcae holder.
                    // TODO - Optimize this (if required) when DFS is supported
                    byte[] buffer = new byte[4096];
                    int len;
                    while ((len = iStream.read(buffer)) != -1) {
View Full Code Here


    }
    /** Creates a new instance of ImageScaler */
    public ImageScaler(String imagePath) throws IOException {
        // Addded for DFS support
        // if we use Hadoop or Mogile, we need to get the image from the remote store
        FileSystem fs = ServiceLocator.getInstance().getFileSystem();
        InputStream iStream = fs.open(imagePath);
        this.image = ImageIO.read(iStream);
        try {
            iStream.close();
        }
        catch (Exception e) {}
View Full Code Here

            this.image = idecoder.decodeAsBufferedImage();
        }
    }
   
    public void write (String path) throws IOException {
        FileSystem fs = ServiceLocator.getInstance().getFileSystem();
        OutputStream oStream = fs.create(path);
        ImageIO.write(image, format, oStream);
        try {
            oStream.close();
        }
        catch (Exception e) {}
View Full Code Here

        this.thumbWidth = width;
        this.thumbHeight = height;
       
        // Added for for DFS support
        // if we use Hadoop or Mogile, we need to get the image from the remote store
        FileSystem fs = ServiceLocator.getInstance().getFileSystem();
        InputStream iStream = fs.open(imagePath);
        this.image = ImageIO.read(iStream);
        try {
            iStream.close();
        }
        catch (Exception e) {}
View Full Code Here

        BufferedImage bThumb = new BufferedImage(thumbWidth, thumbHeight, image.getType());
    bThumb.getGraphics().drawImage(image.getScaledInstance(thumbWidth, thumbHeight,
                Image.SCALE_FAST), 0, 0, thumbWidth, thumbHeight, null);
       
    // Store image based on local of distributed files systems
        FileSystem fs = ServiceLocator.getInstance().getFileSystem();
        OutputStream oStream = fs.create(to);
        ImageIO.write(bThumb, format, oStream);
   
        try {
            oStream.close();
        }
View Full Code Here

                AffineTransformOp.TYPE_BILINEAR);
        op.filter(image, th);

        // Added for distributed file system support
        // Store image based on local of distributed files systems
        FileSystem fs = ServiceLocator.getInstance().getFileSystem();
        OutputStream oStream = fs.create(to);
        ImageIO.write(th, format, oStream);

        try {
            oStream.close();
        }
View Full Code Here

    // Added for Distributed FS support
    // TO DO - Use dynamic loading.
    public FileSystem getFileSystem () throws IOException {
        String cacheKey = "filesystem";
       
        FileSystem fs = (FileSystem) cache.get(cacheKey);
       
        if (fs != null)
            return fs;
       
        synchronized (this) {
View Full Code Here

        // use name for update of session
        String itemName = item.getName();

        ServiceLocator locator = ServiceLocator.getInstance();

        FileSystem fs = locator.getFileSystem();

        logger.fine("Getting fileItem from memory - " + itemName);

        OutputStream fout = fs.create(fileName);

        // It would have been more efficient to use NIO if we are writing to
        // the local filesystem. However, since we need to support DFS,
        // a simple solution is provided.
        // TO DO: Optimize write if required.
View Full Code Here

        // use name for update of session
        String itemName = item.getName();

        ServiceLocator locator = ServiceLocator.getInstance();

        FileSystem fs = locator.getFileSystem();

        logger.fine("Getting fileItem from memory - " + itemName);

        OutputStream imgOut = null;
        OutputStream thumbOut = null;
        InputStream is = null;
        try {
            imgOut = fs.create(imageName);
            thumbOut = fs.create(thumbnailName);
        // It would have been more efficient to use NIO if we are writing to
        // the local filesystem. However, since we need to support DFS,
        // a simple solution is provided.
        // TO DO: Optimize write if required.
View Full Code Here

TOP

Related Classes of org.apache.olio.webapp.util.fs.FileSystem

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.