comparison dwt/internal/image/LEDataInputStream.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents bef543dec5c3
children fd9c62a2998e
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
49 pos = bufferSize; 49 pos = bufferSize;
50 } 50 }
51 else throw new IllegalArgumentException("bufferSize must be greater zero" ); 51 else throw new IllegalArgumentException("bufferSize must be greater zero" );
52 } 52 }
53 53
54 override public void close() { 54 public void close() {
55 buf = null; 55 buf = null;
56 if (host !is null) { 56 if (host !is null) {
57 host.close(); 57 host.close();
58 host = null; 58 host = null;
59 } 59 }
67 } 67 }
68 68
69 /** 69 /**
70 * Answers how many bytes are available for reading without blocking 70 * Answers how many bytes are available for reading without blocking
71 */ 71 */
72 override public int available() { 72 public override int available() {
73 if (buf is null) throw new IOException("buf is null"); 73 if (buf is null) throw new IOException("buf is null");
74 return (buf.length - pos) + host.available(); 74 return (buf.length - pos) + host.available();
75 } 75 }
76 76
77 /** 77 /**
78 * Answer the next byte of the input stream. 78 * Answer the next byte of the input stream.
79 */ 79 */
80 override public int read() { 80 public override int read() {
81 if (buf is null) throw new IOException("buf is null"); 81 if (buf is null) throw new IOException("buf is null");
82 if (pos < buf.length) { 82 if (pos < buf.length) {
83 position++; 83 position++;
84 return (buf[pos++] & 0xFF); 84 return (buf[pos++] & 0xFF);
85 } 85 }
90 90
91 /** 91 /**
92 * Don't imitate the JDK behaviour of reading a random number 92 * Don't imitate the JDK behaviour of reading a random number
93 * of bytes when you can actually read them all. 93 * of bytes when you can actually read them all.
94 */ 94 */
95 override public int read(byte b[], int off, int len) { 95 public override int read(byte b[], int off, int len) {
96 int read_ = 0, count; 96 int read = 0, count;
97 while (read_ !is len && (count = readData(b, off, len - read_)) !is -1) { 97 while (read !is len && (count = readData(b, off, len - read)) !is -1) {
98 off += count; 98 off += count;
99 read_ += count; 99 read += count;
100 } 100 }
101 position += read_; 101 position += read;
102 if (read_ is 0 && read_ !is len) return -1; 102 if (read is 0 && read !is len) return -1;
103 return read_; 103 return read;
104 } 104 }
105 105
106 /** 106 /**
107 * Reads at most <code>length</code> bytes from this LEDataInputStream and 107 * Reads at most <code>length</code> bytes from this LEDataInputStream and
108 * stores them in byte array <code>buffer</code> starting at <code>offset</code>. 108 * stores them in byte array <code>buffer</code> starting at <code>offset</code>.
141 141
142 // Have we copied enough? 142 // Have we copied enough?
143 if (cacheCopied is len) return len; 143 if (cacheCopied is len) return len;
144 144
145 int inCopied = host.read( buffer, newOffset, len - cacheCopied ); 145 int inCopied = host.read( buffer, newOffset, len - cacheCopied );
146 if( inCopied is -1 ) inCopied = -1;
146 if (inCopied > 0 ) return inCopied + cacheCopied; 147 if (inCopied > 0 ) return inCopied + cacheCopied;
147 if (cacheCopied is 0) return inCopied; 148 if (cacheCopied is 0) return inCopied;
148 return cacheCopied; 149 return cacheCopied;
149 } 150 }
150 151
153 * four bytes of the input stream. 154 * four bytes of the input stream.
154 */ 155 */
155 public int readInt() { 156 public int readInt() {
156 byte[4] buf = void; 157 byte[4] buf = void;
157 read(buf); 158 read(buf);
158 return ((((((buf[3] & 0xFF) << 24) | 159 return ((buf[3] & 0xFF) << 24) |
159 (buf[2] & 0xFF)) << 16) | 160 ((buf[2] & 0xFF) << 16) |
160 (buf[1] & 0xFF)) << 8) | 161 ((buf[1] & 0xFF) << 8) |
161 (buf[0] & 0xFF); 162 (buf[0] & 0xFF);
162 } 163 }
163 164
164 /** 165 /**
165 * Answer a short comprised of the next 166 * Answer a short comprised of the next