Debian Codegraph @

tests/reproducers/simple/IcoAccess/srcs/IcoAccess.java

raw
1
2 import java.applet.Applet;
3 import java.awt.image.BufferedImage;
4 import java.io.BufferedInputStream;
5 import java.io.ByteArrayInputStream;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.net.MalformedURLException;
9 import java.net.URL;
10 import javax.imageio.ImageIO;
11 import javax.jnlp.BasicService;
12 import javax.jnlp.ServiceManager;
13 import javax.jnlp.UnavailableServiceException;
14
15
16 /* SimpleTest1.java
17 Copyright (C) 2011 Red Hat, Inc.
18
19 This file is part of IcedTea.
20
21 IcedTea is free software; you can redistribute it and/or
22 modify it under the terms of the GNU General Public License as published by
23 the Free Software Foundation, version 2.
24
25 IcedTea is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 General Public License for more details.
29
30 You should have received a copy of the GNU General Public License
31 along with IcedTea; see the file COPYING. If not, write to
32 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
33 02110-1301 USA.
34
35 Linking this library statically or dynamically with other modules is
36 making a combined work based on this library. Thus, the terms and
37 conditions of the GNU General Public License cover the whole
38 combination.
39
40 As a special exception, the copyright holders of this library give you
41 permission to link this library with independent modules to produce an
42 executable, regardless of the license terms of these independent
43 modules, and to copy and distribute the resulting executable under
44 terms of your choice, provided that you also meet, for each linked
45 independent module, the terms and conditions of the license of that
46 module. An independent module is a module which is not derived from
47 or based on this library. If you modify this library, you may extend
48 this exception to your version of the library, but you are not
49 obligated to do so. If you do not wish to do so, delete this
50 exception statement from your version.
51 */
52 public class IcoAccess extends Applet{
53
54 @Override
55 public void init() {
56 try {
57 main(getCodeBase().toExternalForm());
58 } catch (Exception ex){
59 ex.printStackTrace();
60 }
61 }
62
63 public static void main(String... args) throws UnavailableServiceException, MalformedURLException, IOException {
64 //args = new String[]{"http://localhost:44321"};
65 System.out.println("IcoAccess running");
66 final URL codeBase;
67 if (args.length == 0) {
68 final BasicService bs = (BasicService) ServiceManager.lookup(
69 "javax.jnlp.BasicService");
70 codeBase = bs.getCodeBase();
71 } else {
72 //for "normal" app tsting and appelts
73 codeBase = new URL(args[0]);
74 }
75 System.out.println(codeBase);
76 URL ico = new URL(codeBase + "/IcoAccess.ico");
77 URL png = new URL(codeBase + "/IcoAccess.png");
78 System.out.println(ico);
79 byte[] b = new byte[1406];
80 for (int i = 0; i < b.length; i++) {
81 b[i] = 0;
82
83 }
84 try (InputStream is = ico.openStream()) {
85 is.read(b);
86 }
87 check(0, b[0]);
88 check(0, b[1]);
89 check(1, b[2]);
90 check(0, b[3]);
91 check(1, b[4]);
92 check(0, b[5]);
93 check(16, b[6]);
94 check(16, b[7]);
95 check(0, b[1273]);
96 for (int i = 1274; i <= 1341; i++) {
97 check(1, b[i]);
98 }
99 check(0, b[1342]);
100 System.out.println("array checks passed");
101 BufferedImage i = ImageIO.read(new BufferedInputStream(new ByteArrayInputStream(b)));
102 System.out.println("ico: " + i);
103 System.out.println("IcoAccess ended");
104 BufferedImage i2 = ImageIO.read(png);
105 System.out.println("png: " + i2);
106 System.out.println("*** APPLET FINISHED ***");
107
108 }
109
110 private static void check(int i, byte b) {
111 if (i != b) {
112 throw new RuntimeException("The image was not laoded!");
113 }
114 }
115 }