You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Julius Davies (JIRA)" <ji...@apache.org> on 2009/10/28 07:21:59 UTC

[jira] Updated: (CODEC-89) new Base64().encode() appends a CRLF, and chunks results into 76 character lines

     [ https://issues.apache.org/jira/browse/CODEC-89?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Julius Davies updated CODEC-89:
-------------------------------

    Description: 
The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.


{code}
import org.apache.commons.codec.binary.*;

public class B64 {

  public static void main(String[] args) throws Exception {
    Base64 b64 = new Base64();

    String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    String s2 = "aaaaaaaaaa";
    String s3 = "a";
    
    byte[] b1 = s1.getBytes("UTF-8");
    byte[] b2 = s2.getBytes("UTF-8");
    byte[] b3 = s3.getBytes("UTF-8");

    byte[] result;
    result = Base64.encodeBase64(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");

  }
}
{code}


Here's my output:

{noformat}
$ java -cp commons-codec-1.3.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YQ==]
[YQ==]


$ java -cp commons-codec-1.4.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==
]
[YQ==]
[YQ==
]
{noformat}


  was:
new Base64().encode() appends a CRLF

{code}
import org.apache.commons.codec.binary.*;

public class B64 {

  public static void main(String[] args) throws Exception {
    Base64 b64 = new Base64();

    String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    String s2 = "aaaaaaaaaa";
    String s3 = "a";
    
    byte[] b1 = s1.getBytes("UTF-8");
    byte[] b2 = s2.getBytes("UTF-8");
    byte[] b3 = s3.getBytes("UTF-8");

    byte[] result;
    result = Base64.encodeBase64(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b1);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b2);
    System.out.println("[" + new String(result, "UTF-8") + "]");

    result = Base64.encodeBase64(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");
    result = b64.encode(b3);
    System.out.println("[" + new String(result, "UTF-8") + "]");

  }
}
{code}


Here's my output:

{noformat}
$ java -cp commons-codec-1.3.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==]
[YQ==]
[YQ==]


$ java -cp commons-codec-1.4.jar:. B64
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
]
[YWFhYWFhYWFhYQ==]
[YWFhYWFhYWFhYQ==
]
[YQ==]
[YQ==
]
{noformat}


        Summary: new Base64().encode() appends a CRLF, and chunks results into 76 character lines  (was: new Base64().encode() appends a CRLF)

> new Base64().encode() appends a CRLF, and chunks results into 76 character lines
> --------------------------------------------------------------------------------
>
>                 Key: CODEC-89
>                 URL: https://issues.apache.org/jira/browse/CODEC-89
>             Project: Commons Codec
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Julius Davies
>
> The instance encode() method (e.g. new Base64().encode()) appends a CRLF.  Actually it's fully chunking the output into 76 character lines.  Commons-Codec-1.3 did not do this.  The static Base64.encodeBase64() method behaves the same in both 1.3 and 1.4, so this problem only affects the instance encode() method.
> {code}
> import org.apache.commons.codec.binary.*;
> public class B64 {
>   public static void main(String[] args) throws Exception {
>     Base64 b64 = new Base64();
>     String s1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
>     String s2 = "aaaaaaaaaa";
>     String s3 = "a";
>     
>     byte[] b1 = s1.getBytes("UTF-8");
>     byte[] b2 = s2.getBytes("UTF-8");
>     byte[] b3 = s3.getBytes("UTF-8");
>     byte[] result;
>     result = Base64.encodeBase64(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b1);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b2);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = Base64.encodeBase64(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>     result = b64.encode(b3);
>     System.out.println("[" + new String(result, "UTF-8") + "]");
>   }
> }
> {code}
> Here's my output:
> {noformat}
> $ java -cp commons-codec-1.3.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==]
> [YQ==]
> [YQ==]
> $ java -cp commons-codec-1.4.jar:. B64
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFh
> YWFhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYQ==
> ]
> [YWFhYWFhYWFhYQ==]
> [YWFhYWFhYWFhYQ==
> ]
> [YQ==]
> [YQ==
> ]
> {noformat}

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