encode html with inputstream

by guruk » Fri, 13 Mar 2009 20:38:47 GMT

Sponsored Links

i am reading a text from the net and like to have it right encoded
(german umlaute)

                        conn = new URL(mediaUrl).openConnection();
                        InputStream is = conn.getInputStream();
                        ByteArrayBuffer baf = new ByteArrayBuffer(50);
                        InputStreamReader isr = new 

                        int current = 0;
                        while ((current = isr.read()) != -1)
                                baf.append((byte) current);
                        Log.i(TAG, " *------ Load Data done -----*: ");

                        /* Convert the Bytes read to a String. */
                        html = new String(baf.toByteArray());

but still in my final "html" its not encoded and the german umlaute
are wrong.

Who can i read a stream and get it right encoded?



encode html with inputstream

by Albert Hernč°Šndez » Sun, 15 Mar 2009 00:12:57 GMT


Check these classes:
URLEncoder:  http://developer.android.com/reference/java/net/URLEncoder.html 
URLDecoder:  http://developer.android.com/reference/java/net/URLDecoder.html 

I hope that is what you need.



Sponsored Links

encode html with inputstream

by guruk » Sun, 15 Mar 2009 02:51:03 GMT

 Hi Albert,

thanks for your Effort, you already answered in my other post.
But URLEncoder, looks to encode the URL itself, not the Content.

Now I have this Solution for all other Beginners:

For example after I read my Content with:
while ((current = is.read()) != -1) { baf.append((byte) current);}

//just encode like bellow into a string.
html = EncodingUtils.getString(baf.toByteArray(), "UTF-8");

or any other Code you need like:
html = EncodingUtils.getString(baf.toByteArray(), "ISO-8859-1");
or //html = EncodingUtils.getString(baf.toByteArray(),

import org.apache.http.util.EncodingUtils;

I hope that helps



Other Threads

1. How to change text in a XML-defined text view

Lets say i define in the layout.main a text view but i want to change the
text during the execution of the application. How can i 'call' the view in
the code? Im guessing i can use R.java but i dont know how... Any ideas? An
example would be really cool...



Hugo Rafael Augusto


2. Problem while compiling the cupcake Android release for the HTC G1 dev edition

This question is more suited for the android platform forum

Balwinder Kaur
Open Source Development Center
T  Mobile stick together

The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.


3. AsyncTask - wait until the task has finished

4. Accessing the CallLog from a Service or Broadcastreceiver

5. Question on WebView.addJavaScriptInterface()

6. how to extract RAW HTML using WebView

7. How to use other app to 'view' the media in Gallery