]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[multiple changes]
authorAnthony Green <green@gcc.gnu.org>
Mon, 7 Feb 2005 13:22:36 +0000 (13:22 +0000)
committerAnthony Green <green@gcc.gnu.org>
Mon, 7 Feb 2005 13:22:36 +0000 (13:22 +0000)
2005-02-06  Jerry Quinn  <jlquinn@optonline.net>

        * 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  <graydon@redhat.com>

        * 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  <konqueror@gmx.de>

        * 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  <konqueror@gmx.de>

        * javax/imageio/stream/FileImageOutputStream.java:
        Implemented.

2004-02-06  Michael Koch  <konqueror@gmx.de>

        * 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.

From-SVN: r94698

20 files changed:
libjava/ChangeLog
libjava/javax/imageio/IIOParam.java
libjava/javax/imageio/ImageIO.java
libjava/javax/imageio/ImageReadParam.java
libjava/javax/imageio/ImageReader.java
libjava/javax/imageio/ImageWriter.java
libjava/javax/imageio/metadata/IIOAttr.java [new file with mode: 0644]
libjava/javax/imageio/metadata/IIOInvalidTreeException.java
libjava/javax/imageio/metadata/IIOMetadataNode.java
libjava/javax/imageio/metadata/IIONamedNodeMap.java [new file with mode: 0644]
libjava/javax/imageio/metadata/IIONodeList.java [new file with mode: 0644]
libjava/javax/imageio/spi/IIORegistry.java
libjava/javax/imageio/stream/FileCacheImageInputStream.java
libjava/javax/imageio/stream/FileCacheImageOutputStream.java
libjava/javax/imageio/stream/FileImageInputStream.java
libjava/javax/imageio/stream/FileImageOutputStream.java
libjava/javax/imageio/stream/ImageInputStreamImpl.java
libjava/javax/imageio/stream/ImageOutputStreamImpl.java
libjava/javax/imageio/stream/MemoryCacheImageInputStream.java
libjava/javax/imageio/stream/MemoryCacheImageOutputStream.java

index 1ee4076912b53fb21d5b1593df5c52c16cbef6b6..b294c0b1a1900ed0a42e263a962baa4b37c95821 100644 (file)
@@ -1,3 +1,67 @@
+2005-02-06  Jerry Quinn  <jlquinn@optonline.net>
+
+       * 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  <graydon@redhat.com>
+
+       * 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  <konqueror@gmx.de>
+
+       * 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  <konqueror@gmx.de>
+
+       * javax/imageio/stream/FileImageOutputStream.java:
+       Implemented.
+
+2004-02-06  Michael Koch  <konqueror@gmx.de>
+
+       * 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  <ddaney@avtrex.com>
 
        * java/net/InetAddress.java (InetAddress): Make a private copy of
index bbab1cf79f67b75f8d381fd90bf844e65ea6a1c7..1a59123995ffe2c02414c1c9ed860deb25f303a5 100644 (file)
@@ -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;
+  }
 }
index 6aa5558919c9aa3550e10509ddffbc90c0d25f12..3d74ae0745d7252ee9458a5217f319a7ffb082ba 100644 (file)
@@ -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));
+  }
+
 }
index e5414bda17e4f23cd585cbb90345550274e8cc19..4192c563b14a172ef64307b62ab8247748a25117 100644 (file)
@@ -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
index 91cb53cd8b4c20468941f6d58b8366fc80d8be5d..6e5a1b2d87e98081ef277226eb90e3545871c8d7 100644 (file)
@@ -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;
index 64466b151f08163e8238e5e56f04e735c9b9e1ea..389ca4360a703ef718f0815c6e4c6dd90083a88f 100644 (file)
@@ -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 (file)
index 0000000..c041d39
--- /dev/null
@@ -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");
+  }
+}
index c3ce42482c6f1e14fe63baa4f98632126ce5357b..af84f0732c28fe2125d9d18de2e8d961363fcd31 100644 (file)
@@ -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;
   }
index 3d1c7d26742ac5d78b2ee3a85075d3a6cd2177de..609db4d782311cc7af2089cbcc2cd46ef404e171 100644 (file)
@@ -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 (file)
index 0000000..e549c1c
--- /dev/null
@@ -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 (file)
index 0000000..4ef7f4c
--- /dev/null
@@ -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();
+  }
+
+}
index 7728cf428a32a1c6f68a1d22e6afadd9ececfc05..6531fabca104fb11b9c8266a42a5bde0ec5aa81c 100644 (file)
@@ -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();
   }
index 49827d4e0fbf39fc60de5160b8953afd73be9854..a8db4779bba830756e971d8a657251b8b1319455 100644 (file)
@@ -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);
+  }
 }
index f8bb3100275bfe4b7bce8cc82a638698018edabf..912b368d146fe78bf95f847527b2cf29e1bc32f0 100644 (file)
@@ -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);
+  }
 }
index 67fd07518b189491cfa03e34be80aece80392481..1684632553e77645996eeb456c6438b3c4a51492 100644 (file)
@@ -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);
+  }
 }
index 073faed19f4bba0ff91110ebf823fc54409d06e9..5b47af840d4a8c3f33d93d85b9ebf3c30b30f152 100644 (file)
@@ -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);
+  }
 }
index 3a5d6dcb6d776001b897e62fc720a6a54f733d6d..dbe6d1aaab9cef97aab1e37d4faa4e1d84ebbfad 100644 (file)
@@ -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;
+  }
 }
index d6009431900a13841c9a91c1cddccaf29b0fed9a..2149255457d7053fcbfd03bd721782163cbead00 100644 (file)
@@ -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");
+  }
 }
index c7ca6d6e06d0ce7cdafc95c0f5a8727659bbc984..3631e64fc205767fffe711d8eca5912b00c36b92 100644 (file)
@@ -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);
+  }
 }
index b91fd666382632c83679b76e08f63d8c62c4169a..a21efae984faeae786a5d76419985243665c404d 100644 (file)
@@ -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);
+  }
 }