Package gov.lanl.adore.djatoka.io.reader

Source Code of gov.lanl.adore.djatoka.io.reader.PNMReader

/*
* Copyright (c) 2008  Los Alamos National Security, LLC.
*
* Los Alamos National Laboratory
* Research Library
* Digital Library Research & Prototyping Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

package gov.lanl.adore.djatoka.io.reader;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;

import gov.lanl.adore.djatoka.io.FormatIOException;
import gov.lanl.adore.djatoka.io.IReader;

import info.freelibrary.djatoka.io.PNMImage;

/**
* Returns BufferedImage give a PNM image InputStream or file path.
*
* @author Ryan Chute
* @author Kevin S. Clarke &lt;<a href="mailto:ksclarke@gmail.com">ksclarke@gmail.com</a>&gt;
*/
public class PNMReader implements IReader {

    /**
     * Returns a BufferedImage instance for provided image file path.
     *
     * @param aFileName absolute file path for image file
     * @return a <code>BufferedImage</code> instance for source image file
     * @throws FormatIOException
     */
    @Override
    public BufferedImage open(final String aFileName) throws FormatIOException {
        try {
            return new PNMImage(aFileName).getBufferedImage();
        } catch (final IOException details) {
            throw new FormatIOException(details);
        }
    }

    /**
     * Returns a BufferedImage instance for provided InputStream
     *
     * @param aInputStream an InputStream consisting of an image bitstream
     * @return a <code>BufferedImage</code> instance for source image InputStream
     * @throws FormatIOException
     */
    @Override
    public BufferedImage open(final InputStream aInputStream) throws FormatIOException {
        try {
            return new PNMImage(aInputStream).getBufferedImage();
        } catch (final IOException details) {
            throw new FormatIOException(details);
        }
    }

}
TOP

Related Classes of gov.lanl.adore.djatoka.io.reader.PNMReader

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.