72a1ae9c0728e899c939258a5bb78ef4c7832021
[jalviewjs.git] / site / swingjs / j2s / jssun / misc / Resource.js
1 Clazz.declarePackage ("jssun.misc");
2 Clazz.load (null, "jssun.misc.Resource", ["java.io.EOFException", "java.lang.Thread", "java.util.Arrays"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.cis = null;
5 Clazz.instantialize (this, arguments);
6 }, jssun.misc, "Resource");
7 Clazz.defineMethod (c$, "cachedInputStream", 
8  function () {
9 if (this.cis == null) {
10 this.cis = this.getInputStream ();
11 }return this.cis;
12 });
13 Clazz.defineMethod (c$, "getBytes", 
14 function () {
15 var b;
16 var $in = this.cachedInputStream ();
17 var isInterrupted = Thread.interrupted ();
18 var len;
19 for (; ; ) {
20 try {
21 len = this.getContentLength ();
22 break;
23 } catch (iioe) {
24 if (Clazz.exceptionOf (iioe, java.io.InterruptedIOException)) {
25 Thread.interrupted ();
26 isInterrupted = true;
27 } else {
28 throw iioe;
29 }
30 }
31 }
32 try {
33 b =  Clazz.newByteArray (0, 0);
34 if (len == -1) len = 2147483647;
35 var pos = 0;
36 while (pos < len) {
37 var bytesToRead;
38 if (pos >= b.length) {
39 bytesToRead = Math.min (len - pos, b.length + 1024);
40 if (b.length < pos + bytesToRead) {
41 b = java.util.Arrays.copyOf (b, pos + bytesToRead);
42 }} else {
43 bytesToRead = b.length - pos;
44 }var cc = 0;
45 try {
46 cc = $in.read (b, pos, bytesToRead);
47 } catch (iioe) {
48 if (Clazz.exceptionOf (iioe, java.io.InterruptedIOException)) {
49 Thread.interrupted ();
50 isInterrupted = true;
51 } else {
52 throw iioe;
53 }
54 }
55 if (cc < 0) {
56 if (len != 2147483647) {
57 throw  new java.io.EOFException ("Detect premature EOF");
58 } else {
59 if (b.length != pos) {
60 b = java.util.Arrays.copyOf (b, pos);
61 }break;
62 }}pos += cc;
63 }
64 } finally {
65 try {
66 $in.close ();
67 } catch (e$$) {
68 if (Clazz.exceptionOf (e$$, java.io.InterruptedIOException)) {
69 var iioe = e$$;
70 {
71 isInterrupted = true;
72 }
73 } else if (Clazz.exceptionOf (e$$, java.io.IOException)) {
74 var ignore = e$$;
75 {
76 }
77 } else {
78 throw e$$;
79 }
80 }
81 if (isInterrupted) {
82 Thread.currentThread ().interrupt ();
83 }}
84 return b;
85 });
86 });