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: [email protected]
ReportedBy: [email protected]
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: [email protected]
For additional commands, e-mail: [email protected]