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. welcome... Android ?

Hi guys

I'd like to start working on Android platform in parallel with the
iPhone....
but seems quite impossible to start even installing the SDK....
not clear if compatible or not with  OS X 10.6.2
no clear installation for the latest OS X....

I downloaded  Mac OS X (intel)  android-sdk_r05-mac_86.zip   from this
page
http://developer.android.com/sdk/index.html

installed it, and launched  'tools/android' in the console, and got
Starting Android SDK and AVD Manager
Warning: The Mac OS -XstartOnFirstThread: is currently unsupported
No command line parameters provided, launching UI.
See 'android --help' for operations from the command line.
Trace/BPT trap

I read also that SDK Tools, Revision 5 (March 2010) Fixes issue with
64-bit JVM on Window , BUT not on OS X 10.6 ?

I tried also to modify the Java Preferences SE 6 32-bits first ...
same issue

so is it or not supported ???
not sure that google android likes apple os x these last days..... so
should I forgot this platform ?

-- 

2. Buying a new Android phone - can I keep my apps?




If you're signing in to the new phone with the same Google account you used
to buy them, they should be there waiting for you when set up your new
phone.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking

-- 

3. Market spams by Genwi

4. Building kernel for I/O device

5. Android File System Permission (Accessing Private folder in file system)

6. Crash in call to opeCameraHardware()

7. transforming an activity to a modal full screen dialog