1 Reply Latest reply on Feb 3, 2012 8:01 PM by jtahlborn

    Compression/ uncompression issue over sokects

      Only one thread running at the time of test;
      JAVA: Java(TM) SE Runtime Environment (build 1.7.0_02-b13)

      i have a problem with the following scenario.
      A client inside a loop reads data from a file, does some processing of incoming data, compresses it and sends it
      to the server over a socket. The server at the first instance of the read throws: *"java.util.zip.ZipException: invalid distance too far back"*

      The Client side compressiion code snippet is:

      Deflater defltr = new Deflater(Deflater.DEFAULT_COMPRESSION, true);
      DeflaterOutputStream deflOpStrm = new DeflaterOutputStream(new BufferedOutputStream(
           thrdHlpr.getClntSkt().getOutputStream()), defltr, BUF_SIZE); //BUF_SIZE= 10240 .....1024/512
      DataOutputStream opStrm = new DataOutputStream(deflOpStrm);

      while(!isInterrupted()) {

      while(0 != chBufLen && -1 != chBufLen){
      char[] chBuff = new char[BUF_SIZE]; //BUF_SIZE= 10240 .....1024/512
      chBufLen = inFile.read(chBuff, 0, BUF_SIZE);
      if( 0 < chBufLen){
      offset += chBufLen;
      rawBuf.append(chBuff, 0, chBufLen);
      //Do my things with the data and transfer data to outBuf


      //I have tried with and without calling finish & reset
      chBuff = null;
      }//end while(0 != chBufLen &&.....
      }//end while(!isInterrupted

      //Catch block.....

      Server side UncompressCode is:

      Inflater infltr = new Inflater(true);
      InflaterInputStream infInputStrm = new InflaterInputStream(clntSokt.getInputStream(), infltr, BUF_SIZE/2);
      DataInputStream dInptStrm = new DataInputStream(infInputStrm);

      while(true) {
      String result = dInptStrm.readUTF(); //Exception is thrown here

      //Have tried with and without reset.
      }//end while(true....
      //catch block

      The Satk is:
      java.util.zip.ZipException: invalid distance too far back
           at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:164)
           at java.io.DataInputStream.readFully(DataInputStream.java:195)
           at java.io.DataInputStream.readUTF(DataInputStream.java:609)
           at java.io.DataInputStream.readUTF(DataInputStream.java:564)

      Since i have tried this many different ways..... i most appreciate time and effort of those who have a difinite answer to take a shot at it.

      Thanks very much for your time and answer.

      Edited by: user10049207 on Feb 3, 2012 8:38 AM

      Edited by: user10049207 on Feb 3, 2012 8:40 AM

      Edited by: user10049207 on Feb 3, 2012 8:42 AM