|
1 /* |
|
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. |
|
8 * |
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
|
13 * accompanied this code). |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License version |
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 * |
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 * or visit www.oracle.com if you need additional information or have any |
|
21 * questions. |
|
22 */ |
|
23 |
|
24 /* |
|
25 * @test |
|
26 * @bug 8163258 |
|
27 * @summary Test verifies that when we create our own ImageReaderSpi |
|
28 * implementaion with MIMEType or FileSuffix as null, it should |
|
29 * not throw NullPointerException when we call |
|
30 * ImageIO.getReaderMIMETypes() or ImageIO.getReaderFileSuffixes(). |
|
31 * @run main GetReaderWriterInfoNullTest |
|
32 */ |
|
33 |
|
34 import java.awt.image.BufferedImage; |
|
35 import java.io.IOException; |
|
36 import java.util.Iterator; |
|
37 import java.util.Locale; |
|
38 import javax.imageio.IIOException; |
|
39 import javax.imageio.ImageReadParam; |
|
40 import javax.imageio.ImageReader; |
|
41 import javax.imageio.ImageTypeSpecifier; |
|
42 import javax.imageio.metadata.IIOMetadata; |
|
43 import javax.imageio.spi.ImageReaderSpi; |
|
44 import javax.imageio.stream.ImageInputStream; |
|
45 import javax.imageio.ImageIO; |
|
46 import javax.imageio.spi.IIORegistry; |
|
47 |
|
48 class TestImageReaderSpi extends ImageReaderSpi { |
|
49 |
|
50 public TestImageReaderSpi(String[] FORMATNAMES, String[] SUFFIXES, |
|
51 String[] MIMETYPES) { |
|
52 super("J Duke", // vendor |
|
53 "1.0", // version |
|
54 FORMATNAMES, // format names |
|
55 SUFFIXES, // file suffixes |
|
56 MIMETYPES, // mimetypes |
|
57 "readTest.TestImageReader", // reader class name |
|
58 new Class<?>[] { ImageInputStream.class }, // input types |
|
59 null, // writer class names. |
|
60 true, // supports native metadata, |
|
61 null, // [no] native stream metadata format |
|
62 null, // [no] native stream metadata class |
|
63 null, // [no] native extra stream metadata format |
|
64 null, // [no] native extra stream metadata class |
|
65 true, // supports standard metadata, |
|
66 null, // metadata format name, |
|
67 null, // metadata format class name |
|
68 null, // [no] extra image metadata format |
|
69 null // [no] extra image metadata format class |
|
70 ); |
|
71 } |
|
72 |
|
73 @Override |
|
74 public boolean canDecodeInput(Object source) throws IOException { |
|
75 throw new UnsupportedOperationException("Not supported yet."); |
|
76 } |
|
77 |
|
78 @Override |
|
79 public String getDescription(Locale locale) { |
|
80 throw new UnsupportedOperationException("Not supported yet."); |
|
81 } |
|
82 |
|
83 @Override |
|
84 public ImageReader createReaderInstance(Object extension) |
|
85 throws IOException { |
|
86 throw new UnsupportedOperationException("Not supported yet."); |
|
87 } |
|
88 |
|
89 } |
|
90 |
|
91 class TestImageReader extends ImageReader { |
|
92 |
|
93 public TestImageReader(ImageReaderSpi originatingProvider) { |
|
94 super(originatingProvider); |
|
95 } |
|
96 |
|
97 @Override |
|
98 public int getNumImages(boolean allowSearch) throws IOException { |
|
99 throw new UnsupportedOperationException("Not supported yet."); |
|
100 } |
|
101 |
|
102 @Override |
|
103 public int getWidth(int imageIndex) throws IOException { |
|
104 throw new UnsupportedOperationException("Not supported yet."); |
|
105 } |
|
106 |
|
107 @Override |
|
108 public int getHeight(int imageIndex) throws IOException { |
|
109 throw new UnsupportedOperationException("Not supported yet."); |
|
110 } |
|
111 |
|
112 @Override |
|
113 public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex) |
|
114 throws IOException { |
|
115 throw new UnsupportedOperationException("Not supported yet."); |
|
116 } |
|
117 |
|
118 @Override |
|
119 public IIOMetadata getStreamMetadata() throws IOException { |
|
120 throw new UnsupportedOperationException("Not supported yet."); |
|
121 } |
|
122 |
|
123 @Override |
|
124 public IIOMetadata getImageMetadata(int imageIndex) throws IOException { |
|
125 throw new UnsupportedOperationException("Not supported yet."); |
|
126 } |
|
127 |
|
128 @Override |
|
129 public BufferedImage read(int imageIndex, ImageReadParam param) |
|
130 throws IOException { |
|
131 throw new UnsupportedOperationException("Not supported yet."); |
|
132 } |
|
133 } |
|
134 public class GetReaderWriterInfoNullTest { |
|
135 static final String[] FORMATNAMES = {"readTest"}; |
|
136 static final String[] SUFFIXES = {"readTest"}; |
|
137 static final String[] MIMETYPES = {"readTest"}; |
|
138 public static void main (String[] args) throws IIOException { |
|
139 // Verify getReaderMIMETypes() behavior by keeping MIMEType as null. |
|
140 TestImageReaderSpi mimeNullReadSpi = |
|
141 new TestImageReaderSpi(FORMATNAMES, SUFFIXES, null); |
|
142 IIORegistry.getDefaultInstance(). |
|
143 registerServiceProvider(mimeNullReadSpi); |
|
144 ImageIO.getReaderMIMETypes(); |
|
145 IIORegistry.getDefaultInstance(). |
|
146 deregisterServiceProvider(mimeNullReadSpi); |
|
147 |
|
148 /* |
|
149 * Verify getReaderFileSuffixes() behavior by keeping |
|
150 * file suffix as null. |
|
151 */ |
|
152 TestImageReaderSpi suffixNullReadSpi = |
|
153 new TestImageReaderSpi(FORMATNAMES, null, MIMETYPES); |
|
154 IIORegistry.getDefaultInstance(). |
|
155 registerServiceProvider(suffixNullReadSpi); |
|
156 ImageIO.getReaderFileSuffixes(); |
|
157 IIORegistry.getDefaultInstance(). |
|
158 deregisterServiceProvider(suffixNullReadSpi); |
|
159 } |
|
160 } |
|
161 |