Mercurial > hg > Members > nobuyasu > tightVNCProxy
changeset 93:40c22e507655
unzip/zip Test passed.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Aug 2011 12:34:50 +0900 |
parents | aa7df396e04d |
children | b551b7af0a8a |
files | src/myVncProxy/MyRfbProto.java |
diffstat | 1 files changed, 43 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java Wed Aug 03 11:40:18 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Wed Aug 03 12:34:50 2011 +0900 @@ -16,6 +16,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.nio.ByteBuffer; +import java.util.Iterator; import java.util.LinkedList; import javax.imageio.ImageIO; @@ -32,7 +33,7 @@ import java.io.OutputStream; public -class MyRfbProto extends RfbProto { +class MyRfbProto<ByteBuffersIterator> extends RfbProto { final static String versionMsg_3_998 = "RFB 003.998\n"; /** * CheckMillis is one of new msgType for RFB 3.998. @@ -566,6 +567,7 @@ public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, LinkedList<ByteBuffer> outputs) throws DataFormatException { int len=0,len0; + inflater.reset(); do { ByteBuffer input = inputs.poll(); inflater.setInput(input.array(),0,input.limit()); @@ -716,29 +718,50 @@ return copy; } + + public void equalByteBuffers(LinkedList<ByteBuffer> in, LinkedList<ByteBuffer> out2) { - int k = 0; - ByteBuffer c = out2.get(k++); - c.mark(); - for(ByteBuffer b:in) { - b.mark(); - while(b.remaining()>0) { - if (c.remaining()==0) { - c.reset(); - if (k>=out2.size()) { - assertEquals(0,1); - return; + Iterable<Byte> i = byteBufferIterator(in); + Iterator<Byte> o = byteBufferIterator(out2).iterator(); + + for(int b: i) { + if (o.hasNext()) { + int c = o.next(); + assertEquals(b,c); + } else + assertEquals(0,1); + } + if (o.hasNext()) assertEquals(0,1); + // System.out.println(); + } + + private Iterable<Byte> byteBufferIterator(final LinkedList<ByteBuffer> in) { + return new Iterable<Byte>() { + public Iterator<Byte> iterator() { + return new Iterator<Byte>() { + int bytes = 0; + int buffers = 0; + public boolean hasNext() { + if (buffers>=in.size()) return false; + ByteBuffer b = in.getFirst(); + return bytes<b.remaining(); } - c = out2.get(k++); - c.mark(); - } - byte i = b.get(); - byte j = c.get(); - assertEquals(i,j); + public Byte next() { + ByteBuffer bf =in.get(buffers); + byte b = bf.get(bytes++); + if (bf.remaining()<=bytes) { + buffers++; + bytes = 0; + } + // System.out.print(b); + return b; + } + public void remove() { + } + }; } - b.reset(); - } + }; } }