encode html with inputstream

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


Sponsored Links
 Hi,

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 
InputStreamReader(is,"windows-1252");

                        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?

thanks
chris

--~--~---------~--~----~------------~-------~--~----~



encode html with inputstream

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


 Hi,

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.

Albert.



--~--~---------~--~----~------------~-------~--~----~


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(),
"windows-1252");
*/

Just:
import org.apache.http.util.EncodingUtils;


I hope that helps

Greets
Chris

--~--~---------~--~----~------------~-------~--~----~



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
app2sdnya.

terima kasih

salam,
deddy

-- 
"Indonesian Android Community [id-android]" 

2. understanding intents and notepad sample

hi,
can somebody clarify few things here. I read
http://developer.android.com/guide/topics/intents/intents-filters.html
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
<intent-filter>
            <action android:name="android.intent.action.CALL" />
            <category android:name="android.intent.category.LAUNCHER" /
</intent-filter>

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
<intent-filter>
            <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" />
</intent-filter>
<intent-filter>
            <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" />
</intent-filter>
to define kind of call back in an activity code but in turn I found
@Override
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
by
            // the user.  The have clicked on one, so return it now.
                        setResult(RESULT_OK, new
Intent().setData(uri));
            } else {
            // Launch activity to view/edit the currently selected
item
                        startActivity(new Intent(Intent.ACTION_EDIT,
uri));
            }
}
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!!

cheers

-- 

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?