/*
 *    GeoTools - OpenSource mapping toolkit
 *    http://geotools.org
 *    (C) 2003-2006, Geotools Project Managment Committee (PMC)
 *    (C) 2001, Institut de Recherche pour le Développement
 *
 *    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.
 */
package org.geotools.image.io;

// Input/output
import java.io.IOException;
import java.io.OutputStream;
import javax.imageio.stream.ImageOutputStream;


/**
 * Wraps an {@link ImageOutputStream} into a standard {@link OutputStream}.
 *
 * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/coverageio/src/main/java/org/geotools/image/io/OutputStreamAdapter.java $
 * @version $Id: OutputStreamAdapter.java 25467 2007-05-08 16:30:30Z desruisseaux $
 * @author Martin Desruisseaux
 */
final class OutputStreamAdapter extends OutputStream {
    /**
     * The wrapped image output stream.
     */
    private final ImageOutputStream output;

    /**
     * Construct a new output stream.
     */
    public OutputStreamAdapter(final ImageOutputStream output) {
        this.output = output;
    }

    /**
     * Writes the specified byte to this output stream.
     *
     * @throws IOException if an I/O error occurs.
     */
    public void write(final int b) throws IOException {
        output.write(b);
    }

    /**
     * Writes {@code b.length} bytes from the specified byte array.
     *
     * @throws IOException if an I/O error occurs.
     */
    public void write(final byte[] b) throws IOException {
        output.write(b);
    }

    /**
     * Writes {@code len} bytes from the specified byte array.
     *
     * @throws IOException if an I/O error occurs.
     */
    public void write(final byte[] b, final int off, final int len) throws IOException {
        output.write(b, off, len);
    }

    /**
     * Forces any buffered output bytes to be written out.
     *
     * @throws IOException if an I/O error occurs.
     */
    public void flush() throws IOException {
        output.flush();
    }

    /**
     * Closes this output stream.
     *
     * @throws IOException if an I/O error occurs.
     */
    public void close() throws IOException {
        output.close();
    }
}
