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. Tanya App2sd

Bro gw mo tanya untuk app2sd, apa bisa kita buat untuk partisinya lebih dari
512mb, karena kalo dilihat dari menu file recovery pilihan yg tinggi hanya
512mb, kalo memang bisa lebih tinggi gimana caranya......? dan cara root
untuk partisi yg sudah di buat misalnya 1 GB untuk di jadikan app2sd.
soalnya gw punya MicroSD 8 GB (class 6) mau gw partisi 1 gb or 2 gb utk

terima kasih


"Indonesian Android Community [id-android]" 

2. understanding intents and notepad sample

can somebody clarify few things here. I read
about intents and tried to listen for CALL action so my application
could start if user dial a number and start conversation.

I tried with something like
            <action android:name="android.intent.action.CALL" />
            <category android:name="android.intent.category.LAUNCHER" /

but it doesnt seem to work.
But now after I ve examine the notepad sample (http://
developer.android.com/resources/samples/NotePad/index.html) I am even
more confused. I expected filters
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.EDIT" />
            <action android:name="android.intent.action.PICK" />
            <category android:name="android.intent.category.DEFAULT" /
            <data android:mimeType="vnd.android.cursor.dir/
vnd.google.note" />
            <action android:name="android.intent.action.GET_CONTENT" /
            <category android:name="android.intent.category.DEFAULT" /
            <data android:mimeType="vnd.android.cursor.item/
vnd.google.note" />
to define kind of call back in an activity code but in turn I found
protected void onListItemClick(ListView l, View v, int position, long
id) {
            Uri uri =
ContentUris.withAppendedId(getIntent().getData(), id);

            String action = getIntent().getAction();
            if (Intent.ACTION_PICK.equals(action) ||
Intent.ACTION_GET_CONTENT.equals(action)) {
            // The caller is waiting for us to return a note selected
            // the user.  The have clicked on one, so return it now.
                        setResult(RESULT_OK, new
            } else {
            // Launch activity to view/edit the currently selected
                        startActivity(new Intent(Intent.ACTION_EDIT,
so I dont know what to think about it and I cant find any explanation
for this sample.

could somebody guide me here in good direction, point me to some
resources that I obviously missed??
thanks for help!!



3. For X10i User. Ada yang pernah install update service nya X10i

4. Tragedi Nexus One, Pelajaran Pahit bagi Google

5. Cheap Embedded Android Phone (M2M device?)

6. (WTI) Panda Home, apk utk home screen yg kerenn..

7. How to tell if phone lock screen is up?