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

(cs) CharsetDecoder.decode() returns an charArray with empty chars on the end

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P5
    • Resolution: Not an Issue
    • Affects Version/s: 1.4.1, 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description



      Name: jl125535 Date: 07/22/2003


      A DESCRIPTION OF THE REQUEST :
      When you use java.nio.charset.CharsetDecoder.decode() it creates a charArray that is an approximate length based on the averageCharsPerByte(). This is fine, but it returns this full Array even if there are empty '\u0000' chars on the end of the array. It'd be much nicer if it stripped the array down to the correct length before returning it.


      JUSTIFICATION :
      It saves a lot of wasted development time for end users. Currently we have to put the following wherever we want to write out an encoded byte array:

      ByteBuffer data = ByteBuffer.wrap(readDataPacket(input));
                          CharBuffer decodedChars = decoder.decode(data);
                          char[] charArray = decodedChars.array();
                          int length = charArray.length;
                          for(int i=length-1;i>0;i--){
                              if ((charArray[i] != '\u0000')) {
                                  length = i+1;
                                  break;
                              }
                          }
                          writer.write(charArray,0,length);

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The returned char[] should be the correct length
      The char[] can contain '\u0000' chars at the end, which weren't part of the original byte[]
      (Incident Review ID: 182246)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              martin Martin Buchholz
              Reporter:
              jleesunw Jon Lee (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: