Closed FroMage closed 7 years ago
Wait, how should I interpret this? A charset that does encoding to/from Base64? Wow, never thought of it that way :)
One of Java 8's big new features ;)
Oh I thought lambda's would be its big feature ;)
http://openjdk.java.net/jeps/135 and http://download.java.net/jdk8/docs/api/java/util/Base64.html for what Java does.
I think we rather need a Base64 encoder/decoder of ByteArray<->String like they have. It's not really a Charset, especially since converting text to Base64 in binary means text -> charset convertion (UTF or else) to binary -> Base64 conversion to String -> charset conversion (probably ASCII) to binary.
We just need utility methods that do this chaining for us.
There is another implementation that is public domain and as far as I know has been copied countless times due to the sun.util.Base64 being in the "proprietary" namespace: http://iharder.sourceforge.net/current/java/base64/
@FroMage - Can you elaborate what need to be done? And from where should I start if I am to work on this issue ? As I understand(by the comment),what is needed is implementation similar to http://download.java.net/jdk8/docs/api/java/util/Base64.html.
Hi @Bhathiya90 this is partially implemented: https://github.com/ceylon/ceylon-sdk/blob/master/source/ceylon/io/base64.ceylon , i think maybe it would be good to complete with same RFC implementations as your link.
@FroMage @DiegoCoronel
Started with some helper methods without changing the implemeted base64 encode/decode.
/*Encode a givenString to Base64.*/
shared String encodeStringToString(String string ,String enc = "ASCII"){
//In the java implemetation i am reffering string.getBytes() is used
value cs = getCharset(enc);
if(exists cs){
return encodeByteToString(cs.encode(string), enc);
}
throw Exception("Charset not supported ");
}
shared String encodeByteToString(ByteBuffer inputBuffer,String enc ="ASCII"){
// in java new String(byte[] b ) is used
ByteBuffer encodedBuffer = base64.getEncoder().encode(inputBuffer);//uses already implemeted base64 encoding
value cs = getCharset(enc);
if(exists cs){
return cs.decode(encodedBuffer);
}
throw Exception("Charset not supported");
}
is this what you are looking for?
I think we should add the following methods on the base64
object:
"Encodes the given string in Base64 using the given character encoding"
shared String encode(String input, Charset charset);
"Decodes the given string from Base64 using the given character encoding"
shared String decode(String input, Charset charset);
Here , https://github.com/Bhathiya90/ceylon-sdk/blob/master/source/ceylon/io/base64.ceylon implemented
shared String encode(String input, String charset);
shared String decode(String input, String charset); methods with a class Base64Helper().
In most of the java implementations Charset is passed as a String (with platform's default character encoding as default) ? What should we choose? Charset charset or String charset?
Definitly keep it type-safe with Charset
.
@FroMage Changed the methods to take a Charset.What should I do next? as for me if I 1- Change/ Reimplement shared actual ByteBuffer decode(ByteBuffer encoded) to discard padding 2 -Update testing classes to test new methods added this issue can be closed.Is it?
Changed the base64 test classas well. https://github.com/Bhathiya90/ceylon-sdk/blob/master/test-source/test/ceylon/io/testBase64.ceylon
Sounds great. Can you create a pull-request?
Charset
and Base64
, as part of the unified Codec
types.I think this is done and in ceylon.buffer
now.
Yeah. the implementation is in base64.ceylon
That will be very useful :)