You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2010/05/20 13:37:47 UTC

DO NOT REPLY [Bug 49317] New: org.apache.catalina.util.Base64 interface needs refactoring

https://issues.apache.org/bugzilla/show_bug.cgi?id=49317

           Summary: org.apache.catalina.util.Base64 interface needs
                    refactoring
           Product: Tomcat 7
           Version: trunk
          Platform: PC
        OS/Version: Windows Server 2003
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: dblock@dblock.org


The interface in org.apache.catalina.util.Base64 is not symmetrical. Base64 
always returns a valid string from encoding and bytes when decoding. So it
should look like this:

String encode(byte[])
byte[] decode(String)

similarly, if you need chunks

void encode(ByteChunk, CharChunk)
void decode(CharChunk, ByteChunk)

You can write this interface with the current code:

    public static String encode(byte[] value) {
        return new String(encode(value));
    }

    private byte[] decode(String value) throws IOException {
        ByteChunk encoded = new ByteChunk();
        encoded.append(value.getBytes(), 0, value.length());
        CharChunk decoded = new CharChunk();         
        decode(encoded, decoded);
        byte[] result = new byte[decoded.getLength()];
        for(int i = 0; i < decoded.getLength(); i++) {
            result[i] = (byte) decoded.getBuffer()[i];
        }
        return result;
    }

(see how nasty decode looks now)

Better, refactor the class to have the interface I suggest.

Attached is an implementation that is much more elegant, although it's probably
less efficient (now how many times do we really do base64 encode/decode - 1-2
per request).

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 49317] org.apache.catalina.util.Base64 interface needs refactoring

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49317

Mark Thomas <ma...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #1 from Mark Thomas <ma...@apache.org> 2010-05-20 07:58:15 EDT ---
Looks like you forgot to provide your attachment.

The current implementation isn't symmetrical because that isn't what Tomcat
needs (keeping in mind this class is primarily for use by Tomcat internals).
That said, every method that calls encode then converts to String so that can
change to clean the code up a little. I'll make that change shortly.

This gets called frequently enough that I'd at least want to check performance
of old implementation against any new one.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


DO NOT REPLY [Bug 49317] org.apache.catalina.util.Base64 interface needs refactoring

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=49317

Tim Funk <fu...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |WONTFIX

--- Comment #2 from Tim Funk <fu...@apache.org> 2010-11-01 17:34:00 EDT ---
Since this is internal for tomcat only - I am marking as WONTFIX since it is
change without any functional need.

If a webapp needs a Base64 util class, there are many other public
implementations.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org