Mercurial > hg > Members > nobuyasu > tightVNCProxy
comparison src/myVncProxy/MyRfbProto.java @ 92:aa7df396e04d
Test on going
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Aug 2011 11:40:18 +0900 |
parents | 4116c19cd76e |
children | 40c22e507655 |
comparison
equal
deleted
inserted
replaced
91:4116c19cd76e | 92:aa7df396e04d |
---|---|
532 * @throws IOException | 532 * @throws IOException |
533 */ | 533 */ |
534 public int zip(Deflater deflater,LinkedList<ByteBuffer> inputs, LinkedList<ByteBuffer> outputs) throws IOException { | 534 public int zip(Deflater deflater,LinkedList<ByteBuffer> inputs, LinkedList<ByteBuffer> outputs) throws IOException { |
535 int len1=0,len = 0; | 535 int len1=0,len = 0; |
536 deflater.reset(); | 536 deflater.reset(); |
537 do { | 537 while(inputs.size()>0) { |
538 ByteBuffer b1 = inputs.poll(); | 538 ByteBuffer b1 = inputs.poll(); |
539 deflater.setInput(b1.array(),b1.position(),b1.limit()); | 539 deflater.setInput(b1.array(),b1.position(),b1.limit()); |
540 if (inputs.size()==0) { | 540 if (inputs.size()==0) { |
541 deflater.finish(); | 541 deflater.finish(); |
542 } | 542 } |
547 if (len1>0) { | 547 if (len1>0) { |
548 outputs.addLast(c1); | 548 outputs.addLast(c1); |
549 len += len1; | 549 len += len1; |
550 } | 550 } |
551 } while (len1==INFLATE_BUFSIZE); | 551 } while (len1==INFLATE_BUFSIZE); |
552 } while(inputs.size()>0); | 552 } |
553 return len; | 553 return len; |
554 } | 554 } |
555 | 555 |
556 /** | 556 /** |
557 * gunzip byte arrays | 557 * gunzip byte arrays |
686 in.add(ByteBuffer.wrap("test1".getBytes())); | 686 in.add(ByteBuffer.wrap("test1".getBytes())); |
687 in.add(ByteBuffer.wrap("test2".getBytes())); | 687 in.add(ByteBuffer.wrap("test2".getBytes())); |
688 in.add(ByteBuffer.wrap("test3".getBytes())); | 688 in.add(ByteBuffer.wrap("test3".getBytes())); |
689 in.add(ByteBuffer.wrap("test4".getBytes())); | 689 in.add(ByteBuffer.wrap("test4".getBytes())); |
690 } | 690 } |
691 LinkedList<ByteBuffer> in1 = clone(in); | |
691 | 692 |
692 Deflater deflater = new Deflater(); | 693 Deflater deflater = new Deflater(); |
693 zip(deflater, in,out); | 694 zip(deflater, in,out); |
695 // LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend on deflator's state | |
694 unzip(inflater, out, out2); | 696 unzip(inflater, out, out2); |
695 for(ByteBuffer b:in) { | 697 equalByteBuffers(in1, out2); |
696 ByteBuffer c = out2.poll(); | 698 LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>(); |
697 assertEquals(b,c); | 699 zip(deflater,out2,out4); |
698 } | 700 LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>(); |
701 unzip(inflater,out4,out5); | |
702 equalByteBuffers(in1,out5); | |
703 | |
699 System.out.println("Test Ok."); | 704 System.out.println("Test Ok."); |
700 } catch (Exception e) { | 705 } catch (Exception e) { |
701 assertEquals(0,1); | 706 assertEquals(0,1); |
702 } | 707 } |
703 } | 708 } |
704 | 709 |
710 private LinkedList<ByteBuffer> clone(LinkedList<ByteBuffer> in) { | |
711 LinkedList<ByteBuffer> copy = new LinkedList<ByteBuffer>(); | |
712 for(ByteBuffer b: in) { | |
713 ByteBuffer c = b.duplicate(); | |
714 copy.add(c); | |
715 } | |
716 return copy; | |
717 } | |
718 | |
719 public void equalByteBuffers(LinkedList<ByteBuffer> in, | |
720 LinkedList<ByteBuffer> out2) { | |
721 int k = 0; | |
722 ByteBuffer c = out2.get(k++); | |
723 c.mark(); | |
724 for(ByteBuffer b:in) { | |
725 b.mark(); | |
726 while(b.remaining()>0) { | |
727 if (c.remaining()==0) { | |
728 c.reset(); | |
729 if (k>=out2.size()) { | |
730 assertEquals(0,1); | |
731 return; | |
732 } | |
733 c = out2.get(k++); | |
734 c.mark(); | |
735 } | |
736 byte i = b.get(); | |
737 byte j = c.get(); | |
738 assertEquals(i,j); | |
739 } | |
740 b.reset(); | |
741 } | |
742 } | |
743 | |
705 } | 744 } |
706 | 745 |
707 | 746 |