001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2001, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.image.io;
018:
019: // Input/output
020: import java.io.IOException;
021: import java.io.InputStream;
022: import javax.imageio.stream.ImageInputStream;
023:
024: /**
025: * Wraps an {@link ImageInputStream} into a standard {@link InputStream}.
026: *
027: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/coverageio/src/main/java/org/geotools/image/io/InputStreamAdapter.java $
028: * @version $Id: InputStreamAdapter.java 25467 2007-05-08 16:30:30Z desruisseaux $
029: * @author Martin Desruisseaux
030: */
031: final class InputStreamAdapter extends InputStream {
032: /**
033: * The wrapped image input stream.
034: */
035: private final ImageInputStream input;
036:
037: /**
038: * Constructs a new input stream.
039: */
040: public InputStreamAdapter(final ImageInputStream input) {
041: this .input = input;
042: }
043:
044: /**
045: * Reads the next byte of data from the input stream.
046: *
047: * @throws IOException if an I/O error occurs.
048: */
049: public int read() throws IOException {
050: return input.read();
051: }
052:
053: /**
054: * Reads some number of bytes from the input stream.
055: *
056: * @throws IOException if an I/O error occurs.
057: */
058: public int read(final byte[] b) throws IOException {
059: return input.read(b);
060: }
061:
062: /**
063: * Reads up to {@code len} bytes of data from the input stream.
064: *
065: * @throws IOException if an I/O error occurs.
066: */
067: public int read(final byte[] b, final int off, final int len)
068: throws IOException {
069: return input.read(b, off, len);
070: }
071:
072: /**
073: * Skips over and discards {@code n} bytes of data from this input stream.
074: *
075: * @throws IOException if an I/O error occurs.
076: */
077: public long skip(final long n) throws IOException {
078: return input.skipBytes(n);
079: }
080:
081: /**
082: * Returns always {@code true}.
083: *
084: * @throws IOException if an I/O error occurs.
085: */
086: public boolean markSupported() {
087: return true;
088: }
089:
090: /**
091: * Marks the current position in this input stream.
092: *
093: * @throws IOException if an I/O error occurs.
094: */
095: public void mark(final int readlimit) {
096: input.mark();
097: }
098:
099: /**
100: * Repositions this stream to the position at the time
101: * the {@code mark} method was last called.
102: *
103: * @throws IOException if an I/O error occurs.
104: */
105: public void reset() throws IOException {
106: input.reset();
107: }
108:
109: /**
110: * Closes this input stream.
111: *
112: * @throws IOException if an I/O error occurs.
113: */
114: public void close() throws IOException {
115: input.close();
116: }
117: }
|