12
|
1 package jp.ac.u_ryukyu.treevnc.server;
|
11
|
2
|
|
3 import static org.junit.Assert.*;
|
|
4
|
|
5 import java.awt.Graphics;
|
|
6 import java.awt.Image;
|
|
7 import java.awt.image.BufferedImage;
|
|
8 import java.io.BufferedOutputStream;
|
|
9 import java.io.BufferedReader;
|
|
10 import java.io.ByteArrayInputStream;
|
|
11 import java.io.ByteArrayOutputStream;
|
|
12 import java.io.IOException;
|
|
13 import java.io.InputStream;
|
|
14 import java.io.InputStreamReader;
|
|
15 import java.net.BindException;
|
|
16 import java.net.ServerSocket;
|
|
17 import java.net.Socket;
|
|
18 import java.nio.ByteBuffer;
|
|
19 import java.util.Iterator;
|
|
20 import java.util.LinkedList;
|
|
21
|
|
22 import javax.imageio.ImageIO;
|
|
23
|
|
24 import org.junit.Test;
|
|
25
|
|
26
|
|
27 //import myVncProxy.MulticastQueue.Client;
|
|
28
|
|
29 import java.util.concurrent.ExecutorService;
|
|
30 import java.util.concurrent.atomic.AtomicInteger;
|
|
31 import java.util.zip.DataFormatException;
|
|
32 import java.util.zip.Deflater;
|
|
33 import java.util.zip.Inflater;
|
|
34 import java.io.OutputStream;
|
|
35
|
12
|
36 import jp.ac.u_ryukyu.treevnc.MulticastQueue;
|
|
37
|
11
|
38 public class MyRfbProtoProxy {
|
|
39 final static String versionMsg_3_855 = "RFB 003.855\n";
|
|
40 /**
|
|
41 * CheckMillis is one of new msgType for RFB 3.855.
|
|
42 */
|
|
43 final static byte SpeedCheckMillis = 4;
|
|
44
|
|
45 // Secyrity type of OS X
|
|
46 final static int SecTypeReqAccess = 32;
|
|
47
|
|
48 // Supported authentication types
|
|
49 final static int AuthAccess = 32;
|
|
50
|
|
51 private static final int INFLATE_BUFSIZE = 1024 * 100;
|
|
52 boolean printStatusFlag = false;
|
|
53 long startCheckTime;
|
|
54 private int messageType;
|
|
55 private int rectangles;
|
|
56 private int rectX;
|
|
57 private int rectY;
|
|
58 private int rectW;
|
|
59 private int rectH;
|
|
60 private int encoding;
|
|
61 private int zLen;
|
|
62 private boolean clicomp = false;
|
|
63
|
|
64 private ServerSocket servSock;
|
|
65 protected int acceptPort;
|
|
66 // private byte initData[];
|
|
67 byte initData[];
|
|
68 private LinkedList<Socket> cliListTmp;
|
|
69 private LinkedList<Socket> cliList;
|
|
70 boolean createBimgFlag;
|
|
71 boolean proxyFlag = true;
|
|
72
|
|
73 ExecutorService executor;
|
|
74
|
|
75 byte[] pngBytes;
|
|
76
|
|
77 // private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new
|
|
78 // MostRecentMultiCast<LinkedList<ByteBuffer>>(10);
|
|
79 private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
|
|
80 private int clients = 0;
|
|
81 private Inflater inflater = new Inflater();
|
|
82 private Deflater deflater = new Deflater();
|
|
83 private CreateThread geth;
|
|
84 // private Thread requestThread;
|
|
85 private RequestScreenThread rThread;
|
|
86 private Thread requestThread;
|
|
87
|
|
88 public MyRfbProtoProxy() throws IOException {
|
|
89 }
|
|
90
|
|
91
|
|
92 void initServSock(int port) throws IOException {
|
|
93 servSock = new ServerSocket(port);
|
|
94 acceptPort = port;
|
|
95 }
|
|
96
|
|
97 /*
|
|
98 * default port number is 5999.
|
|
99 */
|
|
100 public void selectPort(int p) {
|
|
101 if (servSock != null)
|
|
102 return;
|
|
103 int port = p;
|
|
104 while (true) {
|
|
105 try {
|
|
106 initServSock(port);
|
|
107 break;
|
|
108 } catch (BindException e) {
|
|
109 port++;
|
|
110 continue;
|
|
111 } catch (IOException e) {
|
|
112
|
|
113 }
|
|
114 }
|
|
115 System.out.println("accept port = " + port);
|
|
116 }
|
|
117
|
|
118 int getAcceptPort() {
|
|
119 return acceptPort;
|
|
120 }
|
|
121
|
|
122 void setSoTimeout(int num) throws IOException {
|
|
123 servSock.setSoTimeout(num);
|
|
124 }
|
|
125
|
|
126 public Socket accept() throws IOException {
|
|
127 return servSock.accept();
|
|
128 }
|
|
129
|
|
130 void addSock(Socket sock) {
|
|
131 cliList.add(sock);
|
|
132 }
|
|
133
|
|
134 void addSockTmp(Socket sock) {
|
|
135 System.out.println("connected " + sock.getInetAddress());
|
|
136 cliListTmp.add(sock);
|
|
137 }
|
|
138
|
|
139 synchronized void changeStatusFlag() {
|
|
140 printStatusFlag = true;
|
|
141 }
|
|
142
|
|
143 void printMills() {
|
|
144 if (printStatusFlag) {
|
|
145
|
|
146 changeStatusFlag();
|
|
147 } else {
|
|
148 changeStatusFlag();
|
|
149 }
|
|
150 }
|
|
151
|
|
152
|
|
153 void requestThreadStart() {
|
|
154 requestThread.start();
|
|
155 }
|
|
156
|
|
157 public synchronized void requestThreadNotify() {
|
|
158 rThread.reStart();
|
|
159 }
|
|
160
|
|
161 /**
|
|
162 * gzip byte arrays
|
|
163 *
|
|
164 * @param deflater
|
|
165 * @param inputs
|
|
166 * byte data[]
|
|
167 * @param inputIndex
|
|
168 * @param outputs
|
|
169 * byte data[]
|
|
170 * @return byte length in last byte array
|
|
171 * @throws IOException
|
|
172 */
|
|
173 public int zip(Deflater deflater, LinkedList<ByteBuffer> inputs,
|
|
174 int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException {
|
|
175 int len = 0;
|
|
176 ByteBuffer c1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
|
|
177 while (inputIndex < inputs.size()) {
|
|
178 ByteBuffer b1 = inputs.get(inputIndex++);
|
|
179 deflater.setInput(b1.array(), b1.position(), b1.remaining());
|
|
180 /**
|
|
181 * If we finish() stream and reset() it, Deflater start new gzip
|
|
182 * stream, this makes continuous zlib reader unhappy. if we remove
|
|
183 * finish(), Deflater.deflate() never flushes its output. The
|
|
184 * original zlib deflate has flush flag. I'm pretty sure this a kind
|
|
185 * of bug of Java library.
|
|
186 */
|
|
187 if (inputIndex == inputs.size())
|
|
188 deflater.finish();
|
|
189 int len1 = 0;
|
|
190 do {
|
|
191 len1 = deflater.deflate(c1.array(), c1.position(),
|
|
192 c1.remaining());
|
|
193 if (len1 > 0) {
|
|
194 len += len1;
|
|
195 c1.position(c1.position() + len1);
|
|
196 if (c1.remaining() == 0) {
|
|
197 c1.flip();
|
|
198 outputs.addLast(c1);
|
|
199 c1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
|
|
200 }
|
|
201 }
|
|
202 } while (len1 > 0 || !deflater.needsInput()); // &&!deflater.finished());
|
|
203 }
|
|
204 if (c1.position() != 0) {
|
|
205 c1.flip();
|
|
206 outputs.addLast(c1);
|
|
207 }
|
|
208 deflater.reset();
|
|
209 return len;
|
|
210 }
|
|
211
|
|
212 /**
|
|
213 * gunzip byte arrays
|
|
214 *
|
|
215 * @param inflater
|
|
216 * @param inputs
|
|
217 * byte data[]
|
|
218 * @param outputs
|
|
219 * byte data[]
|
|
220 * @return number of total bytes
|
|
221 * @throws IOException
|
|
222 */
|
|
223 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs,
|
|
224 int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize)
|
|
225 throws DataFormatException {
|
|
226 int len = 0;
|
|
227 ByteBuffer buf = ByteBuffer.allocate(bufSize);
|
|
228 while (inputIndex < inputs.size()) {
|
|
229 ByteBuffer input = inputs.get(inputIndex++);
|
|
230 inflater.setInput(input.array(), input.position(), input.limit());
|
|
231 // if (inputIndex==inputs.size()) if inflater/deflater has symmetry,
|
|
232 // we need this
|
|
233 // inflater.end(); but this won't work
|
|
234 do {
|
|
235 int len0 = inflater.inflate(buf.array(), buf.position(),
|
|
236 buf.remaining());
|
|
237 if (len0 > 0) {
|
|
238 buf.position(buf.position() + len0);
|
|
239 len += len0;
|
|
240 if (buf.remaining() == 0) {
|
|
241 buf.flip();
|
|
242 outputs.addLast(buf);
|
|
243 buf = ByteBuffer.allocate(bufSize);
|
|
244 }
|
|
245 }
|
|
246 } while (!inflater.needsInput());
|
|
247 }
|
|
248 if (buf.position() != 0) {
|
|
249 buf.flip();
|
|
250 outputs.addLast(buf);
|
|
251 }
|
|
252 return len;
|
|
253 }
|
|
254
|
|
255 float maxMag = 1;
|
|
256
|
|
257 /**
|
|
258 * send data to clients
|
|
259 *
|
|
260 * @param dataLen
|
|
261 * @throws IOException
|
|
262 * @throws DataFormatException
|
|
263 *
|
|
264 * Zlibed packet is compressed in context dependent way, that
|
|
265 * is, it have to send from the beginning. But this is
|
|
266 * impossible. So we have to compress it again for each clients.
|
|
267 * Separate deflater for each clients is necessary.
|
|
268 *
|
|
269 * Java's deflater does not support flush. This means to get the
|
|
270 * result, we have to finish the compression. Reseting start new
|
|
271 * compression, but it is not accepted well in zlib continuous
|
|
272 * reading. So we need new Encoding ZRLEE which reset decoder
|
|
273 * for each packet. ZRLEE can be invisible from user, but it
|
|
274 * have to be implemented in the clients. ZRLEE compression is
|
|
275 * not context dependent, so no recompression is necessary.
|
|
276 */
|
|
277
|
|
278 void readSendData(int dataLen) throws IOException, DataFormatException {
|
|
279 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
|
|
280 ByteBuffer header = ByteBuffer.allocate(16);
|
|
281 readFully(header.array(), 0, 16);
|
|
282 header.limit(16);
|
|
283 if (header.get(0) == RfbProto.FramebufferUpdate) {
|
|
284 int encoding = header.getInt(12);
|
|
285 if (encoding == RfbProto.EncodingZRLE
|
|
286 || encoding == RfbProto.EncodingZlib) { // ZRLEE is already
|
|
287 // recompressed
|
|
288 ByteBuffer len = ByteBuffer.allocate(4);
|
|
289 readFully(len.array(), 0, 4);
|
|
290 len.limit(4);
|
|
291 ByteBuffer inputData = ByteBuffer.allocate(dataLen - 20);
|
|
292
|
|
293 readFully(inputData.array(), 0, inputData.capacity());
|
|
294 // System.out.println(dataLen);
|
|
295 inputData.limit(dataLen - 20);
|
|
296
|
|
297 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>();
|
|
298 inputs.add(inputData);
|
|
299
|
|
300 header.putInt(12, RfbProto.EncodingZRLEE); // means recompress
|
|
301 // every time
|
|
302 // using new Deflecter every time is incompatible with the
|
|
303 // protocol, clients have to be modified.
|
|
304 Deflater nDeflater = deflater; // new Deflater();
|
|
305 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
|
|
306 unzip(inflater, inputs, 0, out, INFLATE_BUFSIZE);
|
|
307 // dump32(inputs);
|
|
308 int len2 = zip(nDeflater, out, 0, bufs);
|
|
309 ByteBuffer blen = ByteBuffer.allocate(4);
|
|
310 blen.putInt(len2);
|
|
311 blen.flip();
|
|
312 bufs.addFirst(blen);
|
|
313
|
|
314 bufs.addFirst(header);
|
|
315 // if(dataLen<=64000)
|
|
316 multicastqueue.put(bufs);
|
|
317 // is.reset();
|
|
318
|
|
319 /*
|
|
320 * System.out.println("ZRLE = "+dataLen);
|
|
321 * System.out.println("ZRLEE = "+(len2+20)); float mag =
|
|
322 * (float)dataLen / (float)(len2 + 20);
|
|
323 * System.out.println("ZRLE / ZRLEE = "+ mag); if(mag > maxMag)
|
|
324 * maxMag = mag; System.out.println("maxMag = "+maxMag);
|
|
325 */
|
|
326 return;
|
|
327 }
|
|
328 bufs.add(header);
|
|
329 if (dataLen > 16) {
|
|
330 ByteBuffer b = ByteBuffer.allocate(dataLen - 16);
|
|
331 readFully(b.array(), 0, dataLen - 16);
|
|
332 b.limit(dataLen - 16);
|
|
333 bufs.add(b);
|
|
334 }
|
|
335 multicastqueue.put(bufs);
|
|
336 // is.reset();
|
|
337 return;
|
|
338 }
|
|
339 is.reset();
|
|
340
|
|
341 // It may be compressed. We can inflate here to avoid repeating clients
|
|
342 // decompressing here,
|
|
343 // but it may generate too many large data. It is better to do it in
|
|
344 // each client.
|
|
345 // But we have do inflation for all input data, so we have to do it
|
|
346 // here.
|
|
347 }
|
|
348
|
|
349 public void newClient(AcceptThread acceptThread, final Socket newCli,
|
|
350 final OutputStream os, final InputStream is) throws IOException {
|
|
351 // createBimgFlag = true;
|
|
352 // rfb.addSockTmp(newCli);
|
|
353 // addSock(newCli);
|
|
354 final int myId = clients;
|
|
355 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue
|
|
356 .newClient();
|
|
357 final AtomicInteger writerRunning = new AtomicInteger();
|
|
358 writerRunning.set(1);
|
|
359 /**
|
|
360 * Timeout thread. If a client is suspended, it has top of queue
|
|
361 * indefinitely, which caused memory overflow. After the timeout, we
|
|
362 * poll the queue and discard it. Start long wait if writer is running.
|
|
363 */
|
|
364 final Runnable timer = new Runnable() {
|
|
365 public void run() {
|
|
366 int count = 0;
|
|
367 for (;;) {
|
|
368 long timeout = 50000 / 8;
|
|
369 try {
|
|
370 synchronized (this) {
|
|
371 int state, flag;
|
|
372 writerRunning.set(0);
|
|
373 wait(timeout);
|
|
374 flag = 0;
|
|
375 while ((state = writerRunning.get()) == 0) {
|
|
376 c.poll(); // discard, should be timeout
|
|
377 count++;
|
|
378 if (flag == 0) {
|
|
379 System.out.println("Discarding " + myId
|
|
380 + " count=" + count);
|
|
381 flag = 1;
|
|
382 }
|
|
383 wait(10); // if this is too short, writer cannot
|
|
384 // take the poll, if this is too
|
|
385 // long, memory will overflow...
|
|
386 }
|
|
387 if (flag == 1)
|
|
388 System.out.println("Resuming " + myId
|
|
389 + " count=" + count);
|
|
390 if (state != 1) {
|
|
391 System.out.println("Client died " + myId);
|
|
392 break;
|
|
393 }
|
|
394 }
|
|
395 } catch (InterruptedException e) {
|
|
396 }
|
|
397 }
|
|
398 }
|
|
399 };
|
|
400 new Thread(timer).start();
|
|
401 /**
|
|
402 * discard all incoming from clients
|
|
403 */
|
|
404 final Runnable reader = new Runnable() {
|
|
405 public void run() {
|
|
406 byte b[] = new byte[4096];
|
|
407 for (;;) {
|
|
408 try {
|
|
409 int c = is.read(b);
|
|
410 if (c <= 0)
|
|
411 throw new IOException();
|
|
412 // System.out.println("client read "+c);
|
|
413 } catch (IOException e) {
|
|
414 try {
|
|
415 writerRunning.set(2);
|
|
416 os.close();
|
|
417 is.close();
|
|
418 } catch (IOException e1) {
|
|
419 }
|
|
420 return;
|
|
421 }
|
|
422 }
|
|
423 }
|
|
424 };
|
|
425 /**
|
|
426 * send packets to a client
|
|
427 */
|
|
428 Runnable sender = new Runnable() {
|
|
429 public void run() {
|
|
430 writerRunning.set(1);
|
|
431 try {
|
|
432 requestThreadNotify();
|
|
433 // rThread.checkDelay();
|
|
434
|
|
435 /**
|
|
436 * initial connection of RFB protocol
|
|
437 */
|
|
438 sendRfbVersion(os);
|
|
439 // readVersionMsg(is);
|
|
440 int rfbMinor = readVersionMsg(is, os);
|
|
441 sendSecurityType(os);
|
|
442 readSecType(is);
|
|
443 sendSecResult(os);
|
|
444 readClientInit(is);
|
|
445 sendInitData(os);
|
|
446 new Thread(reader).start(); // discard incoming packet here
|
|
447 // after.
|
|
448 // writeFramebufferUpdateRequest(0,0, framebufferWidth,
|
|
449 // framebufferHeight, false );
|
|
450 int i = 0;
|
|
451 for (;;) {
|
|
452 LinkedList<ByteBuffer> bufs = c.poll();
|
|
453 int inputIndex = 0;
|
|
454 ByteBuffer header = bufs.get(inputIndex);
|
|
455 if (header == null)
|
|
456 continue;
|
|
457 else if (header.get(0) == RfbProto.CheckDelay) {
|
|
458 writeToClient(os, bufs, inputIndex);
|
|
459 continue;
|
|
460 } else if (header.get(0) == RfbProto.FramebufferUpdate) {
|
|
461 // System.out.println("client "+ myId);
|
|
462 }
|
|
463 /*
|
|
464 if(i%20==0){
|
|
465 sendDataCheckDelay();
|
|
466 }
|
|
467 i++;
|
|
468 */
|
|
469 writeToClient(os, bufs, inputIndex);
|
|
470 writerRunning.set(1); // yes my client is awaking.
|
|
471 }
|
|
472 } catch (IOException e) {
|
|
473 try {
|
|
474 writerRunning.set(2);
|
|
475 os.close();
|
|
476 } catch (IOException e1) {
|
|
477 }
|
|
478 /* if socket closed cliList.remove(newCli); */
|
|
479 }
|
|
480 }
|
|
481
|
|
482 public void writeToClient(final OutputStream os,
|
|
483 LinkedList<ByteBuffer> bufs, int inputIndex)
|
|
484 throws IOException {
|
|
485 while (inputIndex < bufs.size()) {
|
|
486 ByteBuffer b = bufs.get(inputIndex++);
|
|
487 os.write(b.array(), b.position(), b.limit());
|
|
488 }
|
|
489 os.flush();
|
|
490 }
|
|
491 };
|
|
492 clients++;
|
|
493 new Thread(sender).start();
|
|
494
|
|
495 }
|
|
496
|
|
497 public void dump32(LinkedList<ByteBuffer> bufs) {
|
|
498 int len = 0;
|
|
499 for (ByteBuffer b : bufs)
|
|
500 len += b.remaining();
|
|
501 ByteBuffer top = bufs.getFirst();
|
|
502 ByteBuffer end = bufs.getLast();
|
|
503 System.err.println("length: " + len);
|
|
504 System.err.print("head 0: ");
|
|
505 for (int i = 0; i < 16 && i < top.remaining(); i++) {
|
|
506 System.err.print(" " + top.get(i));
|
|
507 }
|
|
508 System.err.print("tail 0: ");
|
|
509 for (int i = 0; i < 16 && i < end.remaining(); i++) {
|
|
510 System.err.print(" " + end.get(i));
|
|
511 }
|
|
512 System.err.println();
|
|
513 }
|
|
514
|
|
515 @Test
|
|
516 public void test1() {
|
|
517 try {
|
|
518 LinkedList<ByteBuffer> in = new LinkedList<ByteBuffer>();
|
|
519 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
|
|
520 LinkedList<ByteBuffer> out2 = new LinkedList<ByteBuffer>();
|
|
521 // if (false) {
|
|
522 // for(int i=0;i<10;i++) {
|
|
523 // in.add(ByteBuffer.wrap("test1".getBytes()));
|
|
524 // in.add(ByteBuffer.wrap("test2".getBytes()));
|
|
525 // in.add(ByteBuffer.wrap("test3".getBytes()));
|
|
526 // in.add(ByteBuffer.wrap("test44".getBytes()));
|
|
527 // }
|
|
528 // } else
|
|
529 {
|
|
530 String t = "";
|
|
531 for (int i = 0; i < 10; i++) {
|
|
532 t += "test1";
|
|
533 t += "test2";
|
|
534 t += "test3";
|
|
535 t += "test44";
|
|
536 }
|
|
537 in.add(ByteBuffer.wrap(t.getBytes()));
|
|
538 }
|
|
539
|
|
540 LinkedList<ByteBuffer> in1 = clone(in);
|
|
541
|
|
542 Deflater deflater = new Deflater();
|
|
543 zip(deflater, in, 0, out);
|
|
544 // LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend
|
|
545 // on deflator's state
|
|
546 unzip(inflater, out, 0, out2, INFLATE_BUFSIZE);
|
|
547 // inflater.reset();
|
|
548 equalByteBuffers(in1, out2);
|
|
549 LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>();
|
|
550 deflater = new Deflater();
|
|
551 zip(deflater, out2, 0, out4);
|
|
552 LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>();
|
|
553 unzip(inflater, out4, 0, out5, INFLATE_BUFSIZE);
|
|
554 int len = equalByteBuffers(in1, out5);
|
|
555
|
|
556 System.out.println("Test Ok. " + len);
|
|
557 } catch (Exception e) {
|
|
558 assertEquals(0, 1);
|
|
559 }
|
|
560 }
|
|
561
|
|
562 private LinkedList<ByteBuffer> clone(LinkedList<ByteBuffer> in) {
|
|
563 LinkedList<ByteBuffer> copy = new LinkedList<ByteBuffer>();
|
|
564 for (ByteBuffer b : in) {
|
|
565 ByteBuffer c = b.duplicate();
|
|
566 copy.add(c);
|
|
567 }
|
|
568 return copy;
|
|
569 }
|
|
570
|
|
571 public int equalByteBuffers(LinkedList<ByteBuffer> in,
|
|
572 LinkedList<ByteBuffer> out2) {
|
|
573 int len = 0;
|
|
574 Iterable<Byte> i = byteBufferIterator(in);
|
|
575 Iterator<Byte> o = byteBufferIterator(out2).iterator();
|
|
576
|
|
577 for (int b : i) {
|
|
578 len++;
|
|
579 if (o.hasNext()) {
|
|
580 int c = o.next();
|
|
581 assertEquals(b, c);
|
|
582 } else
|
|
583 assertEquals(0, 1);
|
|
584 }
|
|
585 if (o.hasNext())
|
|
586 assertEquals(0, 1);
|
|
587 // System.out.println();
|
|
588 return len;
|
|
589 }
|
|
590
|
|
591 private Iterable<Byte> byteBufferIterator(final LinkedList<ByteBuffer> in) {
|
|
592 return new Iterable<Byte>() {
|
|
593 public Iterator<Byte> iterator() {
|
|
594 return new Iterator<Byte>() {
|
|
595 int bytes = 0;
|
|
596 int buffers = 0;
|
|
597
|
|
598 public boolean hasNext() {
|
|
599 for (;;) {
|
|
600 if (buffers >= in.size())
|
|
601 return false;
|
|
602 ByteBuffer b = in.get(buffers);
|
|
603 if (!(bytes < b.remaining())) {
|
|
604 buffers++;
|
|
605 bytes = 0;
|
|
606 } else
|
|
607 return true;
|
|
608 }
|
|
609 }
|
|
610
|
|
611 public Byte next() {
|
|
612 ByteBuffer bf = in.get(buffers);
|
|
613 byte b = bf.get(bytes++);
|
|
614 if (bf.remaining() <= bytes) {
|
|
615 buffers++;
|
|
616 bytes = 0;
|
|
617 }
|
|
618 // System.out.print(b);
|
|
619 return b;
|
|
620 }
|
|
621
|
|
622 public void remove() {
|
|
623 }
|
|
624 };
|
|
625 }
|
|
626 };
|
|
627 }
|
|
628
|
|
629 }
|