1 Reply Latest reply: Oct 16, 2007 4:34 AM by 807605 RSS

    decompressing byte[]

    807605
      hi, sorry for taking your time. however i am encountering problem reguarding compress and uncompressing of byte[].

      below is the codes i used for compression
      ----------
      java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
      try
      {
      java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(baos);
      oos.writeObject(object);
      }
      catch (java.io.IOException ioe)
      {
      java.util.logging.Logger.global.log(java.util.logging.Level.SEVERE, ioe.getMessage());
      }

      byte[] bytearr = baos.toByteArray();
      Deflater deflater = new Deflater(Deflater.BEST_COMPRESSION);
      deflater.setInput(bytearr);
      deflater.finish();

      deflater.deflate(bytearr);
      byte[] compressedByte = new byte[deflater.getTotalOut()];
      System.arraycopy(bytearr, 0, compressedByte, 0, size);

      return compressedByte;
        • 1. Re: decompressing byte[]
          807605
          this is the codes i use for uncompression.
          ----------
          Inflater inflater = new Inflater();

          inflater.setInput(compressedByte);
          inflater.finished();
          inflater.inflate(cardByte);
          int size = inflater.getTotalOut();
          byte[] decompressedByte= new byte[size];

          System.arraycopy(compressedByte, 0, decompressedByte, 0, size);
          ByteArrayInputStream bains = new ByteArrayInputStream(cardByteUC)
          Object object = new java.io.ObjectInputStream(bains).readObject();
          ----------
          however i can't get any data out. keep geting java.io.StreamCorruptedException. another problem i see is that even after decompress the data my size of my byte[] is still the same which shouldn't be the case.

          can someone kindly guide me?