hadoop-common-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "kishore gopalakrishna (JIRA)" <j...@apache.org>
Subject [jira] Created: (HADOOP-3449) problem with bytewritable tostring
Date Tue, 27 May 2008 19:02:03 GMT
problem with bytewritable tostring
----------------------------------

                 Key: HADOOP-3449
                 URL: https://issues.apache.org/jira/browse/HADOOP-3449
             Project: Hadoop Core
          Issue Type: Bug
            Reporter: kishore gopalakrishna


The BytesWritable toString method is not bidirectional. What it means is we cannot get back
the bytes from the toString form of bytesWritable. Here is the snippet

public String toString() { 
    StringBuffer sb = new StringBuffer(3*size);
    for (int idx = 0; idx < size; idx++) {
      // if not the first, put a blank separator in
      if (idx != 0) {
        sb.append(' ');
      }
     *String num = Integer.toHexString((int) bytes[idx]);*
      // if it is only one digit, add a leading 0.
      if (num.length() < 2) {
        sb.append('0');
      }
      sb.append(num);
    }
    return sb.toString();
  }


This is not the correct way to convert byte to string. This works well for positive numbers
but fails for negative numbers

String num = Integer.toHexString((int) bytes[idx] && 0XFF);
http://forum.java.sun.com/thread.jspa?threadID=252591&messageID=2272668




-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message