Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/imageio/plugins/jpeg/ReadAllThumbnailsTest.java
41152 views
1
/*
2
* Copyright (c) 2004, 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 4958271 8160943
27
* @summary This test verifies that ImageReader.readAll() method is able to read
28
* all the thumbnails present in the input source without throwing any
29
* exception while reading through Jpeg data.
30
* @run main ReadAllThumbnailsTest
31
*/
32
33
import java.util.Iterator;
34
import java.io.File;
35
import javax.imageio.IIOImage;
36
import javax.imageio.ImageIO;
37
import javax.imageio.ImageReader;
38
import javax.imageio.stream.ImageInputStream;
39
40
public class ReadAllThumbnailsTest {
41
42
public ReadAllThumbnailsTest() {
43
44
try {
45
ImageReader reader = null;
46
47
String fileName = "thumbimg.jpg";
48
String sep = System.getProperty("file.separator");
49
String dir = System.getProperty("test.src", ".");
50
String filePath = dir+sep+fileName;
51
System.out.println("Test file: " + filePath);
52
File f = new File(filePath);
53
54
ImageInputStream iis = ImageIO.createImageInputStream(f);
55
Iterator readerIt = ImageIO.getImageReaders(iis);
56
if (readerIt.hasNext()) {
57
reader = (ImageReader) readerIt.next();
58
}
59
60
if (reader == null) {
61
error("FAIL: Reader is not available for reading a " +
62
"JPG image with thumbnails. Test Aborted !!");
63
}
64
65
reader.setInput(iis);
66
67
if (!reader.readerSupportsThumbnails()) {
68
error("FAIL: JPG Reader fails to support thumbnails."
69
+ " Test aborted !!");
70
}
71
72
int numThumbnails = reader.getNumThumbnails(0);
73
if (numThumbnails <= 0) {
74
error(" FAIL: Reader.getNumThumbnails() returns 0 when the " +
75
"input image contains some thumbnails");
76
}
77
IIOImage iioImg = reader.readAll(0, null);
78
int thumbnailsRead = iioImg.getNumThumbnails();
79
80
if (numThumbnails == thumbnailsRead) {
81
System.out.println("PASS: Thumbnails are read properly by"
82
+ " ImageReader.readAll(index, readParam) ");
83
} else {
84
error("FAIL: Some of the thumbnails are not read" +
85
" from the input source when calling" +
86
" ImageReader.readAll(index, readParam) ");
87
}
88
89
iis = ImageIO.createImageInputStream(f);
90
reader.setInput(iis);
91
92
iioImg = null;
93
Iterator imgIter = reader.readAll(null);
94
if (imgIter.hasNext()) {
95
iioImg = (IIOImage) imgIter.next();
96
thumbnailsRead = iioImg.getNumThumbnails();
97
98
if (numThumbnails == thumbnailsRead) {
99
System.out.println("PASS: Thumbnails are read properly by"
100
+ " ImageReader.readAll(Iter)");
101
} else {
102
error("FAIL: Some of the thumbnails are not read " +
103
"from the input source when calling"
104
+ " ImageReader.readAll(Iter)");
105
}
106
} else {
107
error("FAIL: ImageReader.readAll(Iter) fails to read the image"
108
+ " & thumbnails from the input source");
109
}
110
111
} catch (Exception e) {
112
error(" FAIL: The following exception is thrown by " +
113
"ImageReader.readAll() method when input source contains " +
114
"some thumbnails. Exception: " + e.toString());
115
}
116
117
}
118
119
public final void error(String mesg) {
120
throw new RuntimeException(mesg);
121
}
122
123
public static void main(String args[]) {
124
ReadAllThumbnailsTest test = new ReadAllThumbnailsTest();
125
}
126
}
127
128