• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to do the encoding and decoding in Java?  RSS feed

 
kavinethere vasan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I hava a problem in encoding
what I want is , I want to get a enocded value of a String in string format
example: "vas" ----------->"diklildnSIikaOMh"
Has anyone done this ?if so Please give me some details

Thanks in advance
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are many ways to do this, in general you could get a ByteOutputStream, wrap it in an ObjectOutputStream, send the String to the OOS, read the bytes from the BOS then convert to a String representation (eg Base64 encode), but this doesn't give the output you specified. (I got 'rO0ABXQAA3Zhcw==')

Implementation is left to the user
 
kavinethere vasan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks david

but stil I have problem in implemetation, I would be greatefull if you help me more , because Im weak in Streams pls

I could not find any read method for BOS in API and also I think BOS mean ByteArrayOutputStream
following think ,I have done and I donnt how to read and convert, because there no read method in the API
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject("vas");
Thanks
kavi
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the API for the BOS to see how to read the bytes. Once you have the bytes, you need to convert it into a string form (I'm assuming). I chose Base64 encoding since it is fairly common, and used the 'unsupported Sun implementation', if you search the web you should be able to find a free implentation to use.
 
kavinethere vasan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
david
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!