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. Video Playback / h264 encoded videos

We convert videos using ffmpeg to downsize mp4 videos. The result is a
h264 encoded video that can be played on the iPhone, in Quicktime and
other media players but the Android.
If i simply convert the source video file via Quicktime the video can
be played but i can't see any reasons why the video converted via
ffmpeg is not playing on android devices.

To show the videos i use the standard media player library from
android (android.media.MediaPlayer) which works mostly fine but not
here. As the converted video works on other (non-android) devices i
assume that this is an Android/Java problem.

Does anyone know what settings I have to use or what i have to change
to make it work with android handsets?



The converted video got the following media information :

Format                           : MPEG-4
Format profile                   : Base Media
Codec ID                         : isom
File size                        : 11.2 MiB
Duration                         : 2mn 33s
Overall bit rate                 : 611 Kbps
Encoded date                     : UTC 1970-01-01 00:00:00
Tagged date                      : UTC 1970-01-01 00:00:00
Writing application              : Lavf52.34.1

Video
ID                               : 1
Format                           : AVC
Format/Info                      : Advanced Video Codec
Format profile                   : basel...@l2.0
Format settings, CABAC           : No
Format settings, ReFrames        : 5 frames
Codec ID                         : avc1
Codec ID/Info                    : Advanced Video Coding
Duration                         : 2mn 33s
Bit rate mode                    : Variable
Bit rate                         : 511 Kbps
Width                            : 320 pixels
Height                           : 240 pixels
Display aspect ratio             : 1.422
Original display aspect ratio    : 1.423
Frame rate mode                  : Constant
Frame rate                       : 25.000 fps
Resolution                       : 24 bits
Colorimetry                      : 4:2:0
Scan type                        : Progressive
Bits/(Pixel*Frame)               : 0.266
Stream size                      : 9.35 MiB (84%)
Language                         : English
Encoded date                     : UTC 1970-01-01 00:00:00
Tagged date                      : UTC 1970-01-01 00:00:00

Audio
ID                               : 2
Format                           : AAC
Format/Info                      : Advanced Audio Codec
Format version                   : Version 4
Format profile                   : LC
Format settings, SBR             : No
Codec ID                         : 40
Duration                         : 2mn 33s
Bit rate mode                    : Variable
Bit rate                         : 96.0 Kbps
Channel(s)                       : 2 channels
Channel positions                : L R
Sampling rate                    : 44.1 KHz
Resolution                       : 16 bits
Stream size                      : 1.75 MiB (16%)
Language                         : English


-----------

Please let me know if more information are needed.
--~--~---------~--~----~------------~-------~--~----~

2. Who makes embedded hardware Android devices?

I'm playing around with an idea in the back of my head, was wondering
if there were any Android devices that had touchscreen and wifi - no
other requirements necessary.  The GiiNii Movit Mini is as close to
what I'm looking for as I can find.  Are there hardware vendors that
make custom Android products such as this?  Inexpensive, ARM or MIPS,
run Android, touchscreen, wifi, that's it.  Thanks.

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

3. AppWidgetProviderInfo documentation not found?

4. auto-repeat Buttons

5. Reloading our Activities State after firing Intent to camera

6. task affinity - what is it?

7. Developer review of all Android (Cupcake) devices - HTC vs. Samsung, test cases, etc.