From 42b143f8e2002d1d01907e490d5a5025c34c7be2 Mon Sep 17 00:00:00 2001 From: green Date: Mon, 7 Feb 2005 13:22:36 +0000 Subject: [PATCH] 2005-02-06 Jerry Quinn * javax/imageio/metadata/IIOMetadataNode.java: Implemented. * javax/imageio/metadata/IIOAttr.java, javax/imageio/metadata/IIONamedNodeMap.java, javax/imageio/metadata/IIONodeList.java: New files 2005-02-06 Graydon Hoare * gnu/java/awt/ClasspathToolkit.java (registerImageIOSpis): New method. * javax/imageio/ImageIO.java (WriterFormatFilter.filter): Fix copy-and-paste typos. (WriterMIMETypeFilter.filter): Likewise. (ImageReaderIterator): Pass extension argument through to SPI. (getReadersByFilter): Likewise. (getWritersByFilter): Likewise. (getImageReadersByFormatName): Likewise. (getImageReadersByMIMEType): Likewise. (getImageReadersBySuffix): Likewise. (getImageWritersByFormatName): Likewise. (getImageWritersByMIMEType): Likewise. (getImageWritersBySuffix): Likewise. (read): Implement. (write): Implement. * javax/imageio/ImageReader.java (progressListeners): Initialize. (setInput): Implement. * javax/imageio/ImageWriter.java (progressListeners): Initialize. (warningListeners): Likewise. (warningLocales): Likewise. (setOutput): Test "isInstance" rather than class equality. * javax/imageio/spi/IIORegistry.java (static): Add reader and writer SPIs. (IIORegistry): Call ClasspathToolkit.registerImageIOSpis. 2004-02-06 Michael Koch * javax/imageio/metadata/IIOInvalidTreeException.java (IIOInvalidTreeException): Reformatted. * javax/imageio/spi/IIORegistry.java (static): Register ImageReaderSpi.class and ImageWriterSpi.class. * javax/imageio/stream/MemoryCacheImageInputStream.java: Reworked import statements. 2004-02-06 Michael Koch * javax/imageio/stream/FileImageOutputStream.java: Implemented. 2004-02-06 Michael Koch * javax/imageio/stream/FileCacheImageInputStream.java, javax/imageio/stream/FileCacheImageOutputStream.java, javax/imageio/stream/FileImageInputStream.java, javax/imageio/stream/ImageInputStreamImpl.java, javax/imageio/stream/ImageOutputStreamImpl.java, javax/imageio/stream/MemoryCacheImageInputStream.java, javax/imageio/stream/MemoryCacheImageOutputStream.java: Added all missing methods in javax.imageio.stream. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@94698 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/ChangeLog | 64 +++ libjava/javax/imageio/IIOParam.java | 14 + libjava/javax/imageio/ImageIO.java | 146 +++++- libjava/javax/imageio/ImageReadParam.java | 16 + libjava/javax/imageio/ImageReader.java | 39 +- libjava/javax/imageio/ImageWriter.java | 13 +- libjava/javax/imageio/metadata/IIOAttr.java | 378 ++++++++++++++ .../imageio/metadata/IIOInvalidTreeException.java | 13 +- .../javax/imageio/metadata/IIOMetadataNode.java | 549 +++++++++++++++++++++ .../javax/imageio/metadata/IIONamedNodeMap.java | 138 ++++++ libjava/javax/imageio/metadata/IIONodeList.java | 72 +++ libjava/javax/imageio/spi/IIORegistry.java | 8 +- .../imageio/stream/FileCacheImageInputStream.java | 18 +- .../imageio/stream/FileCacheImageOutputStream.java | 32 +- .../javax/imageio/stream/FileImageInputStream.java | 23 +- .../imageio/stream/FileImageOutputStream.java | 45 +- .../javax/imageio/stream/ImageInputStreamImpl.java | 360 +++++++++++++- .../imageio/stream/ImageOutputStreamImpl.java | 180 +++++++ .../stream/MemoryCacheImageInputStream.java | 40 +- .../stream/MemoryCacheImageOutputStream.java | 54 +- 20 files changed, 2162 insertions(+), 40 deletions(-) create mode 100644 libjava/javax/imageio/metadata/IIOAttr.java create mode 100644 libjava/javax/imageio/metadata/IIONamedNodeMap.java create mode 100644 libjava/javax/imageio/metadata/IIONodeList.java diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 1ee4076..b294c0b 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,67 @@ +2005-02-06 Jerry Quinn + + * javax/imageio/metadata/IIOMetadataNode.java: + Implemented. + * javax/imageio/metadata/IIOAttr.java, + javax/imageio/metadata/IIONamedNodeMap.java, + javax/imageio/metadata/IIONodeList.java: + New files + +2005-02-06 Graydon Hoare + + * gnu/java/awt/ClasspathToolkit.java + (registerImageIOSpis): New method. + * javax/imageio/ImageIO.java + (WriterFormatFilter.filter): Fix copy-and-paste typos. + (WriterMIMETypeFilter.filter): Likewise. + (ImageReaderIterator): Pass extension argument through to SPI. + (getReadersByFilter): Likewise. + (getWritersByFilter): Likewise. + (getImageReadersByFormatName): Likewise. + (getImageReadersByMIMEType): Likewise. + (getImageReadersBySuffix): Likewise. + (getImageWritersByFormatName): Likewise. + (getImageWritersByMIMEType): Likewise. + (getImageWritersBySuffix): Likewise. + (read): Implement. + (write): Implement. + * javax/imageio/ImageReader.java + (progressListeners): Initialize. + (setInput): Implement. + * javax/imageio/ImageWriter.java + (progressListeners): Initialize. + (warningListeners): Likewise. + (warningLocales): Likewise. + (setOutput): Test "isInstance" rather than class equality. + * javax/imageio/spi/IIORegistry.java + (static): Add reader and writer SPIs. + (IIORegistry): Call ClasspathToolkit.registerImageIOSpis. + +2004-02-06 Michael Koch + + * javax/imageio/metadata/IIOInvalidTreeException.java + (IIOInvalidTreeException): Reformatted. + * javax/imageio/spi/IIORegistry.java + (static): Register ImageReaderSpi.class and ImageWriterSpi.class. + * javax/imageio/stream/MemoryCacheImageInputStream.java: + Reworked import statements. + +2004-02-06 Michael Koch + + * javax/imageio/stream/FileImageOutputStream.java: + Implemented. + +2004-02-06 Michael Koch + + * javax/imageio/stream/FileCacheImageInputStream.java, + javax/imageio/stream/FileCacheImageOutputStream.java, + javax/imageio/stream/FileImageInputStream.java, + javax/imageio/stream/ImageInputStreamImpl.java, + javax/imageio/stream/ImageOutputStreamImpl.java, + javax/imageio/stream/MemoryCacheImageInputStream.java, + javax/imageio/stream/MemoryCacheImageOutputStream.java: + Added all missing methods in javax.imageio.stream. + 2005-02-02 David Daney * java/net/InetAddress.java (InetAddress): Make a private copy of diff --git a/libjava/javax/imageio/IIOParam.java b/libjava/javax/imageio/IIOParam.java index bbab1cf..1a59123 100644 --- a/libjava/javax/imageio/IIOParam.java +++ b/libjava/javax/imageio/IIOParam.java @@ -141,6 +141,11 @@ public abstract class IIOParam this.destinationOffset = destinationOffset; } + public void setSourceBands(int[] sourceBands) + { + this.sourceBands = sourceBands; + } + public void setSourceRegion(Rectangle sourceRegion) { if (sourceRegion != null @@ -154,4 +159,13 @@ public abstract class IIOParam this.sourceRegion = sourceRegion; } + + public void setSourceSubsampling(int sourceXSubsampling, int sourceYSubsampling, + int subsamplingXOffset, int subsamplingYOffset) + { + this.sourceXSubsampling = sourceXSubsampling; + this.sourceYSubsampling = sourceYSubsampling; + this.subsamplingXOffset = subsamplingXOffset; + this.subsamplingYOffset = subsamplingYOffset; + } } diff --git a/libjava/javax/imageio/ImageIO.java b/libjava/javax/imageio/ImageIO.java index 6aa5558..3d74ae0 100644 --- a/libjava/javax/imageio/ImageIO.java +++ b/libjava/javax/imageio/ImageIO.java @@ -38,8 +38,15 @@ exception statement from your version. */ package javax.imageio; +import java.awt.image.RenderedImage; +import java.awt.image.BufferedImage; +import java.net.URL; import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; import java.io.IOException; +import java.io.OutputStream; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; @@ -48,6 +55,10 @@ import javax.imageio.spi.IIORegistry; import javax.imageio.spi.ImageReaderSpi; import javax.imageio.spi.ImageWriterSpi; import javax.imageio.spi.ServiceRegistry; +import javax.imageio.stream.ImageOutputStream; +import javax.imageio.stream.ImageInputStream; +import javax.imageio.stream.MemoryCacheImageInputStream; +import javax.imageio.stream.MemoryCacheImageOutputStream; public final class ImageIO { @@ -142,14 +153,14 @@ public final class ImageIO public boolean filter(Object provider) { - if (provider instanceof ImageReaderSpi) + if (provider instanceof ImageWriterSpi) { - ImageReaderSpi spi = (ImageReaderSpi) provider; + ImageWriterSpi spi = (ImageWriterSpi) provider; String[] formatNames = spi.getFormatNames(); for (int i = formatNames.length - 1; i >= 0; --i) - if (formatName.equals(formatNames[i])) - return true; + if (formatName.equals(formatNames[i])) + return true; } return false; @@ -167,7 +178,7 @@ public final class ImageIO public boolean filter(Object provider) { - if (provider instanceof ImageReaderSpi) + if (provider instanceof ImageWriterSpi) { ImageWriterSpi spi = (ImageWriterSpi) provider; String[] mimetypes = spi.getMIMETypes(); @@ -192,7 +203,7 @@ public final class ImageIO public boolean filter(Object provider) { - if (provider instanceof ImageReaderSpi) + if (provider instanceof ImageWriterSpi) { ImageWriterSpi spi = (ImageWriterSpi) provider; String[] suffixes = spi.getFileSuffixes(); @@ -209,10 +220,12 @@ public final class ImageIO private static final class ImageReaderIterator implements Iterator { Iterator it; + Object readerExtension; - public ImageReaderIterator(Iterator it) + public ImageReaderIterator(Iterator it, Object readerExtension) { this.it = it; + this.readerExtension = readerExtension; } public boolean hasNext() @@ -224,7 +237,7 @@ public final class ImageIO { try { - return ((ImageReaderSpi) it.next()).createReaderInstance(); + return ((ImageReaderSpi) it.next()).createReaderInstance(readerExtension); } catch (IOException e) { @@ -241,10 +254,12 @@ public final class ImageIO private static final class ImageWriterIterator implements Iterator { Iterator it; + Object writerExtension; - public ImageWriterIterator(Iterator it) + public ImageWriterIterator(Iterator it, Object writerExtension) { this.it = it; + this.writerExtension = writerExtension; } public boolean hasNext() @@ -256,7 +271,7 @@ public final class ImageIO { try { - return ((ImageWriterSpi) it.next()).createWriterInstance(); + return ((ImageWriterSpi) it.next()).createWriterInstance(writerExtension); } catch (IOException e) { @@ -274,12 +289,13 @@ public final class ImageIO private static boolean useCache = true; private static Iterator getReadersByFilter(Class type, - ServiceRegistry.Filter filter) + ServiceRegistry.Filter filter, + Object readerExtension) { try { Iterator it = getRegistry().getServiceProviders(type, filter, true); - return new ImageReaderIterator(it); + return new ImageReaderIterator(it, readerExtension); } catch (IllegalArgumentException e) { @@ -288,12 +304,13 @@ public final class ImageIO } private static Iterator getWritersByFilter(Class type, - ServiceRegistry.Filter filter) + ServiceRegistry.Filter filter, + Object writerExtension) { try { Iterator it = getRegistry().getServiceProviders(type, filter, true); - return new ImageWriterIterator(it); + return new ImageWriterIterator(it, writerExtension); } catch (IllegalArgumentException e) { @@ -312,7 +329,8 @@ public final class ImageIO throw new IllegalArgumentException("formatName may not be null"); return getReadersByFilter(ImageReaderSpi.class, - new ReaderFormatFilter(formatName)); + new ReaderFormatFilter(formatName), + formatName); } public static Iterator getImageReadersByMIMEType(String MIMEType) @@ -321,7 +339,8 @@ public final class ImageIO throw new IllegalArgumentException("MIMEType may not be null"); return getReadersByFilter(ImageReaderSpi.class, - new ReaderMIMETypeFilter(MIMEType)); + new ReaderMIMETypeFilter(MIMEType), + MIMEType); } public static Iterator getImageReadersBySuffix(String fileSuffix) @@ -330,7 +349,8 @@ public final class ImageIO throw new IllegalArgumentException("formatName may not be null"); return getReadersByFilter(ImageReaderSpi.class, - new ReaderSuffixFilter(fileSuffix)); + new ReaderSuffixFilter(fileSuffix), + fileSuffix); } public static Iterator getImageWritersByFormatName(String formatName) @@ -339,7 +359,8 @@ public final class ImageIO throw new IllegalArgumentException("formatName may not be null"); return getWritersByFilter(ImageWriterSpi.class, - new WriterFormatFilter(formatName)); + new WriterFormatFilter(formatName), + formatName); } public static Iterator getImageWritersByMIMEType(String MIMEType) @@ -348,7 +369,8 @@ public final class ImageIO throw new IllegalArgumentException("MIMEType may not be null"); return getWritersByFilter(ImageWriterSpi.class, - new WriterMIMETypeFilter(MIMEType)); + new WriterMIMETypeFilter(MIMEType), + MIMEType); } public static Iterator getImageWritersBySuffix(String fileSuffix) @@ -357,7 +379,8 @@ public final class ImageIO throw new IllegalArgumentException("fileSuffix may not be null"); return getWritersByFilter(ImageWriterSpi.class, - new WriterSuffixFilter(fileSuffix)); + new WriterSuffixFilter(fileSuffix), + fileSuffix); } public static String[] getReaderFormatNames() @@ -496,4 +519,87 @@ public final class ImageIO { ImageIO.useCache = useCache; } + + /* + * "Standard" simplified entry points. + */ + + public static boolean write(RenderedImage im, + String formatName, + File output) + throws IOException + { + return write(im, formatName, new FileOutputStream(output)); + } + + public static boolean write(RenderedImage im, + String formatName, + OutputStream output) + throws IOException + { + return write(im, formatName, new MemoryCacheImageOutputStream(output)); + } + + + public static boolean write(RenderedImage im, + String formatName, + ImageOutputStream output) + throws IOException + { + Iterator writers = getImageWritersByFormatName(formatName); + IIOImage img = new IIOImage(im, null, null); + while (writers.hasNext()) + { + ImageWriter w = (ImageWriter) writers.next(); + try + { + w.setOutput(output); + } + catch (IllegalArgumentException e) + { + continue; + } + + w.write(null, img, null); + output.close(); + return true; + } + return false; + } + + public static BufferedImage read(ImageInputStream stream) + throws IOException + { + Iterator providers = getRegistry().getServiceProviders(ImageReaderSpi.class, true); + while (providers.hasNext()) + { + ImageReaderSpi spi = (ImageReaderSpi) providers.next(); + if (spi.canDecodeInput(stream)) + { + ImageReader reader = spi.createReaderInstance(); + reader.setInput(stream); + return reader.read(0, null); + } + } + return null; + } + + public static BufferedImage read(URL input) + throws IOException + { + return read(input.openStream()); + } + + public static BufferedImage read(InputStream input) + throws IOException + { + return read(new MemoryCacheImageInputStream(input)); + } + + public static BufferedImage read(File input) + throws IOException + { + return read(new FileInputStream(input)); + } + } diff --git a/libjava/javax/imageio/ImageReadParam.java b/libjava/javax/imageio/ImageReadParam.java index e5414bd..4192c56 100644 --- a/libjava/javax/imageio/ImageReadParam.java +++ b/libjava/javax/imageio/ImageReadParam.java @@ -94,6 +94,22 @@ public class ImageReadParam extends IIOParam { return sourceRenderSize; } + + public void setDestination(BufferedImage destination) + { + this.destination = destination; + } + + public void setDestinationBands(int[] destinationBands) + { + this.destinationBands = destinationBands; + } + + public void setSourceProgressivePasses(int minPass, int numPasses) + { + this.minProgressivePass = minPass; + this.numProgressivePasses = numPasses; + } public void setSourceRenderSize(Dimension size) throws UnsupportedOperationException diff --git a/libjava/javax/imageio/ImageReader.java b/libjava/javax/imageio/ImageReader.java index 91cb53c..6e5a1b2 100644 --- a/libjava/javax/imageio/ImageReader.java +++ b/libjava/javax/imageio/ImageReader.java @@ -51,6 +51,7 @@ import javax.imageio.event.IIOReadUpdateListener; import javax.imageio.event.IIOReadWarningListener; import javax.imageio.metadata.IIOMetadata; import javax.imageio.spi.ImageReaderSpi; +import javax.imageio.stream.ImageInputStream; public abstract class ImageReader { @@ -62,7 +63,7 @@ public abstract class ImageReader protected Locale locale; protected int minIndex; protected ImageReaderSpi originatingProvider; - protected List progressListeners; + protected List progressListeners = new ArrayList(); protected boolean seekForwardOnly; protected List updateListeners = new ArrayList(); protected List warningListeners = new ArrayList(); @@ -156,6 +157,42 @@ public abstract class ImageReader public abstract Iterator getImageTypes(int imageIndex) throws IOException; + public void setInput(Object input, + boolean seekForwardOnly, + boolean ignoreMetadata) + { + Class[] okClasses = originatingProvider.getInputTypes(); + if (okClasses == null) + { + if (!(input instanceof ImageInputStream)) + throw new IllegalArgumentException(); + } + else + { + boolean classOk = false; + for (int i = 0; i < okClasses.length; ++i) + if (okClasses[i].isInstance(input)) + classOk = true; + if (!classOk) + throw new IllegalArgumentException(); + } + + this.input = input; + this.seekForwardOnly = seekForwardOnly; + this.ignoreMetadata = ignoreMetadata; + this.minIndex = 0; + } + + public void setInput(Object in, boolean seekForwardOnly) + { + setInput(in, seekForwardOnly, false); + } + + public void setInput(Object in) + { + setInput(in, false, false); + } + public Object getInput() { return input; diff --git a/libjava/javax/imageio/ImageWriter.java b/libjava/javax/imageio/ImageWriter.java index 64466b1..389ca43 100644 --- a/libjava/javax/imageio/ImageWriter.java +++ b/libjava/javax/imageio/ImageWriter.java @@ -40,6 +40,7 @@ package javax.imageio; import java.awt.Dimension; import java.io.IOException; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -59,9 +60,9 @@ public abstract class ImageWriter protected Locale locale; protected ImageWriterSpi originatingProvider; protected Object output; - protected List progressListeners; - protected List warningListeners; - protected List warningLocales; + protected List progressListeners = new ArrayList(); + protected List warningListeners = new ArrayList(); + protected List warningLocales = new ArrayList(); protected ImageWriter(ImageWriterSpi originatingProvider) { @@ -371,11 +372,11 @@ public abstract class ImageWriter if (originatingProvider != null) types = originatingProvider.getOutputTypes(); - + if (types != null) for (int i = types.length - 1; i >= 0; --i) - if (types[i].equals(output.getClass())) - found = true; + if (types[i].isInstance(output)) + found = true; if (! found) throw new IllegalArgumentException("output type not available"); diff --git a/libjava/javax/imageio/metadata/IIOAttr.java b/libjava/javax/imageio/metadata/IIOAttr.java new file mode 100644 index 0000000..c041d39 --- /dev/null +++ b/libjava/javax/imageio/metadata/IIOAttr.java @@ -0,0 +1,378 @@ +/* IIOAttr.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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.metadata; + +import org.w3c.dom.Attr; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.TypeInfo; +import org.w3c.dom.UserDataHandler; + +/** + * Simple Attr node for metadata trees + * + * @author jlquinn + */ +class IIOAttr implements Attr +{ + String name; + String value; + IIOMetadataNode owner; + + public IIOAttr(String name, String value, IIOMetadataNode owner) + { + this.name = name; + this.value = value; + this.owner = owner; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Attr#getName() + */ + public String getName() + { + return name; + } + + public TypeInfo getSchemaTypeInfo() + { + throw new Error("not implemented"); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Attr#getSpecified() + */ + public boolean getSpecified() + { + // I don't think there can be default attrs in metadata + return true; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Attr#getValue() + */ + public String getValue() + { + return value; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Attr#setValue(java.lang.String) + */ + public void setValue(String value) throws DOMException + { + this.value = value; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Attr#getOwnerElement() + */ + public Element getOwnerElement() + { + return owner; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNodeName() + */ + public String getNodeName() + { + return name; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNodeValue() + */ + public String getNodeValue() throws DOMException + { + return value; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#setNodeValue(java.lang.String) + */ + public void setNodeValue(String nodeValue) throws DOMException + { + this.value = nodeValue; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNodeType() + */ + public short getNodeType() + { + return ATTRIBUTE_NODE; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getParentNode() + */ + public Node getParentNode() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getChildNodes() + */ + public NodeList getChildNodes() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getFirstChild() + */ + public Node getFirstChild() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getLastChild() + */ + public Node getLastChild() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getPreviousSibling() + */ + public Node getPreviousSibling() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNextSibling() + */ + public Node getNextSibling() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getAttributes() + */ + public NamedNodeMap getAttributes() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getOwnerDocument() + */ + public Document getOwnerDocument() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node) + */ + public Node insertBefore(Node newChild, Node refChild) throws DOMException + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node) + */ + public Node replaceChild(Node newChild, Node oldChild) throws DOMException + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node) + */ + public Node removeChild(Node oldChild) throws DOMException + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node) + */ + public Node appendChild(Node newChild) throws DOMException + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#hasChildNodes() + */ + public boolean hasChildNodes() + { + return false; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#cloneNode(boolean) + */ + public Node cloneNode(boolean deep) + { + return new IIOAttr(name, value, owner); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#normalize() + */ + public void normalize() + { + } + + public boolean isDefaultNamespace(String namespaceURI) + { + throw new Error("not implemented"); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#isSupported(java.lang.String, java.lang.String) + */ + public boolean isSupported(String feature, String version) + { + return false; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNamespaceURI() + */ + public String getNamespaceURI() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getPrefix() + */ + public String getPrefix() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#setPrefix(java.lang.String) + */ + public void setPrefix(String prefix) throws DOMException + { + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getLocalName() + */ + public String getLocalName() + { + return name; + } + + public Object getUserData(String key) + { + throw new Error("not implemented"); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#hasAttributes() + */ + public boolean hasAttributes() + { + return false; + } + + public boolean isId() + { + throw new Error("not implemented"); + } + + public String lookupNamespaceURI(String prefix) + { + throw new Error("not implemented"); + } + + public String lookupPrefix(String namespaceURI) + { + throw new Error("not implemented"); + } + + public Object setUserData(String key, Object data, UserDataHandler handler) + { + throw new Error("not implemented"); + } + + public String getBaseURI() + { + throw new Error("not implemented"); + } + + public String getTextContent() + { + throw new Error("not implemented"); + } + + public void setTextContent(String textContent) + { + throw new Error("not implemented"); + } + + public short compareDocumentPosition(Node other) + throws DOMException + { + throw new Error("not implemented"); + } + + public Object getFeature(String feature, String version) + { + throw new Error("not implemented"); + } + + public boolean isEqualNode(Node other) + { + throw new Error("not implemented"); + } + + public boolean isSameNode(Node other) + { + throw new Error("not implemented"); + } +} diff --git a/libjava/javax/imageio/metadata/IIOInvalidTreeException.java b/libjava/javax/imageio/metadata/IIOInvalidTreeException.java index c3ce424..af84f07 100644 --- a/libjava/javax/imageio/metadata/IIOInvalidTreeException.java +++ b/libjava/javax/imageio/metadata/IIOInvalidTreeException.java @@ -40,23 +40,28 @@ package javax.imageio.metadata; import javax.imageio.IIOException; +import org.w3c.dom.Node; + public class IIOInvalidTreeException extends IIOException { - protected /*Node*/ Object offendingNode; + private static final long serialVersionUID = -1314083172544132777L; + + protected Node offendingNode; - public IIOInvalidTreeException(String message, /*Node*/ Object offendingNode) + public IIOInvalidTreeException(String message, Node offendingNode) { super(message); this.offendingNode = offendingNode; } - public IIOInvalidTreeException(String message, Throwable cause, /*Node*/ Object offendingNode) + public IIOInvalidTreeException(String message, Throwable cause, + Node offendingNode) { super(message, cause); this.offendingNode = offendingNode; } - public /*Node*/ Object getOffendingNode() + public Node getOffendingNode() { return offendingNode; } diff --git a/libjava/javax/imageio/metadata/IIOMetadataNode.java b/libjava/javax/imageio/metadata/IIOMetadataNode.java index 3d1c7d2..609db4d 100644 --- a/libjava/javax/imageio/metadata/IIOMetadataNode.java +++ b/libjava/javax/imageio/metadata/IIOMetadataNode.java @@ -38,6 +38,555 @@ exception statement from your version. */ package javax.imageio.metadata; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; + +import org.w3c.dom.Attr; +import org.w3c.dom.DOMException; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.w3c.dom.TypeInfo; +import org.w3c.dom.UserDataHandler; + public class IIOMetadataNode + implements Element, NodeList { + private String name; + private HashMap attrs = new HashMap(); + private List children = new ArrayList(); + private IIOMetadataNode parent; + private Object obj; + + public IIOMetadataNode() + { + // Do nothing here. + } + + public IIOMetadataNode(String nodename) + { + name = nodename; + } + + public Object getUserObject() + { + return obj; + } + + public void setUserObject(Object o) + { + obj = o; + } + + public short compareDocumentPosition(Node other) + throws DOMException + { + throw new Error("not implemented"); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#getAttribute(java.lang.String) + */ + public String getAttribute(String name) + { + Attr anode = (Attr) attrs.get(name); + return anode != null ? anode.getValue() : null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#getAttributeNode(java.lang.String) + */ + public Attr getAttributeNode(String name) + { + String val = getAttribute(name); + if (val != null) + return new IIOAttr(name, val, this); + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#getAttributeNodeNS(java.lang.String, java.lang.String) + */ + public Attr getAttributeNodeNS(String namespaceURI, String localName) + { + return getAttributeNode(localName); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#getAttributeNS(java.lang.String, java.lang.String) + */ + public String getAttributeNS(String namespaceURI, String localName) + { + return getAttribute(localName); + } + + public String getBaseURI() + { + throw new Error("not implemented"); + } + + // Recursive function for assembling a node list. + private void getElementsRecurse(IIONodeList list, String name) + { + for (int i=0; i < children.size(); i++) + { + if (((Node)children.get(i)).getNodeName().equals(name)) + list.children.add(children.get(i)); + getElementsRecurse(list, name); + } + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#getElementsByTagName(java.lang.String) + */ + public NodeList getElementsByTagName(String name) + { + IIONodeList list = new IIONodeList(); + getElementsRecurse(list, name); + return list; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#getElementsByTagNameNS(java.lang.String, java.lang.String) + */ + public NodeList getElementsByTagNameNS(String namespaceURI, String localName) + { + IIONodeList list = new IIONodeList(); + getElementsRecurse(list, name); + return list; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#getTagName() + */ + public String getTagName() + { + return name; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#hasAttribute(java.lang.String) + */ + public boolean hasAttribute(String name) + { + return attrs.containsKey(name); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#hasAttributeNS(java.lang.String, java.lang.String) + */ + public boolean hasAttributeNS(String namespaceURI, String localName) + { + return attrs.containsKey(localName); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#removeAttribute(java.lang.String) + */ + public void removeAttribute(String name) + { + attrs.remove(name); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#removeAttributeNode(org.w3c.dom.Attr) + */ + public Attr removeAttributeNode(Attr oldAttr) + { + return (Attr)attrs.remove(oldAttr.getName()); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#removeAttributeNS(java.lang.String, java.lang.String) + */ + public void removeAttributeNS(String namespaceURI, String localName) + { + removeAttribute(localName); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#setAttribute(java.lang.String, java.lang.String) + */ + public void setAttribute(String name, String value) + { + Attr attr = (Attr) getAttributeNode(name); + if (attr != null) + attr.setValue(value); + else + attrs.put(name, new IIOAttr(name, value, this)); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#setAttributeNode(org.w3c.dom.Attr) + */ + public Attr setAttributeNode(Attr newAttr) + { + return (Attr)attrs.put(newAttr.getName(), newAttr); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#setAttributeNodeNS(org.w3c.dom.Attr) + */ + public Attr setAttributeNodeNS(Attr newAttr) + { + return (Attr)attrs.put(newAttr.getName(), newAttr); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Element#setAttributeNS(java.lang.String, java.lang.String, java.lang.String) + */ + public void setAttributeNS(String namespaceURI, String qualifiedName, String value) + { + setAttribute(qualifiedName, value); + } + + /* (non-Javadoc) + * @see org.w3c.dom.NodeList#getLength() + */ + public int getLength() + { + return children.size(); + } + + /* (non-Javadoc) + * @see org.w3c.dom.NodeList#item(int) + */ + public Node item(int index) + { + if (index < children.size()) + return (Node)children.get(index); + else + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node) + */ + public Node appendChild(Node newChild) + { + if (newChild == null) + throw new IllegalArgumentException("Child node is null"); + + IIOMetadataNode child = (IIOMetadataNode) newChild; + + children.add(child); + child.parent = this; + return this; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#cloneNode(boolean) + */ + public Node cloneNode(boolean deep) + { + IIOMetadataNode newnode = new IIOMetadataNode(name); + newnode.parent = null; + newnode.obj = obj; + if (deep) + { + for (int i=0; i < children.size(); i++) + newnode.children.add(((Node)children.get(i)).cloneNode(deep)); + } + + // clone attrs + for (Iterator it = attrs.values().iterator(); it.hasNext();) + { + IIOAttr attr = (IIOAttr)it.next(); + newnode.attrs.put(attr.name, attr.cloneNode(deep)); + attr.owner = newnode; + } + + return newnode; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getAttributes() + */ + public NamedNodeMap getAttributes() + { + return new IIONamedNodeMap(attrs); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getChildNodes() + */ + public NodeList getChildNodes() + { + return this; + } + + public Object getFeature(String feature, String version) + { + throw new Error("not implemented"); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getFirstChild() + */ + public Node getFirstChild() + { + return (children.size() > 0) ? (Node)children.get(0) : null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getLastChild() + */ + public Node getLastChild() + { + return (children.size() > 0) ? (Node)children.get(children.size() - 1) + : null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getLocalName() + */ + public String getLocalName() + { + return name; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNamespaceURI() + */ + public String getNamespaceURI() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNextSibling() + */ + public Node getNextSibling() + { + // If this op needs to be faster, add links to prev and next nodes. + if (parent == null) return null; + int idx = parent.children.indexOf(this); + return (idx == parent.children.size() - 1) ? null + : (Node)parent.children.get(idx + 1); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNodeName() + */ + public String getNodeName() + { + return name; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNodeType() + */ + public short getNodeType() + { + return ELEMENT_NODE; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getNodeValue() + */ + public String getNodeValue() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getOwnerDocument() + */ + public Document getOwnerDocument() + { + // IOMetadataNodes have no owner + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getParentNode() + */ + public Node getParentNode() + { + return parent; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getPrefix() + */ + public String getPrefix() + { + return null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#getPreviousSibling() + */ + public Node getPreviousSibling() + { + // If this op needs to be faster, add links to prev and next nodes. + if (parent == null) return null; + int idx = parent.children.indexOf(this); + return (idx == 0) ? null + : (Node)parent.children.get(idx - 1); + } + + public TypeInfo getSchemaTypeInfo() + { + throw new Error("not implemented"); + } + + public String getTextContent() + throws DOMException + { + throw new Error("not implemented"); + } + + public Object getUserData(String key) + { + throw new Error("not implemented"); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#hasAttributes() + */ + public boolean hasAttributes() + { + return !attrs.isEmpty(); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#hasChildNodes() + */ + public boolean hasChildNodes() + { + return !children.isEmpty(); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node) + */ + public Node insertBefore(Node newChild, Node refChild) + { + if (newChild == null) + throw new IllegalArgumentException(); + + int idx = children.indexOf(refChild); + if (idx == -1) + children.add(newChild); + else + children.add(idx, newChild); + ((IIOMetadataNode)newChild).parent = this; + + return newChild; + } + + public boolean isDefaultNamespace(String namespaceURI) + { + throw new Error("not implemented"); + } + + public boolean isEqualNode(Node arg) + { + throw new Error("not implemented"); + } + + public boolean isSameNode(Node other) + { + return this == other; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#isSupported(java.lang.String, java.lang.String) + */ + public boolean isSupported(String feature, String version) + { + // No DOM features are supported + return false; + } + + public String lookupNamespaceURI(String prefix) + { + throw new Error("not implemented"); + } + + public String lookupPrefix(String namespaceURI) + { + throw new Error("not implemented"); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#normalize() + */ + public void normalize() + { + // No text nodes so no action + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node) + */ + public Node removeChild(Node oldChild) + { + if (oldChild == null) + throw new IllegalArgumentException(); + children.remove(oldChild); + ((IIOMetadataNode)oldChild).parent = null; + + return oldChild; + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node) + */ + public Node replaceChild(Node newChild, Node oldChild) + { + if (newChild == null) + throw new IllegalArgumentException(); + children.set(children.indexOf(oldChild), newChild); + ((IIOMetadataNode)oldChild).parent = null; + return oldChild; + } + + public void setIdAttribute(String name, boolean isId) + throws DOMException + { + throw new Error("not implemented"); + } + + public void setIdAttributeNode(Attr idAttr, boolean isId) + throws DOMException + { + throw new Error("not implemented"); + } + + public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) + throws DOMException + { + throw new Error("not implemented"); + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#setNodeValue(java.lang.String) + */ + public void setNodeValue(String nodeValue) throws DOMException + { + } + + /* (non-Javadoc) + * @see org.w3c.dom.Node#setPrefix(java.lang.String) + */ + public void setPrefix(String prefix) + { + } + + public void setTextContent(String textContent) + throws DOMException + { + throw new Error("not implemented"); + } + + public Object setUserData(String key, Object data, UserDataHandler handler) + { + throw new Error("not implemented"); + } } diff --git a/libjava/javax/imageio/metadata/IIONamedNodeMap.java b/libjava/javax/imageio/metadata/IIONamedNodeMap.java new file mode 100644 index 0000000..e549c1c --- /dev/null +++ b/libjava/javax/imageio/metadata/IIONamedNodeMap.java @@ -0,0 +1,138 @@ +/* IIONamedNodeMap.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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.metadata; + +import java.util.HashMap; + +import org.w3c.dom.DOMException; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +/** + * Simple NamedNodeMap class for IIOMetadataNode. + * + * @author jlquinn + */ +class IIONamedNodeMap implements NamedNodeMap +{ + HashMap attrs; + + /** + * @param attrs + * @param node + */ + public IIONamedNodeMap(HashMap attrs) + { + this.attrs = attrs; + } + + /* (non-Javadoc) + * @see org.w3c.dom.NamedNodeMap#getNamedItem(java.lang.String) + */ + public Node getNamedItem(String name) + { + return (Node)attrs.get(name); + } + + /* (non-Javadoc) + * @see org.w3c.dom.NamedNodeMap#setNamedItem(org.w3c.dom.Node) + */ + public Node setNamedItem(Node arg) throws DOMException + { + if (arg instanceof IIOAttr) + { + IIOAttr attr = (IIOAttr) arg; + // The only code that can successfully do this is in this package. + if (attr.owner != null) + throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, ""); + return (Node)attrs.put(attr.name, attr); + } + // Anything else gets treated as an invalid op. + throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, ""); + } + + /* (non-Javadoc) + * @see org.w3c.dom.NamedNodeMap#removeNamedItem(java.lang.String) + */ + public Node removeNamedItem(String name) throws DOMException + { + return (Node)attrs.remove(name); + } + + /* (non-Javadoc) + * @see org.w3c.dom.NamedNodeMap#item(int) + */ + public Node item(int index) + { + return (Node)attrs.values().toArray()[index]; + } + + /* (non-Javadoc) + * @see org.w3c.dom.NamedNodeMap#getLength() + */ + public int getLength() + { + return attrs.size(); + } + + /* (non-Javadoc) + * @see org.w3c.dom.NamedNodeMap#getNamedItemNS(java.lang.String, java.lang.String) + */ + public Node getNamedItemNS(String namespaceURI, String localName) + { + return getNamedItem(localName); + } + + /* (non-Javadoc) + * @see org.w3c.dom.NamedNodeMap#setNamedItemNS(org.w3c.dom.Node) + */ + public Node setNamedItemNS(Node arg) throws DOMException + { + return setNamedItem(arg); + } + + /* (non-Javadoc) + * @see org.w3c.dom.NamedNodeMap#removeNamedItemNS(java.lang.String, java.lang.String) + */ + public Node removeNamedItemNS(String namespaceURI, String localName) + throws DOMException + { + return removeNamedItem(localName); + } + +} diff --git a/libjava/javax/imageio/metadata/IIONodeList.java b/libjava/javax/imageio/metadata/IIONodeList.java new file mode 100644 index 0000000..4ef7f4c --- /dev/null +++ b/libjava/javax/imageio/metadata/IIONodeList.java @@ -0,0 +1,72 @@ +/* IIOAttr.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., 59 Temple Place, Suite 330, Boston, MA +02111-1307 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.metadata; + +import java.util.ArrayList; +import java.util.List; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Simple NodeList implementation for IIOMetadataNode. + * + * @author jlquinn + * + */ +class IIONodeList implements NodeList +{ + List children = new ArrayList(); + + /* (non-Javadoc) + * @see org.w3c.dom.NodeList#item(int) + */ + public Node item(int index) + { + return (index < children.size()) ? (Node)children.get(index) : null; + } + + /* (non-Javadoc) + * @see org.w3c.dom.NodeList#getLength() + */ + public int getLength() + { + return children.size(); + } + +} diff --git a/libjava/javax/imageio/spi/IIORegistry.java b/libjava/javax/imageio/spi/IIORegistry.java index 7728cf4..6531fab 100644 --- a/libjava/javax/imageio/spi/IIORegistry.java +++ b/libjava/javax/imageio/spi/IIORegistry.java @@ -39,7 +39,9 @@ exception statement from your version. */ package javax.imageio.spi; import gnu.classpath.ServiceFactory; +import gnu.java.awt.ClasspathToolkit; +import java.awt.Toolkit; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -52,8 +54,8 @@ public final class IIORegistry extends ServiceRegistry static { - //defaultCategories.add(ImageReaderSpi.class); - //defaultCategories.add(ImageWriterSpi.class); + defaultCategories.add(ImageReaderSpi.class); + defaultCategories.add(ImageWriterSpi.class); defaultCategories.add(ImageTranscoderSpi.class); defaultCategories.add(ImageInputStreamSpi.class); defaultCategories.add(ImageOutputStreamSpi.class); @@ -78,6 +80,8 @@ public final class IIORegistry extends ServiceRegistry super(defaultCategories.iterator()); // XXX: Register built-in Spis here. + + ((ClasspathToolkit)Toolkit.getDefaultToolkit()).registerImageIOSpis(this); registerApplicationClasspathSpis(); } diff --git a/libjava/javax/imageio/stream/FileCacheImageInputStream.java b/libjava/javax/imageio/stream/FileCacheImageInputStream.java index 49827d4..a8db477 100644 --- a/libjava/javax/imageio/stream/FileCacheImageInputStream.java +++ b/libjava/javax/imageio/stream/FileCacheImageInputStream.java @@ -45,7 +45,7 @@ import java.io.InputStream; /** * @author Michael Koch (konqueror@gmx.de) */ -public class FileCacheImageInputStream +public class FileCacheImageInputStream extends ImageInputStreamImpl { private InputStream stream; private File cacheDir; @@ -90,4 +90,20 @@ public class FileCacheImageInputStream { 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/javax/imageio/stream/FileCacheImageOutputStream.java b/libjava/javax/imageio/stream/FileCacheImageOutputStream.java index f8bb310..912b368 100644 --- a/libjava/javax/imageio/stream/FileCacheImageOutputStream.java +++ b/libjava/javax/imageio/stream/FileCacheImageOutputStream.java @@ -45,7 +45,7 @@ import java.io.OutputStream; /** * @author Michael Koch (konqueror@gmx.de) */ -public class FileCacheImageOutputStream +public class FileCacheImageOutputStream extends ImageOutputStreamImpl { private OutputStream stream; private File cacheDir; @@ -90,4 +90,34 @@ public class FileCacheImageOutputStream { 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/javax/imageio/stream/FileImageInputStream.java b/libjava/javax/imageio/stream/FileImageInputStream.java index 67fd075..1684632 100644 --- a/libjava/javax/imageio/stream/FileImageInputStream.java +++ b/libjava/javax/imageio/stream/FileImageInputStream.java @@ -46,7 +46,7 @@ import java.io.RandomAccessFile; /** * @author Michael Koch (konqueror@gmx.de) */ -public class FileImageInputStream +public class FileImageInputStream extends ImageInputStreamImpl { private RandomAccessFile file; @@ -84,4 +84,25 @@ public class FileImageInputStream 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/javax/imageio/stream/FileImageOutputStream.java b/libjava/javax/imageio/stream/FileImageOutputStream.java index 073faed..5b47af8 100644 --- a/libjava/javax/imageio/stream/FileImageOutputStream.java +++ b/libjava/javax/imageio/stream/FileImageOutputStream.java @@ -46,7 +46,7 @@ import java.io.RandomAccessFile; /** * @author Michael Koch (konqueror@gmx.de) */ -public class FileImageOutputStream +public class FileImageOutputStream extends ImageOutputStreamImpl { private RandomAccessFile file; @@ -87,4 +87,47 @@ public class FileImageOutputStream 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/javax/imageio/stream/ImageInputStreamImpl.java b/libjava/javax/imageio/stream/ImageInputStreamImpl.java index 3a5d6dc..dbe6d1a 100644 --- a/libjava/javax/imageio/stream/ImageInputStreamImpl.java +++ b/libjava/javax/imageio/stream/ImageInputStreamImpl.java @@ -38,8 +38,11 @@ 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) @@ -47,6 +50,9 @@ import java.nio.ByteOrder; 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; @@ -99,6 +105,7 @@ public abstract class ImageInputStreamImpl implements ImageInputStream public int getBitOffset() throws IOException { + checkClosed(); return bitOffset; } @@ -115,6 +122,7 @@ public abstract class ImageInputStreamImpl implements ImageInputStream public long getStreamPosition() throws IOException { + checkClosed(); return streamPos; } @@ -138,6 +146,18 @@ public abstract class ImageInputStreamImpl implements ImageInputStream return -1L; } + public void mark() + { + try + { + markStack.push(new Long(getStreamPosition())); + } + catch (IOException e) + { + // Ignored. + } + } + public abstract int read() throws IOException; @@ -150,8 +170,346 @@ public abstract class ImageInputStreamImpl implements ImageInputStream public abstract int read(byte[] data, int offset, int len) throws IOException; - public void setByteOrder (ByteOrder byteOrder) + 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/javax/imageio/stream/ImageOutputStreamImpl.java b/libjava/javax/imageio/stream/ImageOutputStreamImpl.java index d600943..2149255 100644 --- a/libjava/javax/imageio/stream/ImageOutputStreamImpl.java +++ b/libjava/javax/imageio/stream/ImageOutputStreamImpl.java @@ -39,6 +39,7 @@ exception statement from your version. */ package javax.imageio.stream; import java.io.IOException; +import java.nio.ByteOrder; /** * @author Michael Koch (konqueror@gmx.de) @@ -51,6 +52,13 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl // Do nothing here. } + protected void flushBits() + throws IOException + { + // FIXME: Implement me. + throw new Error("not implemented"); + } + public void write(byte[] data) throws IOException { @@ -62,4 +70,176 @@ public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl 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/javax/imageio/stream/MemoryCacheImageInputStream.java b/libjava/javax/imageio/stream/MemoryCacheImageInputStream.java index c7ca6d6..3631e64 100644 --- a/libjava/javax/imageio/stream/MemoryCacheImageInputStream.java +++ b/libjava/javax/imageio/stream/MemoryCacheImageInputStream.java @@ -38,11 +38,35 @@ 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 +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; @@ -57,4 +81,18 @@ public class MemoryCacheImageInputStream { 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/javax/imageio/stream/MemoryCacheImageOutputStream.java b/libjava/javax/imageio/stream/MemoryCacheImageOutputStream.java index b91fd66..a21efae 100644 --- a/libjava/javax/imageio/stream/MemoryCacheImageOutputStream.java +++ b/libjava/javax/imageio/stream/MemoryCacheImageOutputStream.java @@ -38,11 +38,35 @@ 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 +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; @@ -57,4 +81,32 @@ public class MemoryCacheImageOutputStream { 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); + } } -- 2.7.4