# HG changeset patch # User Shinji KONO # Date 1312372515 -32400 # Node ID 3db7ac2b10f7dc116cf28e59ec2addb163c3dbf2 # Parent 145506601e0dce523fdbdaa6cac15dc4bb71de16 JUnit test passed, but VNC stopped. diff -r 145506601e0d -r 3db7ac2b10f7 src/myVncProxy/MyRfbProto.java --- a/src/myVncProxy/MyRfbProto.java Wed Aug 03 15:02:37 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Wed Aug 03 20:55:15 2011 +0900 @@ -536,23 +536,30 @@ */ public int zip(Deflater deflater,LinkedList inputs, int inputIndex, LinkedList outputs) throws IOException { int len1=0,len = 0; - deflater.reset(); - while(inputIndex < inputs.size()) { + ByteBuffer c1= ByteBuffer.allocate(INFLATE_BUFSIZE); + while(inputIndex < inputs.size() ) { ByteBuffer b1 = inputs.get(inputIndex++); - deflater.setInput(b1.array(),b1.position(),b1.limit()); + deflater.setInput(b1.array(),b1.position(),b1.remaining()); if (inputIndex==inputs.size()) { deflater.finish(); } do { - ByteBuffer c1 = ByteBuffer.allocate(INFLATE_BUFSIZE); - len1 = deflater.deflate(c1.array(),c1.position(),c1.capacity()); - c1.limit(len1); - if (len1>0) { + len1 = deflater.deflate(c1.array(),c1.position(),c1.remaining()); + if (len1<=0) break; // get next buffer + len += len1; + c1.position(c1.position()+len1); + if (c1.remaining()==0) { + c1.flip(); outputs.addLast(c1); - len += len1; + c1 = ByteBuffer.allocate(INFLATE_BUFSIZE); } - } while (len1==INFLATE_BUFSIZE); - } + } while (!deflater.finished()); + } + if (c1.position()!=0) { + c1.flip(); + outputs.addLast(c1); + } + deflater.reset(); return len; } @@ -566,24 +573,30 @@ *@return number of total bytes * @throws IOException */ - public int unzip(Inflater inflater, LinkedList inputs, LinkedList outputs) + public int unzip(Inflater inflater, LinkedList inputs, int inputIndex, LinkedList outputs) throws DataFormatException { int len=0,len0; - inflater.reset(); - int inputIndex = 0; - do { + ByteBuffer buf = ByteBuffer.allocate(INFLATE_BUFSIZE); + // inflater.reset(); // if we uncomment this, test1() will be passed. But it won't work with real connection. + while (inputIndex < inputs.size()) { ByteBuffer input = inputs.get(inputIndex++); inflater.setInput(input.array(),0,input.limit()); do { - ByteBuffer buf = ByteBuffer.allocate(INFLATE_BUFSIZE); - len0 = inflater.inflate(buf.array(),0,buf.capacity()); - buf.limit(len0); + len0 = inflater.inflate(buf.array(),buf.position(),buf.remaining()); + buf.position(buf.position()+len0); len += len0; - if (len0>0) { + if (buf.remaining()==0) { + buf.flip(); outputs.addLast(buf); + buf = ByteBuffer.allocate(INFLATE_BUFSIZE); } - } while (len0>0); - } while (inputIndex < inputs.size()) ; + } while (!inflater.finished()); + } + if (buf.position()!=0) { + buf.flip(); + outputs.addLast(buf); + } + inflater.reset(); return len; } @@ -601,7 +614,7 @@ readFully(inputData.array(),0,inputData.capacity()); inputData.limit(dataLen-20); LinkedListinputs = new LinkedList(); inputs.add(inputData); - unzip(inflater, inputs, bufs); + unzip(inflater, inputs, 0, bufs); bufs.addFirst(header); multicastqueue.put(bufs); is.reset(); @@ -631,7 +644,7 @@ Runnable sender = new Runnable() { public void run() { - Deflater deflater = new Deflater(); + Deflater deflater = new Deflater(9,true); try { /** * initial connection of RFB protocol @@ -727,12 +740,12 @@ Deflater deflater = new Deflater(); zip(deflater,in,0,out); // LinkedList out3 = clone(out); zipped result is depend on deflator's state - unzip(inflater, out, out2); + unzip(inflater, out, 0,out2); equalByteBuffers(in1, out2); LinkedList out4 = new LinkedList(); zip(deflater,out2,0,out4); LinkedList out5 = new LinkedList(); - unzip(inflater,out4,out5); + unzip(inflater,out4,0, out5); equalByteBuffers(in1,out5); System.out.println("Test Ok.");