author | jdv |
Wed, 10 Jan 2018 12:45:14 +0530 | |
changeset 48643 | 2ea3667af41d |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
39545
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
1 |
/* |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
4 |
* |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
8 |
* |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
13 |
* accompanied this code). |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
14 |
* |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
18 |
* |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
21 |
* questions. |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
22 |
*/ |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
23 |
|
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
24 |
/* |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
25 |
* @test |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
26 |
* @bug 8152672 |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
27 |
* @summary When jpeg file has more than one set of EOI-SOI markers, |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
28 |
* test verifies whether we calculate EOI markers of all images |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
29 |
* properly skipping EOI markers present in application headers. |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
30 |
* @run main JpegMultipleEOITest |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
31 |
*/ |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
32 |
|
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
33 |
import java.io.File; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
34 |
import java.io.IOException; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
35 |
import java.util.Iterator; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
36 |
import javax.imageio.ImageIO; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
37 |
import javax.imageio.ImageReader; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
38 |
import javax.imageio.stream.ImageInputStream; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
39 |
|
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
40 |
public class JpegMultipleEOITest { |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
41 |
public static void main (String[] args) throws IOException { |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
42 |
Iterator readers = ImageIO.getImageReadersByFormatName("JPEG"); |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
43 |
ImageReader reader = null; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
44 |
while(readers.hasNext()) { |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
45 |
reader = (ImageReader)readers.next(); |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
46 |
if(reader.canReadRaster()) { |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
47 |
break; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
48 |
} |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
49 |
} |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
50 |
|
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
51 |
if (reader != null) { |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
52 |
String fileName = "JpegMultipleEOI.jpg"; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
53 |
String sep = System.getProperty("file.separator"); |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
54 |
String dir = System.getProperty("test.src", "."); |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
55 |
String filePath = dir+sep+fileName; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
56 |
System.out.println("Test file: " + filePath); |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
57 |
File imageFile = new File(filePath); |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
58 |
ImageInputStream stream = ImageIO. |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
59 |
createImageInputStream(imageFile); |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
60 |
reader.setInput(stream); |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
61 |
int pageNum = 1; |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
62 |
try { |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
63 |
// read width of image index 1 |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
64 |
reader.getWidth(pageNum + reader.getMinIndex()); |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
65 |
} catch (IndexOutOfBoundsException e) { |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
66 |
/* |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
67 |
* do nothing, we are supposed to get IndexOutofBoundsException |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
68 |
* as number of image is 1 and we are trying to get width of |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
69 |
* second image. But we should not see IIOException with |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
70 |
* message "Not a JPEG file: starts with 0xff 0xe2" |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
71 |
*/ |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
72 |
} |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
73 |
} |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
74 |
} |
1b92907cf159
8152672: IIOException while getting second image properties for JPEG
jdv
parents:
diff
changeset
|
75 |
} |