Mercurial > hg > Members > nobuyasu > tightVNCProxy
comparison src/myVncProxy/MyRfbProto.java @ 91:4116c19cd76e
unzip/zip test passed.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Aug 2011 10:52:19 +0900 |
parents | 462bca4c8cec |
children | aa7df396e04d |
comparison
equal
deleted
inserted
replaced
90:462bca4c8cec | 91:4116c19cd76e |
---|---|
523 | 523 |
524 /** | 524 /** |
525 * gzip byte arrays | 525 * gzip byte arrays |
526 * @param deflater | 526 * @param deflater |
527 * @param inputs | 527 * @param inputs |
528 * byte len[4] total byte length | |
529 * byte data[] | 528 * byte data[] |
530 * @param outputs | 529 * @param outputs |
531 * byte len[4] total byte length | |
532 * byte data[] | 530 * byte data[] |
533 * @return byte length in last byte array | 531 * @return byte length in last byte array |
534 * @throws IOException | 532 * @throws IOException |
535 */ | 533 */ |
536 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 { |
548 c1.limit(len1); | 546 c1.limit(len1); |
549 if (len1>0) { | 547 if (len1>0) { |
550 outputs.addLast(c1); | 548 outputs.addLast(c1); |
551 len += len1; | 549 len += len1; |
552 } | 550 } |
553 } while (len1 > 0); | 551 } while (len1==INFLATE_BUFSIZE); |
554 } while(inputs.size()>0); | 552 } while(inputs.size()>0); |
555 ByteBuffer blen = ByteBuffer.wrap(castIntByte(len)); | |
556 outputs.addFirst(blen); | |
557 return len; | 553 return len; |
558 } | 554 } |
559 | 555 |
560 /** | 556 /** |
561 * gunzip byte arrays | 557 * gunzip byte arrays |
562 * @param inflater | 558 * @param inflater |
563 * @param inputs | 559 * @param inputs |
564 * byte len[4] total byte length | |
565 * byte data[] | 560 * byte data[] |
566 * @param outputs | 561 * @param outputs |
567 * byte len[4] total byte length | |
568 * byte data[] | 562 * byte data[] |
563 *@return number of total bytes | |
569 * @throws IOException | 564 * @throws IOException |
570 */ | 565 */ |
571 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, LinkedList<ByteBuffer> outputs) | 566 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, LinkedList<ByteBuffer> outputs) |
572 throws DataFormatException { | 567 throws DataFormatException { |
573 int len=0,len0; | 568 int len=0,len0; |
577 do { | 572 do { |
578 ByteBuffer buf = ByteBuffer.allocate(INFLATE_BUFSIZE); | 573 ByteBuffer buf = ByteBuffer.allocate(INFLATE_BUFSIZE); |
579 len0 = inflater.inflate(buf.array(),0,buf.capacity()); | 574 len0 = inflater.inflate(buf.array(),0,buf.capacity()); |
580 buf.limit(len0); | 575 buf.limit(len0); |
581 len += len0; | 576 len += len0; |
582 outputs.addLast(buf); | 577 if (len0>0) { |
583 } while (len0 ==INFLATE_BUFSIZE); | 578 outputs.addLast(buf); |
579 } | |
580 } while (len0>0); | |
584 } while (!inputs.isEmpty()); | 581 } while (!inputs.isEmpty()); |
585 return len; | 582 return len; |
586 } | 583 } |
587 | 584 |
588 void readSendData(int dataLen) throws IOException, DataFormatException { | 585 void readSendData(int dataLen) throws IOException, DataFormatException { |
693 } | 690 } |
694 | 691 |
695 Deflater deflater = new Deflater(); | 692 Deflater deflater = new Deflater(); |
696 zip(deflater, in,out); | 693 zip(deflater, in,out); |
697 unzip(inflater, out, out2); | 694 unzip(inflater, out, out2); |
698 for(ByteBuffer b:out) { | 695 for(ByteBuffer b:in) { |
699 ByteBuffer c = out2.poll(); | 696 ByteBuffer c = out2.poll(); |
700 assertEquals(b,c); | 697 assertEquals(b,c); |
701 } | 698 } |
702 System.out.println("Test Ok."); | 699 System.out.println("Test Ok."); |
703 } catch (Exception e) { | 700 } catch (Exception e) { |