|
Description
|
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)
======================================================================
Posted Date : 2005-09-22 18:43:05.0
Peabody community fix submitted by: (company - Self , email - xxxxx@xxxxx -mlv.fr)
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
Posted Date : 2005-11-28 17:47:15.0
|
|
Evaluation
|
This information is available via the SPI.
Also the ImageIO class will return the list of informal names via
the ImageIO.getWriterFormatNames() method.
It would be possible however to add an additional convenience method to
the ImageIO class. If doing this then a getWriterSuffixes() method should
be added too.
xxxxx@xxxxx 2002-06-17
=============================
This is a reasonable request, and should be simple to add these two new methods
to the ImageIO convenience class. Committing to fix in Mustang.
xxxxx@xxxxx 2004-07-19
Missed mustang, retarget to dolphin.
Posted Date : 2005-09-22 18:43:05.0
A complete fix and testcase has been provided by a developer from the
jdk-collaboration community, which was attached to this bug report. This is a
low-risk RFE, so we should try to get this in for Mustang. Will require a CCC
request though.
Posted Date : 2005-11-30 07:59:26.0
Contribution-Forum:https://jdk-collaboration.dev.java.net/servlets/ProjectForumMessageView?forumID=1463&messageID=10399
Posted Date : 2005-12-06 17:43:40.0
|