Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/imageio/spi/PluginSpiTest.java
38839 views
1
/*
2
* Copyright (c) 2005, 2017, 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 6275112
27
* @summary Test verifies that imageReaders for base image formats return
28
* meaningful name of service provider interface (SPI) for base image
29
* formats
30
*/
31
32
import javax.imageio.ImageIO;
33
import javax.imageio.ImageReader;
34
import javax.imageio.ImageWriter;
35
import javax.imageio.spi.ImageReaderSpi;
36
37
public class PluginSpiTest {
38
39
public static void main(String[] args) {
40
String format[] = { "GIF", "PNG", "JPEG", "BMP", "WBMP" };
41
for (int i = 0; i < format.length; i++) {
42
System.out.println("\nFormat " + format[i]);
43
testFormat(format[i]);
44
}
45
}
46
47
public static void testFormat(String format) {
48
ImageReader reader =
49
ImageIO.getImageReadersByFormatName(format).next();
50
if (reader == null) {
51
throw new RuntimeException("Failed to get reader for " + format);
52
}
53
54
ImageReaderSpi readerSpi = reader.getOriginatingProvider();
55
System.out.println(format + " Reader SPI: " + readerSpi);
56
57
String writerSpiNames[] = readerSpi.getImageWriterSpiNames();
58
if (writerSpiNames == null || writerSpiNames.length == 0) {
59
throw new RuntimeException("Failed to get writer spi names for " +
60
format);
61
}
62
63
System.out.println("Available writer spi names:");
64
for (int i = 0; i < writerSpiNames.length; i++) {
65
System.out.println(writerSpiNames[i]);
66
try {
67
Class spiClass = Class.forName(writerSpiNames[i]);
68
if (spiClass == null) {
69
throw new RuntimeException("Failed to get spi class " +
70
writerSpiNames[i]);
71
}
72
System.out.println("Got class " + spiClass.getName());
73
74
Object spiObject = spiClass.newInstance();
75
if (spiObject == null) {
76
throw new RuntimeException("Failed to instantiate spi " +
77
writerSpiNames[i]);
78
}
79
System.out.println("Got instance " + spiObject);
80
} catch (Throwable e) {
81
throw new RuntimeException("Failed to test spi " +
82
writerSpiNames[i]);
83
}
84
}
85
86
ImageWriter writer = ImageIO.getImageWriter(reader);
87
if (writer == null) {
88
throw new RuntimeException("Failed to get writer for " + format);
89
}
90
}
91
}
92
93