-
Enhancement
-
Resolution: Fixed
-
P3
-
6
-
b67
-
generic, x86
-
generic, windows_2000
Name: rmT116609 Date: 06/17/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
DESCRIPTION OF THE PROBLEM :
add getReaderFileSuffixes() to the ImageIO class, same as
getReaderMIMETypes() and getReaderFormatTypes() but with
FileSuffixes
Additioanl Information:
When bringing up an Open File dialog, we need to know the file suffixes to
be filterred on. Currently I have just cut and pasted 1 of the other 2
methods (getReaderMIMETypes() and getReaderFormatTypes()), and changed it to
use FileSuffixes. This does the job however this method should be in
ImageIO with the other two. It looks like a small oversight that it wasn't
already included.
(Review ID: 153678)
======================================================================
Peabody community fix submitted by: (company - Self , email - ###@###.###)
A DESCRIPTION OF THE FIX :
I've written getReaderFileSuffixes() and getWriterFileSuffixes() has
described in the evaluation of the bug.
ImageIO is not converted to using generics and
doesn't use some methods from the collection API,
this explains why the code of getReaderFileSuffixes() is not
just a copy/paste from getReaderFormatNames().
Futhermore, there are lost of code duplication between
get(Reader|Writer)(FileSuffixes|FormatNames|MIMETypes),
i think these methods could use a common code.
So at the ends of this message you can find a version that share the
same code between all the methods.
java -version :
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b57)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b57, mixed mode)
diff -u ImageIO.java.old IomageIO.java.new :
--- ImageIO.java.old Thu Nov 24 21:52:16 2005
+++ ImageIO.java.new Thu Nov 24 21:37:09 2005
@@ -18,6 +18,7 @@
import java.security.AccessController;
import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -468,6 +469,32 @@
return toStringArray(s);
}
+
+ /**
+ * Returns an array of <code>String</code>s listing all of the
+ * file suffixes associated with the formats understood
+ * by the current set of registered readers.
+ *
+ * @return an array of <code>String</code>s.
+ */
+ public static String[] getReaderFileSuffixes() {
+
+ Iterator<ImageReaderSpi> iter;
+ // Ensure category is present
+ try {
+ iter = theRegistry.getServiceProviders(ImageReaderSpi.class, true);
+ } catch (IllegalArgumentException e) {
+ return new String[0];
+ }
+
+ HashSet<String> s = new HashSet<String>();
+ while (iter.hasNext()) {
+ ImageReaderSpi spi = iter.next();
+ Collections.addAll(s,spi.getFileSuffixes());
+ }
+
+ return s.toArray(new String[s.size()]);
+ }
static class ImageReaderIterator implements Iterator<ImageReader> {
// Contains ImageReaderSpis
@@ -800,6 +827,32 @@
}
return toStringArray(s);
+ }
+
+ /**
+ * Returns an array of <code>String</code>s listing all of the
+ * file suffixes associated with the formats understood
+ * by the current set of registered writers.
+ *
+ * @return an array of <code>String</code>s.
+ */
+ public static String[] getWriterFileSuffixes() {
+
+ Iterator<ImageWriterSpi> iter;
+ // Ensure category is present
+ try {
+ iter = theRegistry.getServiceProviders(ImageWriterSpi.class, true);
+ } catch (IllegalArgumentException e) {
+ return new String[0];
+ }
+
+ HashSet<String> s = new HashSet<String>();
+ while (iter.hasNext()) {
+ ImageWriterSpi spi = iter.next();
+ Collections.addAll(s,spi.getFileSuffixes());
+ }
+
+ return s.toArray(new String[s.size()]);
}
static class ImageWriterIterator implements Iterator<ImageWriter> {
The code in case of shaing code :
enum SpiInfo {
FORMAT_NAMES {
@Override String[] info(ImageReaderWriterSpi spi) {
return spi.getFormatNames();
}
},
MIME_TYPES {
@Override String[] info(ImageReaderWriterSpi spi) {
return spi.getMIMETypes();
}
},
FILE_SUFFIXES {
@Override String[] info(ImageReaderWriterSpi spi) {
return spi.getFileSuffixes();
}
};
abstract String[] info(ImageReaderWriterSpi spi);
}
public static String[] getWriterFormatNames() {
return getReaderWriterInfos(ImageWriterSpi.class,SpiInfo.FORMAT_NAMES);
}
public static String[] getWriterMIMETypes() {
return getReaderWriterInfos(ImageWriterSpi.class,SpiInfo.MIME_TYPES);
}
public static String[] getWriterFileSuffixes() {
return getReaderWriterInfos(ImageWriterSpi.class,SpiInfo.FILE_SUFFIXES);
}
public static String[] getReaderFormatNames() {
return getReaderWriterInfos(ImageReaderSpi.class,SpiInfo.FORMAT_NAMES);
}
public static String[] getReaderMIMETypes() {
return getReaderWriterInfos(ImageReaderSpi.class,SpiInfo.MIME_TYPES);
}
public static String[] getReaderFileSuffixes() {
return getReaderWriterInfos(ImageReaderSpi.class,SpiInfo.FILE_SUFFIXES);
}
private static <S extends ImageReaderWriterSpi>
String[] getReaderWriterInfos(Class<S> spiClass,SpiInfo info) {
Iterator<S> iter;
// Ensure category is present
try {
iter = theRegistry.getServiceProviders(spiClass, true);
} catch (IllegalArgumentException e) {
return new String[0];
}
HashSet<String> s = new HashSet<String>();
while (iter.hasNext()) {
ImageReaderWriterSpi spi = iter.next();
Collections.addAll(s,spi.getFileSuffixes());
}
return s.toArray(new String[s.size()]);
}
Rémi Forax
JUnit TESTCASE :
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageWriter;
public class Test {
public static void testGetReaderFileSuffixes() {
String[] suffixes=ImageIO.getReaderFileSuffixes();
for(String suffixe:suffixes) {
Iterator<ImageReader> it = ImageIO.getImageReadersBySuffix(suffixe);
if (!it.hasNext())
throw new AssertionError("getReaderFileSuffixes returns an unknown suffixe");
}
}
public static void testGetWriterFileSuffixes() {
String[] suffixes=ImageIO.getWriterFileSuffixes();
for(String suffixe:suffixes) {
Iterator<ImageWriter> it = ImageIO.getImageWritersBySuffix(suffixe);
if (!it.hasNext())
throw new AssertionError("getWriterFileSuffixes returns an unknown suffixe");
}
}
public static void main(String[] args) {
testGetReaderFileSuffixes();
testGetWriterFileSuffixes();
}
}
FIX FOR BUG NUMBER:
4703112
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
DESCRIPTION OF THE PROBLEM :
add getReaderFileSuffixes() to the ImageIO class, same as
getReaderMIMETypes() and getReaderFormatTypes() but with
FileSuffixes
Additioanl Information:
When bringing up an Open File dialog, we need to know the file suffixes to
be filterred on. Currently I have just cut and pasted 1 of the other 2
methods (getReaderMIMETypes() and getReaderFormatTypes()), and changed it to
use FileSuffixes. This does the job however this method should be in
ImageIO with the other two. It looks like a small oversight that it wasn't
already included.
(Review ID: 153678)
======================================================================
Peabody community fix submitted by: (company - Self , email - ###@###.###)
A DESCRIPTION OF THE FIX :
I've written getReaderFileSuffixes() and getWriterFileSuffixes() has
described in the evaluation of the bug.
ImageIO is not converted to using generics and
doesn't use some methods from the collection API,
this explains why the code of getReaderFileSuffixes() is not
just a copy/paste from getReaderFormatNames().
Futhermore, there are lost of code duplication between
get(Reader|Writer)(FileSuffixes|FormatNames|MIMETypes),
i think these methods could use a common code.
So at the ends of this message you can find a version that share the
same code between all the methods.
java -version :
java version "1.6.0-ea"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-ea-b57)
Java HotSpot(TM) Client VM (build 1.6.0-ea-b57, mixed mode)
diff -u ImageIO.java.old IomageIO.java.new :
--- ImageIO.java.old Thu Nov 24 21:52:16 2005
+++ ImageIO.java.new Thu Nov 24 21:37:09 2005
@@ -18,6 +18,7 @@
import java.security.AccessController;
import java.util.Arrays;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -468,6 +469,32 @@
return toStringArray(s);
}
+
+ /**
+ * Returns an array of <code>String</code>s listing all of the
+ * file suffixes associated with the formats understood
+ * by the current set of registered readers.
+ *
+ * @return an array of <code>String</code>s.
+ */
+ public static String[] getReaderFileSuffixes() {
+
+ Iterator<ImageReaderSpi> iter;
+ // Ensure category is present
+ try {
+ iter = theRegistry.getServiceProviders(ImageReaderSpi.class, true);
+ } catch (IllegalArgumentException e) {
+ return new String[0];
+ }
+
+ HashSet<String> s = new HashSet<String>();
+ while (iter.hasNext()) {
+ ImageReaderSpi spi = iter.next();
+ Collections.addAll(s,spi.getFileSuffixes());
+ }
+
+ return s.toArray(new String[s.size()]);
+ }
static class ImageReaderIterator implements Iterator<ImageReader> {
// Contains ImageReaderSpis
@@ -800,6 +827,32 @@
}
return toStringArray(s);
+ }
+
+ /**
+ * Returns an array of <code>String</code>s listing all of the
+ * file suffixes associated with the formats understood
+ * by the current set of registered writers.
+ *
+ * @return an array of <code>String</code>s.
+ */
+ public static String[] getWriterFileSuffixes() {
+
+ Iterator<ImageWriterSpi> iter;
+ // Ensure category is present
+ try {
+ iter = theRegistry.getServiceProviders(ImageWriterSpi.class, true);
+ } catch (IllegalArgumentException e) {
+ return new String[0];
+ }
+
+ HashSet<String> s = new HashSet<String>();
+ while (iter.hasNext()) {
+ ImageWriterSpi spi = iter.next();
+ Collections.addAll(s,spi.getFileSuffixes());
+ }
+
+ return s.toArray(new String[s.size()]);
}
static class ImageWriterIterator implements Iterator<ImageWriter> {
The code in case of shaing code :
enum SpiInfo {
FORMAT_NAMES {
@Override String[] info(ImageReaderWriterSpi spi) {
return spi.getFormatNames();
}
},
MIME_TYPES {
@Override String[] info(ImageReaderWriterSpi spi) {
return spi.getMIMETypes();
}
},
FILE_SUFFIXES {
@Override String[] info(ImageReaderWriterSpi spi) {
return spi.getFileSuffixes();
}
};
abstract String[] info(ImageReaderWriterSpi spi);
}
public static String[] getWriterFormatNames() {
return getReaderWriterInfos(ImageWriterSpi.class,SpiInfo.FORMAT_NAMES);
}
public static String[] getWriterMIMETypes() {
return getReaderWriterInfos(ImageWriterSpi.class,SpiInfo.MIME_TYPES);
}
public static String[] getWriterFileSuffixes() {
return getReaderWriterInfos(ImageWriterSpi.class,SpiInfo.FILE_SUFFIXES);
}
public static String[] getReaderFormatNames() {
return getReaderWriterInfos(ImageReaderSpi.class,SpiInfo.FORMAT_NAMES);
}
public static String[] getReaderMIMETypes() {
return getReaderWriterInfos(ImageReaderSpi.class,SpiInfo.MIME_TYPES);
}
public static String[] getReaderFileSuffixes() {
return getReaderWriterInfos(ImageReaderSpi.class,SpiInfo.FILE_SUFFIXES);
}
private static <S extends ImageReaderWriterSpi>
String[] getReaderWriterInfos(Class<S> spiClass,SpiInfo info) {
Iterator<S> iter;
// Ensure category is present
try {
iter = theRegistry.getServiceProviders(spiClass, true);
} catch (IllegalArgumentException e) {
return new String[0];
}
HashSet<String> s = new HashSet<String>();
while (iter.hasNext()) {
ImageReaderWriterSpi spi = iter.next();
Collections.addAll(s,spi.getFileSuffixes());
}
return s.toArray(new String[s.size()]);
}
Rémi Forax
JUnit TESTCASE :
import java.util.Iterator;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageWriter;
public class Test {
public static void testGetReaderFileSuffixes() {
String[] suffixes=ImageIO.getReaderFileSuffixes();
for(String suffixe:suffixes) {
Iterator<ImageReader> it = ImageIO.getImageReadersBySuffix(suffixe);
if (!it.hasNext())
throw new AssertionError("getReaderFileSuffixes returns an unknown suffixe");
}
}
public static void testGetWriterFileSuffixes() {
String[] suffixes=ImageIO.getWriterFileSuffixes();
for(String suffixe:suffixes) {
Iterator<ImageWriter> it = ImageIO.getImageWritersBySuffix(suffixe);
if (!it.hasNext())
throw new AssertionError("getWriterFileSuffixes returns an unknown suffixe");
}
}
public static void main(String[] args) {
testGetReaderFileSuffixes();
testGetWriterFileSuffixes();
}
}
FIX FOR BUG NUMBER:
4703112