Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/imageio/plugins/jpeg/TruncatedImageWarningTest.java
41152 views
1
/*
2
* Copyright (c) 2014, 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 8032370
27
*
28
* @summary Test verifies that Image I/O jpeg reader correctly handles
29
* and warns of a truncated image stream.
30
*
31
* @run main TruncatedImageWarningTest
32
*/
33
34
import java.io.File;
35
import java.io.IOException;
36
import javax.imageio.ImageIO;
37
import javax.imageio.ImageReader;
38
import javax.imageio.event.IIOReadWarningListener;
39
import javax.imageio.stream.ImageInputStream;
40
41
public class TruncatedImageWarningTest implements IIOReadWarningListener {
42
43
private static String fileName = "truncated.jpg";
44
boolean receivedWarning = false;
45
46
public static void main(String[] args) throws IOException {
47
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
ImageInputStream in = ImageIO.createImageInputStream(f);
54
ImageReader reader = ImageIO.getImageReaders(in).next();
55
TruncatedImageWarningTest twt = new TruncatedImageWarningTest();
56
reader.addIIOReadWarningListener(twt);
57
reader.setInput(in);
58
reader.read(0);
59
if (!twt.receivedWarning) {
60
throw new RuntimeException("No expected warning");
61
}
62
}
63
64
public void warningOccurred(ImageReader source, String warning) {
65
System.out.println("Expected warning: " + warning);
66
receivedWarning = true;
67
}
68
}
69
70