Mercurial > hg > Members > nobuyasu > tightVNCProxy
comparison src/myVncProxy/MyRfbProto.java @ 99:0c5762c3a8dd
Test and VNC not working... Memory Overflow...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Aug 2011 21:35:06 +0900 |
parents | 3db7ac2b10f7 |
children | ae4df9b07805 |
comparison
equal
deleted
inserted
replaced
98:3db7ac2b10f7 | 99:0c5762c3a8dd |
---|---|
62 | 62 |
63 ExecutorService executor; | 63 ExecutorService executor; |
64 | 64 |
65 byte[] pngBytes; | 65 byte[] pngBytes; |
66 | 66 |
67 // private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MostRecentMultiCast<LinkedList<ByteBuffer>>(10); | 67 private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MostRecentMultiCast<LinkedList<ByteBuffer>>(10); |
68 private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); | 68 // private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); |
69 private int clients = 0; | 69 private int clients = 0; |
70 private Inflater inflater = new Inflater(); | 70 private Inflater inflater = new Inflater(); |
71 | 71 |
72 public | 72 public |
73 MyRfbProto() throws IOException { | 73 MyRfbProto() throws IOException { |
581 while (inputIndex < inputs.size()) { | 581 while (inputIndex < inputs.size()) { |
582 ByteBuffer input = inputs.get(inputIndex++); | 582 ByteBuffer input = inputs.get(inputIndex++); |
583 inflater.setInput(input.array(),0,input.limit()); | 583 inflater.setInput(input.array(),0,input.limit()); |
584 do { | 584 do { |
585 len0 = inflater.inflate(buf.array(),buf.position(),buf.remaining()); | 585 len0 = inflater.inflate(buf.array(),buf.position(),buf.remaining()); |
586 if (len0<=0) break; | |
586 buf.position(buf.position()+len0); | 587 buf.position(buf.position()+len0); |
587 len += len0; | 588 len += len0; |
588 if (buf.remaining()==0) { | 589 if (buf.remaining()==0) { |
589 buf.flip(); | 590 buf.flip(); |
590 outputs.addLast(buf); | 591 outputs.addLast(buf); |
594 } | 595 } |
595 if (buf.position()!=0) { | 596 if (buf.position()!=0) { |
596 buf.flip(); | 597 buf.flip(); |
597 outputs.addLast(buf); | 598 outputs.addLast(buf); |
598 } | 599 } |
599 inflater.reset(); | 600 // inflater.reset(); // this make JUnit happy, but VNC won't happy with this |
600 return len; | 601 return len; |
601 } | 602 } |
602 | 603 |
603 void readSendData(int dataLen) throws IOException, DataFormatException { | 604 void readSendData(int dataLen) throws IOException, DataFormatException { |
604 LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>(); | 605 LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>(); |
739 | 740 |
740 Deflater deflater = new Deflater(); | 741 Deflater deflater = new Deflater(); |
741 zip(deflater,in,0,out); | 742 zip(deflater,in,0,out); |
742 // LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend on deflator's state | 743 // LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend on deflator's state |
743 unzip(inflater, out, 0,out2); | 744 unzip(inflater, out, 0,out2); |
745 inflater.reset(); | |
744 equalByteBuffers(in1, out2); | 746 equalByteBuffers(in1, out2); |
745 LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>(); | 747 LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>(); |
746 zip(deflater,out2,0,out4); | 748 zip(deflater,out2,0,out4); |
747 LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>(); | 749 LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>(); |
748 unzip(inflater,out4,0, out5); | 750 unzip(inflater,out4,0, out5); |
749 equalByteBuffers(in1,out5); | 751 int len = equalByteBuffers(in1,out5); |
750 | 752 |
751 System.out.println("Test Ok."); | 753 System.out.println("Test Ok. "+len); |
752 } catch (Exception e) { | 754 } catch (Exception e) { |
753 assertEquals(0,1); | 755 assertEquals(0,1); |
754 } | 756 } |
755 } | 757 } |
756 | 758 |
763 return copy; | 765 return copy; |
764 } | 766 } |
765 | 767 |
766 | 768 |
767 | 769 |
768 public void equalByteBuffers(LinkedList<ByteBuffer> in, | 770 public int equalByteBuffers(LinkedList<ByteBuffer> in, |
769 LinkedList<ByteBuffer> out2) { | 771 LinkedList<ByteBuffer> out2) { |
772 int len = 0; | |
770 Iterable<Byte> i = byteBufferIterator(in); | 773 Iterable<Byte> i = byteBufferIterator(in); |
771 Iterator<Byte> o = byteBufferIterator(out2).iterator(); | 774 Iterator<Byte> o = byteBufferIterator(out2).iterator(); |
772 | 775 |
773 for(int b: i) { | 776 for(int b: i) { |
777 len ++; | |
774 if (o.hasNext()) { | 778 if (o.hasNext()) { |
775 int c = o.next(); | 779 int c = o.next(); |
776 assertEquals(b,c); | 780 assertEquals(b,c); |
777 } else | 781 } else |
778 assertEquals(0,1); | 782 assertEquals(0,1); |
779 } | 783 } |
780 if (o.hasNext()) assertEquals(0,1); | 784 if (o.hasNext()) assertEquals(0,1); |
781 // System.out.println(); | 785 // System.out.println(); |
786 return len; | |
782 } | 787 } |
783 | 788 |
784 private Iterable<Byte> byteBufferIterator(final LinkedList<ByteBuffer> in) { | 789 private Iterable<Byte> byteBufferIterator(final LinkedList<ByteBuffer> in) { |
785 return new Iterable<Byte>() { | 790 return new Iterable<Byte>() { |
786 public Iterator<Byte> iterator() { | 791 public Iterator<Byte> iterator() { |