commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Julius Davies (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CODEC-69) Streaming Base64
Date Thu, 19 Jun 2008 17:27:45 GMT

    [ https://issues.apache.org/jira/browse/CODEC-69?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12606470#action_12606470
] 

Julius Davies commented on CODEC-69:
------------------------------------

To reply to Sebb's comment on CODEC-8:

Base64 encoding will only emit bytes in chunks of 4.

For example:

1. read a byte... nothing emitted
2. read a byte... nothing emitted
3. read a byte...  4 bytes emitted.
4. read a byte... nothing emitted.
5. EOF!   4 bytes emitted (e.g. AA==).


So even if a "lineLength" of 75 is passed to the constructor, the lines will still be 76 characters
long.  Not because we ever actually round the number up, but because of this part of the encode()
method (the += 4 in particular):

{code}
buf[pos++] = intToBase64[(x >> 18) & 0x3f];
buf[pos++] = intToBase64[(x >> 12) & 0x3f];
buf[pos++] = intToBase64[(x >> 6) & 0x3f];
buf[pos++] = intToBase64[x & 0x3f];
currentLinePos += 4;
if (lineLength > 0 && lineLength <= currentLinePos) {
  System.arraycopy(lineSeparator, 0, buf, pos, lineSeparator.length);
  pos += lineSeparator.length;
  currentLinePos = 0;
}
{code}


I can't think of a good name for this magic number!  Maybe ENCODE_UNIT ?

> Streaming Base64
> ----------------
>
>                 Key: CODEC-69
>                 URL: https://issues.apache.org/jira/browse/CODEC-69
>             Project: Commons Codec
>          Issue Type: Improvement
>            Reporter: Julius Davies
>            Assignee: Jochen Wiedmann
>            Priority: Minor
>             Fix For: 1.4
>
>         Attachments: streaming-base64.patch
>
>
> Would be nice to have Base64InputStream and Base64OutputStream, with both supporting
ENCODE or DECODE modes.

-- 
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