You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Novikov Andrey (Commented) (JIRA)" <ji...@apache.org> on 2012/02/15 02:19:59 UTC
[jira] [Commented] (THRIFT-1156) Bug with Base 64 coding in
TBase64Utils
[ https://issues.apache.org/jira/browse/THRIFT-1156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13208176#comment-13208176 ]
Novikov Andrey commented on THRIFT-1156:
----------------------------------------
Can you use this http://migbase64.sourceforge.net
> Bug with Base 64 coding in TBase64Utils
> ---------------------------------------
>
> Key: THRIFT-1156
> URL: https://issues.apache.org/jira/browse/THRIFT-1156
> Project: Thrift
> Issue Type: Bug
> Components: Java - Library
> Affects Versions: 0.6
> Environment: Java SE, Android
> Reporter: Głowka Rafał
> Original Estimate: 1h
> Remaining Estimate: 1h
>
> There are some problems with coding byte[] when values are less that 0.
> The example code :
> public static void main(String[] args)
> {
> byte[] data = new byte[256];
> byte[] data2 = new byte[512];
> for (int i = 0; i < 512; i++)
> data2[i] = 0;
> for (byte b = -128; b < 127; b++)
> data[b + 128] = b;
> int len = 256;
> int off = 0;
> int off2 = 0;
> while (len >= 3) {
> // Encode 3 bytes at a time
> TBase64Utils.encode(data, off, 3, data2, off2);
> off += 3;
> off2 += 4;
> len -= 3;
> }
> if (len > 0) {
> // Encode remainder
> TBase64Utils.encode(data, off, len, data2, off2);
> }
> len = 256;
> off = 0;
> off2 = 0;
> while (len >= 3) {
> // Encode 3 bytes at a time
> TBase64Utils.decode(data2, off2, 4, data, off);
> off += 3;
> len -= 3;
> off2 += 4;
> }
> if (len > 0) {
> // Encode remainder
> TBase64Utils.decode(data2, off2, len, data, off);
> }
> for (byte b = -128; b < 127; b++)
> System.out.println("should be : " + (b) + " is : " + data[b + 128]);
> }
> The results :
> ...
> should be : -18 is : -18
> should be : -17 is : -18
> should be : -16 is : -1
> should be : -15 is : -15
> should be : -14 is : -15
> should be : -13 is : -14
> should be : -12 is : -12
> should be : -11 is : -12
> should be : -10 is : -11
> should be : -9 is : -9
> should be : -8 is : -5
> should be : -7 is : -8
> should be : -6 is : -6
> should be : -5 is : -6
> should be : -4 is : -5
> should be : -3 is : -3
> should be : -2 is : -3
> should be : -1 is : -1
> should be : 0 is : 0
> should be : 1 is : 1
> ...
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira