[android-developers] Re: Reading webpage data

2010-09-17 Thread Maps.Huge.Info (Maps API Guru)
Try using read instead:

byte[] buffer = new byte[2048];

ByteArrayOutputStream baos = new 
ByteArrayOutputStream();

while ((size = in.read(buffer, 0, 
buffer.length)) != -1) {
total += size ;
baos.write(buffer, 0, size) ;
}

Warning: code pasted from brain - could contain errors...

-John Coryat

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Reading webpage data

2010-09-17 Thread pramod.deore

Hi, John Thanks for your  reply.I had tried it but it gives me error
If I used as
 while ((size = in.read(buffer, 0, buffer.length)) != -1)
Then here read() method requires first parameter as char[]  not a
byte[]. If I changed  byte[] buffer = new byte[2048]; to char[] buffer
= new char[2048];
Then at the time of writing file as baos.write(buffer, 0, size) ;
requires byte[]instead of char[].

Now how to solve this. thanks

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Reading webpage data

2010-09-17 Thread pramod.deore

Hi, John after changing code like following I think it is working (i
had tried only on small data till)
 try
 {
 imageFile.createNewFile();
 PrintWriter out = new PrintWriter(imageFile);
 URL yahoo = new URL(URL);

 BufferedReader in = new BufferedReader(new
InputStreamReader(yahoo.openStream()));

 char[] buffer = new char[2048];

 ByteArrayOutputStream baos = new ByteArrayOutputStream();
 BufferedWriter bw = new BufferedWriter(out);

 while ((size = in.read(buffer, 0, buffer.length)) != -1)
 {
 System.out.println (Inside while);
 total += size ;
 bw.write(buffer, 0, size) ;

 }

out.flush();
baos.close();




 }
 catch (MalformedURLException me)
 {
 System.out.println(me);

 }
 catch (IOException ioe)
 {
 System.out.println(ioe);
 }
But now speed is very slow as compared to first code, How to improve
performance of code.

Thanks

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en