Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6341887

Inflater.setInput(), Inflater.inflate() can't handle ByteBuffer

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 11
    • Fix Version/s: 11
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b11
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      A DESCRIPTION OF THE REQUEST :
      The Inflater class' methods - setInput() and inflate() - take byte arrays, but not ByteBuffers.
      They need to take ByteBuffers.

      JUSTIFICATION :
      The new java.nio.* API is nice and uses ByteBuffers, which I've been told are more efficent, and are definitely easier to work with than getting integers from byte arrays. Inflater and Deflater should use ByteBuffers to avoid having to convert back and forth when compressing data to send over the internet.
      Also, I think this would be an easy fix. Wrapping doesn't cut it.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Inflater class taking ByteBuffers

      int len = sockechannel.read(bytebuffer);
      inflater.setInput(bytebuffer, 0 , len);
      inflater.inflate(bytebuffer); //if this has to use a seperate ByteBuffer that's fine too

      ACTUAL -
      Lots of conversions

      int len = socketchannel.read(bytebuffer);
      byte[] temp = byte[len];
      bytebuffer.get(temp);
      inflater.setInput(temp,0,len);
      byte [] temp2 = byte[len*10];
      len = inflater.inflate(temp2);
      bytebuffer.put(temp2, 0 , len);


      ---------- BEGIN SOURCE ----------
       /*
           it really doesn't matter what i put since it would take pages to actually
           connect to the real server. If you really need this to understand my
           issue, email me and ill send you whatever you need.
       */

      import java.util.zip.*;
      import java.nio.*;
      import java.nio.channels.SocketChannel;
      import java.io.IOException;


      public class SocketGold extends Thread
      {
      ByteBuffer lenBytes;
      SocketChannel socket;
      Inflater compresseur;
      byte[] gonflé;

      public SocketGold(SocketChannel sc)
      {
      socket = sc;
      lenBytes = ByteBuffer.allocateDirect(2);
      compresseur = new Inflater();
      gonflé = new byte[1536];
      }


      //disregard this, it just makes the important code easier for the eyes
      private int read(ByteBuffer buf)
      {
      try {
      return socket.read(buf);
      }
      catch(IOException e) {
      System.exit(1);
      }

      return -1;
      }


      public void run()
      {
      short len;
      int résultat=0;
      byte[] temp;
      ByteBuffer tempBuffer;

      while (true) {
      read(lenBytes);
      len = lenBytes.getShort();

      tempBuffer = ByteBuffer.allocateDirect(len);

      //example of good behavior
      read(tempBuffer);

      //i disagree with this method
      temp = new byte[len];
      tempBuffer.get(temp);

      compresseur.setInput(temp,0,len);

      try {
      résultat = compresseur.inflate(gonflé);
      } catch(DataFormatException e) {
      System.exit(1);
      }

      //this is also annoying
      tempBuffer = ByteBuffer.allocateDirect(résultat);
      tempBuffer.put(gonflé,0,résultat);
      }

      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I'm using byte arrays.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sherman Xueming Shen
                Reporter:
                jssunw Jitender S (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: