diff options
Diffstat (limited to 'libjava/classpath/javax/imageio/stream')
12 files changed, 2502 insertions, 0 deletions
diff --git a/libjava/classpath/javax/imageio/stream/FileCacheImageInputStream.java b/libjava/classpath/javax/imageio/stream/FileCacheImageInputStream.java new file mode 100644 index 00000000000..40fed63af01 --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/FileCacheImageInputStream.java @@ -0,0 +1,109 @@ +/* FileCacheImageInputStream.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + +/** + * @author Michael Koch (konqueror@gmx.de) + */ +public class FileCacheImageInputStream extends ImageInputStreamImpl +{ + private InputStream stream; + private File cacheDir; + + public FileCacheImageInputStream(InputStream stream, File cacheDir) + throws IOException + { + super(); + this.stream = stream; + // FIXME: We do not support caching yet. + this.cacheDir = cacheDir; + } + + public void close() + throws IOException + { + if (stream != null) + { + stream.close(); + stream = null; + } + } + + private void checkStreamClosed() + throws IOException + { + if (stream == null) + throw new IOException("stream closed"); + } + + public boolean isCached() + { + return true; + } + + public boolean isCachedFile() + { + return true; + } + + public boolean isCachedMemory() + { + return false; + } + + public int read() + throws IOException + { + checkStreamClosed(); + setBitOffset(0); + return stream.read(); + } + + public int read(byte[] data, int offset, int len) + throws IOException + { + checkStreamClosed(); + setBitOffset(0); + return stream.read(data, offset, len); + } +} diff --git a/libjava/classpath/javax/imageio/stream/FileCacheImageOutputStream.java b/libjava/classpath/javax/imageio/stream/FileCacheImageOutputStream.java new file mode 100644 index 00000000000..16cd0a7a95e --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/FileCacheImageOutputStream.java @@ -0,0 +1,123 @@ +/* FileCacheImageOutputStream.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; + +/** + * @author Michael Koch (konqueror@gmx.de) + */ +public class FileCacheImageOutputStream extends ImageOutputStreamImpl +{ + private OutputStream stream; + private File cacheDir; + + public FileCacheImageOutputStream(OutputStream stream, File cacheDir) + throws IOException + { + super(); + this.stream = stream; + // FIXME: We do not support caching yet. + this.cacheDir = cacheDir; + } + + public void close() + throws IOException + { + if (stream != null) + { + stream.close(); + stream = null; + } + } + + private void checkStreamClosed() + throws IOException + { + if (stream == null) + throw new IOException("stream closed"); + } + + public boolean isCached() + { + return true; + } + + public boolean isCachedFile() + { + return true; + } + + public boolean isCachedMemory() + { + return false; + } + + public int read() + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public int read(byte[] data, int offset, int len) + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public void write(byte[] data, int offset, int len) + throws IOException + { + checkStreamClosed(); + // FIXME: Flush pending bits. + stream.write(data, offset, len); + } + + public void write(int value) + throws IOException + { + checkStreamClosed(); + // FIXME: Flush pending bits. + stream.write(value); + } +} diff --git a/libjava/classpath/javax/imageio/stream/FileImageInputStream.java b/libjava/classpath/javax/imageio/stream/FileImageInputStream.java new file mode 100644 index 00000000000..4fa1ac8a3dc --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/FileImageInputStream.java @@ -0,0 +1,108 @@ +/* FileImageInputStream.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; + +/** + * @author Michael Koch (konqueror@gmx.de) + */ +public class FileImageInputStream extends ImageInputStreamImpl +{ + private RandomAccessFile file; + + public FileImageInputStream(File file) + throws FileNotFoundException, IOException + { + if (file == null) + throw new IllegalArgumentException ("file may not be null"); + + this.file = new RandomAccessFile(file, "r"); + } + + public FileImageInputStream(RandomAccessFile file) + { + if (file == null) + throw new IllegalArgumentException ("file may not be null"); + + this.file = file; + } + + public void close() + throws IOException + { + file.close(); + } + + public long length() + { + try + { + return file.length(); + } + catch (IOException e) + { + return -1L; + } + } + + public int read() + throws IOException + { + setBitOffset(0); + return file.read(); + } + + public int read(byte[] data, int offset, int len) + throws IOException + { + setBitOffset(0); + return file.read(data, offset, len); + } + + public void seek(long position) + throws IOException + { + super.seek(position); + file.seek(position); + } +} diff --git a/libjava/classpath/javax/imageio/stream/FileImageOutputStream.java b/libjava/classpath/javax/imageio/stream/FileImageOutputStream.java new file mode 100644 index 00000000000..e1ce5c25eec --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/FileImageOutputStream.java @@ -0,0 +1,133 @@ +/* FileImageOutputStream.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; + +/** + * @author Michael Koch (konqueror@gmx.de) + */ +public class FileImageOutputStream extends ImageOutputStreamImpl +{ + private RandomAccessFile file; + + public FileImageOutputStream(File file) + throws FileNotFoundException, IOException + { + if (file == null) + throw new IllegalArgumentException("file may not be null"); + + // Do security check. + file.canRead(); + + this.file = new RandomAccessFile(file, "r"); + } + + public FileImageOutputStream(RandomAccessFile file) + { + if (file == null) + throw new IllegalArgumentException("file may not be null"); + + this.file = file; + } + + public void close() + throws IOException + { + file.close(); + } + + public long length() + { + try + { + return file.length(); + } + catch (IOException e) + { + return -1L; + } + } + + public int read() + throws IOException + { + checkClosed(); + + setBitOffset(0); + return file.read(); + } + + public int read(byte[] data, int offset, int len) + throws IOException + { + checkClosed(); + + setBitOffset(0); + return file.read(data, offset, len); + } + + public void seek(long position) + throws IOException + { + super.seek(position); + file.seek(position); + } + + public void write(byte[] data, int offset, int len) + throws IOException + { + checkClosed(); + + flushBits(); + file.write(data, offset, len); + } + + public void write(int value) + throws IOException + { + checkClosed(); + + // FIXME: Flush pending bits. + file.write(value); + } +} diff --git a/libjava/classpath/javax/imageio/stream/IIOByteBuffer.java b/libjava/classpath/javax/imageio/stream/IIOByteBuffer.java new file mode 100644 index 00000000000..f783653a78b --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/IIOByteBuffer.java @@ -0,0 +1,94 @@ +/* IIOByteBuffer.java + Copyright (C) 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +/** + * A data structure for holding a reference to a byte array, an index + * into that array, and a number of bytes, that can be passed to one + * specific variant of the {@link + * javax.imageio.stream.ImageInputStream#readBytes(IIOByteBuffer, int) + * readBytes} method. + * + * @since 1.4 + * + * @author Sascha Brawer (brawer@dandelis.ch) + */ +public class IIOByteBuffer +{ + private byte[] data; + private int offset; + private int length; + + public IIOByteBuffer(byte[] data, int offset, int length) + { + this.data = data; + this.offset = offset; + this.length = length; + } + + public byte[] getData() + { + return data; + } + + public void setData(byte[] data) + { + this.data = data; + } + + public int getOffset() + { + return offset; + } + + public void setOffset(int offset) + { + this.offset = offset; + } + + public int getLength() + { + return length; + } + + public void setLength(int length) + { + this.length = length; + } +} diff --git a/libjava/classpath/javax/imageio/stream/ImageInputStream.java b/libjava/classpath/javax/imageio/stream/ImageInputStream.java new file mode 100644 index 00000000000..ec39fd3294e --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/ImageInputStream.java @@ -0,0 +1,650 @@ +/* ImageInputStream.java + Copyright (C) 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.DataInput; +import java.io.IOException; +import java.nio.ByteOrder; + + +/** + * An input stream for use by {@link javax.imageio.ImageReader + * ImageReaders}. + * + * @since 1.4 + * + * @author Sascha Brawer (brawer@dandelis.ch) + */ +public interface ImageInputStream + extends DataInput +{ + void setByteOrder(ByteOrder order); + + ByteOrder getByteOrder(); + + int read() + throws IOException; + + int read(byte[] b) + throws IOException; + + int read(byte[] b, int offset, int length) + throws IOException; + + + /** + * Reads up to a specified number of bytes, and modifies a + * {@link IIOByteBuffer} to hold the read data. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @param buf an <code>IIOByteBuffer</code> that will hold the read + * data. + * + * @param numBytes the maximum number of bytes to read. + * + * @throws IndexOutOfBoundsException if <code>numBytes</code> is + * negative. + * + * @throws NullPointerException if <code>buf</code> is + * <code>null</code>. + * + * @throws IOException if some general problem happens with + * accessing data. + */ + void readBytes(IIOByteBuffer buf, int numBytes) + throws IOException; + + + /** + * Reads a byte and checks whether or not its value is zero. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before the byte is read. + * + * @throws EOFException if the input stream is at its end. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readBit() + * @see #readByte() + * @see #readFully(byte[], int, int) + */ + boolean readBoolean() + throws IOException; + + + /** + * Reads a signed byte. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @throws EOFException if the input stream is at its end. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readUnsignedByte() + * @see #readFully(byte[], int, int) + */ + byte readByte() + throws IOException; + + + /** + * Reads an unsigned byte. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @throws EOFException if the input stream is at its end. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readByte() + * @see #readFully(byte[], int, int) + */ + int readUnsignedByte() + throws IOException; + + + /** + * Reads an signed 16-bit integer. If necessary, the value gets + * converted from the stream’s {@linkplain #getByteOrder() + * current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @throws EOFException if the input stream ends before all two + * bytes were read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readUnsignedShort() + * @see #readChar() + * @see #readFully(short[], int, int) + */ + short readShort() + throws IOException; + + + /** + * Reads an unsigned 16-bit integer. If necessary, the value gets + * converted from the stream’s {@linkplain #getByteOrder() + * current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * <p>This method does the same as {@link #readChar()}. + * + * @throws EOFException if the input stream ends before all two + * bytes were read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readShort() + * @see #readChar() + * @see #readFully(char[], int, int) + */ + int readUnsignedShort() + throws IOException; + + + /** + * Reads an unsigned 16-bit integer. If necessary, the value gets + * converted from the stream’s {@linkplain #getByteOrder() + * current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * <p>This method does the same as {@link #readUnsignedShort()}. + * + * @throws EOFException if the input stream ends before all two + * bytes were read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readFully(char[], int, int) + */ + char readChar() + throws IOException; + + + /** + * Reads a signed 32-bit integer. If necessary, the value gets + * converted from the stream’s {@linkplain #getByteOrder() + * current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @throws EOFException if the input stream ends before all four + * bytes were read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readUnsignedInt() + * @see #readFully(int[], int, int) + */ + int readInt() + throws IOException; + + + /** + * Reads an unsigned 32-bit integer. If necessary, the value gets + * converted from the stream’s {@linkplain #getByteOrder() + * current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @throws EOFException if the input stream ends before all four + * bytes were read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readInt() + * @see #readFully(int[], int, int) + */ + long readUnsignedInt() + throws IOException; + + + /** + * Reads a signed 64-bit integer. If necessary, the value gets + * converted from the stream’s {@linkplain #getByteOrder() + * current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @throws EOFException if the input stream ends before all eight + * bytes were read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readFully(long[], int, int) + */ + long readLong() + throws IOException; + + + /** + * Reads an IEEE 32-bit single-precision floating point number. If + * necessary, the value gets converted from the stream’s + * {@linkplain #getByteOrder() current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @throws EOFException if the input stream ends before all four + * bytes were read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readFully(float[], int, int) + */ + float readFloat() + throws IOException; + + + /** + * Reads an IEEE 64-bit double-precision floating point number. If + * necessary, the value gets converted from the stream’s + * {@linkplain #getByteOrder() current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @throws EOFException if the input stream ends before all eight + * bytes were read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readFully(double[], int, int) + */ + double readDouble() + throws IOException; + + String readLine() + throws IOException; + + String readUTF() + throws IOException; + + + /** + * Reads a sequence of signed 8-bit integers into a + * <code>byte[]</code> array. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @param b an array for storing the read values. + * + * @param offset the index of the first element in <code>b</code> + * that will hold read data. + * + * @param numBytes the number of bytes to read. + * + * @throws IndexOutOfBoundsException if <code>offset</code> or + * <code>numBytes</code> is negative, or if <code>offset + + * numBytes</code> exceeds <code>b.length</code>. + * + * @throws NullPointerException if <code>b</code> is + * <code>null</code>. + * + * @throws EOFException if the input stream ends before all content + * was read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readByte() + */ + void readFully(byte[] b, int offset, int numBytes) + throws IOException; + + + /** + * Reads a sequence of signed 8-bit integers into a + * <code>byte[]</code> array. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @param b an array for storing the read values. + * + * @throws NullPointerException if <code>b</code> is + * <code>null</code>. + * + * @throws EOFException if the input stream ends before all content + * was read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readByte() + * @see #readFully(byte[], int, int) + */ + void readFully(byte[] b) + throws IOException; + + + /** + * Reads a sequence of signed 16-bit integers into a + * <code>short[]</code> array. If necessary, values are converted + * from the stream’s {@linkplain #getByteOrder() current byte + * order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @param s an array for storing the read values. + * + * @param offset the index of the first element in <code>s</code> + * that will hold read data. + * + * @param numShorts the number of signed 16-bit integers to read + * (which is one half of the number of bytes). + * + * @throws IndexOutOfBoundsException if <code>offset</code> or + * <code>numShorts</code> is negative, or if <code>offset + + * numShorts</code> exceeds <code>s.length</code>. + * + * @throws NullPointerException if <code>s</code> is + * <code>null</code>. + * + * @throws EOFException if the input stream ends before all content + * was read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readShort() + */ + void readFully(short[] s, int offset, int numShorts) + throws IOException; + + + /** + * Reads a sequence of unsigned 16-bit integers into a + * <code>char[]</code> array. If necessary, values are converted + * from the stream’s {@linkplain #getByteOrder() current byte + * order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @param c an array for storing the read values. + * + * @param offset the index of the first element in <code>c</code> + * that will hold read data. + * + * @param numChars the number of unsigned 16-bit integers to read + * (which is one half of the number of bytes). + * + * @throws IndexOutOfBoundsException if <code>offset</code> or + * <code>numChars</code> is negative, or if <code>offset + + * numChars</code> exceeds <code>c.length</code>. + * + * @throws NullPointerException if <code>c</code> is + * <code>null</code>. + * + * @throws EOFException if the input stream ends before all content + * was read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readChar() + */ + void readFully(char[] c, int offset, int numChars) + throws IOException; + + + /** + * Reads a sequence of signed 32-bit integers into a + * <code>long[]</code> array. If necessary, values are converted + * from the stream’s {@linkplain #getByteOrder() current byte + * order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @param i an array for storing the read values. + * + * @param offset the index of the first element in <code>i</code> + * that will hold read data. + * + * @param numLongs the number of signed 32-bit integers to read + * (which is one fourth of the number of bytes). + * + * @throws IndexOutOfBoundsException if <code>offset</code> or + * <code>numInts</code> is negative, or if <code>offset + + * numInts</code> exceeds <code>i.length</code>. + * + * @throws NullPointerException if <code>i</code> is + * <code>null</code>. + * + * @throws EOFException if the input stream ends before all content + * was read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readInt() + */ + void readFully(int[] i, int offset, int numInts) + throws IOException; + + + /** + * Reads a sequence of signed 64-bit integers into a + * <code>long[]</code> array. If necessary, values are converted + * from the stream’s {@linkplain #getByteOrder() current byte + * order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @param l an array for storing the read values. + * + * @param offset the index of the first element in <code>l</code> + * that will hold read data. + * + * @param numLongs the number of signed 64-bit integers to read + * (which is one eight of the number of bytes). + * + * @throws IndexOutOfBoundsException if <code>offset</code> or + * <code>numLongs</code> is negative, or if <code>offset + + * numLongs</code> exceeds <code>l.length</code>. + * + * @throws NullPointerException if <code>l</code> is + * <code>null</code>. + * + * @throws EOFException if the input stream ends before all content + * was read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readLong() + */ + void readFully(long[] l, int offset, int numLongs) + throws IOException; + + + /** + * Reads a sequence of IEEE 32-bit single-precision floating point + * numbers into a <code>float[]</code> array. If necessary, values + * are converted from the stream’s {@linkplain + * #getByteOrder() current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @param d an array for storing the read values. + * + * @param offset the index of the first element in <code>d</code> + * that will hold read data. + * + * @param numFloats the number of IEEE 32-bit single-precision + * floating point numbers to read (which is one fourth of the number + * of bytes). + * + * @throws IndexOutOfBoundsException if <code>offset</code> or + * <code>numFloats</code> is negative, or if <code>offset + + * numFloats</code> exceeds <code>f.length</code>. + * + * @throws NullPointerException if <code>f</code> is + * <code>null</code>. + * + * @throws EOFException if the input stream ends before all content + * was read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readFloat() + */ + void readFully(float[] f, int offset, int numFloats) + throws IOException; + + + /** + * Reads a sequence of IEEE 64-bit double-precision floating point + * numbers into a <code>double[]</code> array. If necessary, values + * are converted from the stream’s {@linkplain + * #getByteOrder() current byte order}. + * + * <p>The {@linkplain #getBitOffset() bit offset} is set to zero + * before any data is read. + * + * @param d an array for storing the read values. + * + * @param offset the index of the first element in <code>d</code> + * that will hold read data. + * + * @param numDoubles the number of IEEE 64-bit double-precision + * floating point numbers to read (which is one eight of the number + * of bytes). + * + * @throws IndexOutOfBoundsException if <code>offset</code> or + * <code>numDoubles</code> is negative, or if <code>offset + + * numDoubles</code> exceeds <code>d.length</code>. + * + * @throws NullPointerException if <code>d</code> is + * <code>null</code>. + * + * @throws EOFException if the input stream ends before all content + * was read. + * + * @throws IOException if some general problem happens with + * accessing data. + * + * @see #readDouble() + */ + void readFully(double[] d, int offset, int numDoubles) + throws IOException; + + long getStreamPosition() + throws IOException; + + int getBitOffset() + throws IOException; + + void setBitOffset(int bitOffset) + throws IOException; + + int readBit() + throws IOException; + + long readBits(int numBits) + throws IOException; + + long length() + throws IOException; + + int skipBytes(int numBytes) + throws IOException; + + long skipBytes(long numBytes) + throws IOException; + + void seek(long pos) + throws IOException; + + void mark(); + + void reset() + throws IOException; + + void flushBefore(long pos) + throws IOException; + + void flush() + throws IOException; + + long getFlushedPosition(); + + boolean isCached(); + + boolean isCachedMemory(); + + boolean isCachedFile(); + + void close() + throws IOException; +} diff --git a/libjava/classpath/javax/imageio/stream/ImageInputStreamImpl.java b/libjava/classpath/javax/imageio/stream/ImageInputStreamImpl.java new file mode 100644 index 00000000000..0967fee467a --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/ImageInputStreamImpl.java @@ -0,0 +1,515 @@ +/* ImageInputStream.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.DataInputStream; +import java.io.EOFException; +import java.io.IOException; +import java.nio.ByteOrder; +import java.util.Stack; + +/** + * @author Michael Koch (konqueror@gmx.de) + */ +public abstract class ImageInputStreamImpl implements ImageInputStream +{ + private boolean closed; + private Stack markStack = new Stack(); + + byte[] buffer = new byte[8]; + + protected int bitOffset; + protected ByteOrder byteOrder; + protected long flushedPos; + protected long streamPos; + + public ImageInputStreamImpl() + { + // Do nothing here. + } + + protected final void checkClosed() + throws IOException + { + if (closed) + throw new IOException("stream closed"); + } + + public void close() + throws IOException + { + checkClosed(); + closed = true; + } + + protected void finalize() + throws Throwable + { + close(); + } + + public void flush() + throws IOException + { + flushBefore(getStreamPosition()); + } + + public void flushBefore(long position) + throws IOException + { + if (position < flushedPos) + throw new IndexOutOfBoundsException(); + + if (position > streamPos) + throw new IndexOutOfBoundsException(); + + flushedPos = position; + } + + public int getBitOffset() + throws IOException + { + checkClosed(); + return bitOffset; + } + + public ByteOrder getByteOrder() + { + return byteOrder; + } + + public long getFlushedPosition() + { + return flushedPos; + } + + public long getStreamPosition() + throws IOException + { + checkClosed(); + return streamPos; + } + + public boolean isCached() + { + return false; + } + + public boolean isCachedFile() + { + return false; + } + + public boolean isCachedMemory() + { + return false; + } + + public long length() + { + return -1L; + } + + public void mark() + { + try + { + markStack.push(new Long(getStreamPosition())); + } + catch (IOException e) + { + // Ignored. + } + } + + public abstract int read() + throws IOException; + + public int read(byte[] data) + throws IOException + { + return read(data, 0, data.length); + } + + public abstract int read(byte[] data, int offset, int len) + throws IOException; + + public int readBit() + throws IOException + { + checkClosed(); + + // Calc new bit offset here, readByte resets it. + int newOffset = (bitOffset + 1) & 0x7; + + byte data = readByte(); + + if (bitOffset != 0) + { + seek(getStreamPosition() - 1); + data = (byte) (data >> (8 - newOffset)); + } + + bitOffset = newOffset; + return data & 0x1; + } + + public long readBits(int numBits) + throws IOException + { + checkClosed(); + + if (numBits < 0 || numBits > 64) + throw new IllegalArgumentException(); + + if (numBits == 0) + return 0L; + + long bits = 0L; + + for (int i = 0; i < numBits; i++) + { + bits <<= 1; + bits |= readBit(); + } + + return bits; + } + + public boolean readBoolean() + throws IOException + { + byte data = readByte(); + return data != 0; + } + + public byte readByte() + throws IOException + { + int data = read(); + + if (data == -1) + throw new EOFException(); + + return (byte) data; + } + + public void readBytes(IIOByteBuffer buffer, int len) + throws IOException + { + int result = read(buffer.getData(), buffer.getOffset(), len); + + if (result == -1 || result < len) + throw new EOFException(); + + buffer.setLength(len); + } + + public char readChar() + throws IOException + { + return (char) readShort(); + } + + public double readDouble() + throws IOException + { + return (double) readLong(); + } + + public float readFloat() + throws IOException + { + return (float) readInt(); + } + + public void readFully(byte[] data) + throws IOException + { + readFully(data, 0, data.length); + } + + public void readFully(byte[] data, int offset, int len) + throws IOException + { + for (int i = 0; i < len; ++i) + data[offset + i] = readByte(); + } + + public void readFully(char[] data, int offset, int len) + throws IOException + { + for (int i = 0; i < len; ++i) + data[offset + i] = readChar(); + } + + public void readFully(double[] data, int offset, int len) + throws IOException + { + for (int i = 0; i < len; ++i) + data[offset + i] = readDouble(); + } + + public void readFully(float[] data, int offset, int len) + throws IOException + { + for (int i = 0; i < len; ++i) + data[offset + i] = readFloat(); + } + + public void readFully(int[] data, int offset, int len) + throws IOException + { + for (int i = 0; i < len; ++i) + data[offset + i] = readInt(); + } + + public void readFully(long[] data, int offset, int len) + throws IOException + { + for (int i = 0; i < len; ++i) + data[offset + i] = readLong(); + } + + public void readFully(short[] data, int offset, int len) + throws IOException + { + for (int i = 0; i < len; ++i) + data[offset + i] = readShort(); + } + + public int readInt() + throws IOException + { + int result = read(buffer, 0, 4); + + if (result == -1) + throw new EOFException(); + + if (getByteOrder() == ByteOrder.LITTLE_ENDIAN) + { + return ((buffer[0] & 0xff) + + (buffer[1] << 8) + + (buffer[2] << 16) + + (buffer[3] << 24)); + } + + return ((buffer[4] << 24) + + (buffer[3] << 16) + + (buffer[2] << 8) + + (buffer[1] & 0xff)); + } + + public String readLine() + throws IOException + { + checkClosed(); + + int c = -1; + boolean eol = false; + StringBuffer buffer = new StringBuffer(); + + while (!eol && (c = read()) != -1) + { + switch(c) + { + case '\r': + // Consume following \n' + long oldPosition = getStreamPosition(); + if (read() != '\n') + seek(oldPosition); + case '\n': + eol = true; + break; + default: + buffer.append((char) c); + break; + } + } + + if (c == -1 && buffer.length() == 0) + return null; + + return buffer.toString(); + } + + public long readLong() + throws IOException + { + int result = read(buffer, 0, 8); + + if (result == -1) + throw new EOFException(); + + if (getByteOrder() == ByteOrder.LITTLE_ENDIAN) + { + return ((buffer[0] & 0xff) + + (((buffer[1] & 0xff)) << 8) + + (((buffer[2] & 0xff)) << 16) + + (((buffer[3] & 0xffL)) << 24) + + (((buffer[4] & 0xffL)) << 32) + + (((buffer[5] & 0xffL)) << 40) + + (((buffer[6] & 0xffL)) << 48) + + (((long) buffer[7]) << 56)); + } + + return ((((long) buffer[7]) << 56) + + ((buffer[6] & 0xffL) << 48) + + ((buffer[5] & 0xffL) << 40) + + ((buffer[4] & 0xffL) << 32) + + ((buffer[3] & 0xffL) << 24) + + ((buffer[2] & 0xff) << 16) + + ((buffer[1] & 0xff) << 8) + + (buffer[0] & 0xff)); + } + + public short readShort() + throws IOException + { + int result = read(buffer, 0, 2); + + if (result == -1) + throw new EOFException(); + + if (getByteOrder() == ByteOrder.LITTLE_ENDIAN) + { + return (short) ((buffer[0] & 0xff) + + (buffer[1] << 8)); + } + + return (short) ((buffer[0] << 8) + + (buffer[1] & 0xff)); + } + + public int readUnsignedByte() + throws IOException + { + return readByte() & 0xff; + } + + public long readUnsignedInt() + throws IOException + { + return readInt() & 0xffffffff; + } + + public int readUnsignedShort() + throws IOException + { + return readShort() & 0xffff; + } + + public String readUTF() + throws IOException + { + checkClosed(); + + String data; + ByteOrder old = getByteOrder(); + setByteOrder(ByteOrder.BIG_ENDIAN); // Strings are always big endian. + + try + { + data = DataInputStream.readUTF(this); + } + finally + { + setByteOrder(old); + } + + return data; + } + + public void reset() + throws IOException + { + checkClosed(); + + long mark = ((Long) markStack.pop()).longValue(); + seek(mark); + } + + public void seek(long position) + throws IOException + { + checkClosed(); + + if (position < getFlushedPosition()) + throw new IndexOutOfBoundsException("position < flushed position"); + + streamPos = position; + bitOffset = 0; + } + + public void setBitOffset (int bitOffset) + throws IOException + { + checkClosed(); + + if (bitOffset < 0 || bitOffset > 7) + throw new IllegalArgumentException(); + + this.bitOffset = bitOffset; + } + + public void setByteOrder(ByteOrder byteOrder) + { + this.byteOrder = byteOrder; + } + + public int skipBytes(int num) + throws IOException + { + checkClosed(); + + seek(getStreamPosition() + num); + bitOffset = 0; + return num; + } + + public long skipBytes(long num) + throws IOException + { + checkClosed(); + + seek(getStreamPosition() + num); + bitOffset = 0; + return num; + } +} diff --git a/libjava/classpath/javax/imageio/stream/ImageOutputStream.java b/libjava/classpath/javax/imageio/stream/ImageOutputStream.java new file mode 100644 index 00000000000..49a1bcf33be --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/ImageOutputStream.java @@ -0,0 +1,269 @@ +/* ImageOutputStream.java + Copyright (C) 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.DataOutput; +import java.io.IOException; + + +/** + * An output stream for use by {@link javax.imageio.ImageWriter + * ImageWriters}. + * + * @since 1.4 + * + * @author Sascha Brawer (brawer@dandelis.ch) + */ +public interface ImageOutputStream + extends ImageInputStream, DataOutput +{ + /** + * @param postion + * + * @throws IOException if an errror occurs + */ + void flushBefore(long position) throws IOException; + + /** + * Writes an array into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void write(byte[] data) throws IOException; + + /** + * Writes a region of data from an array into the stream. + * + * @param data the data to be written + * @param offset the offset in the array + * @param len the length in the array + * + * @throws IOException if an errror occurs + */ + void write(byte[] data, int offset, int len) throws IOException; + + /** + * Writes an <code>int</code> into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void write(int data) throws IOException; + + /** + * Writes a bit value to the stream. + * + * @throws IOException if an error occurs + */ + void writeBit(int bit) throws IOException; + + /** + * Writes a number of bit values to the stream. + * + * @throws IOException if an errror occurs + */ + void writeBits(long bits, int numBits) throws IOException; + + /** + * Writes a <code>boolean</code> value into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeBoolean(boolean data) throws IOException; + + /** + * Writes a <code>byte</code> value into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeByte(int data) throws IOException; + + /** + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeBytes(String data) throws IOException; + + /** + * Writes a character into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeChar(int data) throws IOException; + + /** + * Writes characters to the stream. + * + * @param data the data to be written + * @param offset the offset in the array + * @param len the lenth in the array + * + * @throws IOException if an errror occurs + */ + void writeChars(char[] data, int offset, int len) throws IOException; + + /** + * Writes characters from a given <code>String</code> into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeChars(String data) throws IOException; + + /** + * Writes a <code>double</code> into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeDouble(double data) throws IOException; + + /** + * Writes an array of <code>double</code> into the stream. + * + * @param data the data to be written + * @param offset the offset in the array + * @param len the lenth in the array + * + * @throws IOException if an errror occurs + */ + void writeDoubles(double[] data, int offset, int len) + throws IOException; + + /** + * Writes a <code>float</code> into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeFloat(float data) throws IOException; + + /** + * Writes an array of <code>float</code> into the stream. + * + * @param data the data to be written + * @param offset the offset in the array + * @param len the lenth in the array + * + * @throws IOException if an errror occurs + */ + void writeFloats(float[] data, int offset, int len) throws IOException; + + /** + * Writes a <code>int</code> into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeInt(int data) throws IOException; + + /** + * Writes an array of <code>int</code> into the stream. + * + * @param data the data to be written + * @param offset the offset in the array + * @param len the lenth in the array + * + * @throws IOException if an errror occurs + */ + void writeInts(int[] data, int offset, int len) throws IOException; + + /** + * Writes a <code>long</code> into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeLong(long data) throws IOException; + + /** + * Writes an array of <code>long</code> into the stream. + * + * @param data the data to be written + * @param offset the offset in the array + * @param len the lenth in the array + * + * @throws IOException if an errror occurs + */ + void writeLongs(long[] data, int offset, int len) throws IOException; + + /** + * Writes a <code>short</code> into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeShort(int data) throws IOException; + + /** + * Writes an array of <code>short</code> into the stream. + * + * @param data the data to be written + * @param offset the offset in the array + * @param len the lenth in the array + * + * @throws IOException if an errror occurs + */ + void writeShorts(short[] data, int offset, int len) throws IOException; + + /** + * Writes a <code>String</code> into the stream. + * + * @param data the data to be written + * + * @throws IOException if an errror occurs + */ + void writeUTF(String data) throws IOException; +} diff --git a/libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java b/libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java new file mode 100644 index 00000000000..c708a2368d7 --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/ImageOutputStreamImpl.java @@ -0,0 +1,245 @@ +/* ImageOutputStream.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.IOException; +import java.nio.ByteOrder; + +/** + * @author Michael Koch (konqueror@gmx.de) + */ +public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl + implements ImageOutputStream +{ + public ImageOutputStreamImpl() + { + // Do nothing here. + } + + protected void flushBits() + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public void write(byte[] data) + throws IOException + { + write(data, 0, data.length); + } + + public abstract void write(byte[] data, int offset, int len) + throws IOException; + + public abstract void write(int value) + throws IOException; + + public void writeBit(int bit) + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public void writeBits(long bits, int numBits) + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public void writeBoolean(boolean value) + throws IOException + { + writeByte(value ? 1 : 0); + } + + public void writeByte(int value) + throws IOException + { + write(value & 0xff); + } + + public void writeBytes(String data) + throws IOException + { + write(data.getBytes()); + } + + public void writeChar(int value) + throws IOException + { + writeShort((short) value); + } + + public void writeChars(char[] data, int offset, int len) + throws IOException + { + for(int i = 0; i < len; ++len) + writeChar(data[offset + i]); + } + + public void writeChars(String data) + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public void writeDouble(double value) + throws IOException + { + writeLong((long) value); + } + + public void writeDoubles(double[] data, int offset, int len) + throws IOException + { + for(int i = 0; i < len; ++len) + writeDouble(data[offset + i]); + } + + public void writeFloat(float value) + throws IOException + { + writeInt((int) value); + } + + public void writeFloats(float[] data, int offset, int len) + throws IOException + { + for(int i = 0; i < len; ++len) + writeFloat(data[offset + i]); + } + + public void writeInt(int value) + throws IOException + { + if (getByteOrder() == ByteOrder.LITTLE_ENDIAN) + { + buffer[0] = ((byte) value); + buffer[1] = ((byte) (value >> 8)); + buffer[2] = ((byte) (value >> 16)); + buffer[3] = ((byte) (value >> 24)); + } + else + { + buffer[0] = ((byte) (value >> 24)); + buffer[1] = ((byte) (value >> 16)); + buffer[2] = ((byte) (value >> 8)); + buffer[3] = ((byte) value); + } + + write(buffer, 0, 4); + } + + public void writeInts(int[] data, int offset, int len) + throws IOException + { + for(int i = 0; i < len; ++len) + writeInt(data[offset + i]); + } + + public void writeLong(long value) + throws IOException + { + if (getByteOrder() == ByteOrder.LITTLE_ENDIAN) + { + buffer[0] = ((byte) value); + buffer[1] = ((byte) (value >> 8)); + buffer[2] = ((byte) (value >> 16)); + buffer[3] = ((byte) (value >> 24)); + buffer[4] = ((byte) (value >> 32)); + buffer[5] = ((byte) (value >> 40)); + buffer[6] = ((byte) (value >> 48)); + buffer[7] = ((byte) (value >> 56)); + } + else + { + buffer[0] = ((byte) (value >> 56)); + buffer[1] = ((byte) (value >> 48)); + buffer[2] = ((byte) (value >> 40)); + buffer[3] = ((byte) (value >> 32)); + buffer[4] = ((byte) (value >> 24)); + buffer[5] = ((byte) (value >> 16)); + buffer[6] = ((byte) (value >> 8)); + buffer[7] = ((byte) value); + } + + write(buffer, 0, 8); + } + + public void writeLongs(long[] data, int offset, int len) + throws IOException + { + for(int i = 0; i < len; ++len) + writeLong(data[offset + i]); + } + + public void writeShort(int value) + throws IOException + { + if (getByteOrder() == ByteOrder.LITTLE_ENDIAN) + { + buffer[0] = ((byte) value); + buffer[1] = ((byte) (value >> 8)); + } + else + { + buffer[0] = ((byte) (value >> 8)); + buffer[1] = ((byte) value); + } + + write(buffer, 0, 2); + } + + public void writeShorts(short[] data, int offset, int len) + throws IOException + { + for(int i = 0; i < len; ++len) + writeShort(data[offset + i]); + } + + public void writeUTF(String data) + throws IOException + { + throw new Error("not implemented"); + } +} diff --git a/libjava/classpath/javax/imageio/stream/MemoryCacheImageInputStream.java b/libjava/classpath/javax/imageio/stream/MemoryCacheImageInputStream.java new file mode 100644 index 00000000000..3d9f6184697 --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/MemoryCacheImageInputStream.java @@ -0,0 +1,98 @@ +/* MemoryCacheImageInputStream.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.IOException; +import java.io.InputStream; + +/** + * @author Michael Koch (konqueror@gmx.de) + */ +public class MemoryCacheImageInputStream extends ImageInputStreamImpl +{ + private InputStream stream; + + public MemoryCacheImageInputStream(InputStream stream) + { + this.stream = stream; + } + + public void close() + throws IOException + { + super.close(); + stream.close(); + } + + public void flushBefore(long position) + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public boolean isCached() + { + return true; + } + + public boolean isCachedFile() + { + return false; + } + + public boolean isCachedMemory() + { + return true; + } + + public int read() + throws IOException + { + setBitOffset(0); + return stream.read(); + } + + public int read(byte[] data, int offset, int len) + throws IOException + { + setBitOffset(0); + return stream.read(data, offset, len); + } +} diff --git a/libjava/classpath/javax/imageio/stream/MemoryCacheImageOutputStream.java b/libjava/classpath/javax/imageio/stream/MemoryCacheImageOutputStream.java new file mode 100644 index 00000000000..8914c3305df --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/MemoryCacheImageOutputStream.java @@ -0,0 +1,112 @@ +/* MemoryCacheImageOutputStream.java -- + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package javax.imageio.stream; + +import java.io.IOException; +import java.io.OutputStream; + +/** + * @author Michael Koch (konqueror@gmx.de) + */ +public class MemoryCacheImageOutputStream extends ImageOutputStreamImpl +{ + private OutputStream stream; + + public MemoryCacheImageOutputStream(OutputStream stream) + { + this.stream = stream; + } + + public void close() + throws IOException + { + super.close(); + stream.close(); + } + + public void flushBefore(long position) + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public boolean isCached() + { + return true; + } + + public boolean isCachedFile() + { + return false; + } + + public boolean isCachedMemory() + { + return true; + } + + public int read() + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public int read (byte[] data, int offset, int len) + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + + public void write(byte[] data, int offset, int len) + throws IOException + { + // FIXME: Flush pending bits. + stream.write(data, offset, len); + } + + public void write(int value) + throws IOException + { + // FIXME: Flush pending bits. + stream.write(value); + } +} diff --git a/libjava/classpath/javax/imageio/stream/package.html b/libjava/classpath/javax/imageio/stream/package.html new file mode 100644 index 00000000000..63e53ca6501 --- /dev/null +++ b/libjava/classpath/javax/imageio/stream/package.html @@ -0,0 +1,46 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> +<!-- package.html - describes classes in javax.imageio.stream package. + Copyright (C) 2004 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath 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 +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. --> + +<html> +<head><title>GNU Classpath - javax.imageio.stream</title></head> + +<body> +<p></p> + +</body> +</html> |

