• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

BufferedReader in J2ME

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Salut !
Is there a way to implement a BufferedReader in J2ME, I have to increase the speed of parsing XML with kXML (any other solutions are welcome !)
From now, , I give to the XmlParser an InputStreamReader, made from an
InputStream, open from a HttpConnection. I am right or is there a more
efficient way to do that ?
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sebastien,
Have a look at the below code http://developer.java.sun.com/developer/products/wireless/midp/articles/network/FirstExample.java as well as the article at http://developer.java.sun.com/developer/products/wireless/midp/articles/network/
It has very good answers for ur question.
Regards
Balaji

Originally posted by sebastien GUERLET:
Salut !
Is there a way to implement a BufferedReader in J2ME, I have to increase the speed of parsing XML with kXML (any other solutions


 
sebastien GUERLET
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Balaji but what I need is not a httpconnection tutorial...
I search an efficient way to parse XML with kXML.
If I where in J2SE, I will use a BufferedReader... and there's none in J2ME...
I think reading the InputStream byte by byte is quite slow.
Any idea ???
 
Author
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sebastien GUERLET:
Thank you Balaji but what I need is not a httpconnection tutorial...
I search an efficient way to parse XML with kXML.
If I where in J2SE, I will use a BufferedReader... and there's none in J2ME...
I think reading the InputStream byte by byte is quite slow.
Any idea ???


InputStream does allow multiple byte reads, but then you have the problem of sometimes not knowing exactly how big you should make your array before doing the read(). If you're fetching data from a server, then setContentLength() in the server side servlet:
BufferedReader file = null;
try
{
file = new BufferedReader(new FileReader(DATABASE_DIRECTORY + filename + ".csv"));
StringBuffer wholeFile = new StringBuffer();
String line;
while ((line = file.readLine()) != null)
{
wholeFile.append(line + "\n");
}
int length=wholeFile.length();
response.setContentLength(length);
out.println(wholeFile.toString());
}
catch(IOException ioe)
{
System.out.println("MenuServlet.doGet() IOException");
ioe.printStackTrace();
}
if (file != null)
file.close();

and this in the J2ME:
boolean status = false;
ContentConnection c = null;
InputStream is = null;
try
{
byte[] data;
c = (ContentConnection)Connector.open(filename);
is = c.openInputStream();
int len = (int)c.getLength();
int actual = 0;
if (len > 0)
{
data = new byte[len];
actual = is.read(data);
}
else
{
StringBuffer sb = new StringBuffer();
int ch;
while ((ch = is.read()) != -1)
{
sb.append((char)ch);
actual++;
}
data = sb.toString().getBytes();
}
status = app.merge(data, actual);
if (is != null)
is.close();
if (c != null)
c.close();
}
catch (IOException ioe)
{
System.out.println("download: IOException");
ioe.printStackTrace();
}
I haven't actually tested to see if this loads quicker - for example there may be better ways to buffer in the servlet, and so on. I'd be interested in the answer.. (rct@poqit.com)
Cheers...
------------------
Richard Taylor
Author of Professional Java Mobile Programming
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help me!
I can't get any XML-Parser to work with J2ME Wireless Toolkit!
Do I have to modify the Parser-Sourcefiles after including them into my project? I always get errore when building!
 
Richard Taylor
Author
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tell me a little more...
- which XML parser(s)?
- which version of the J2ME toolkit?
- a simple source example
------------------
Richard Taylor
Author of Professional Java Mobile Programming
 
Mark Owen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Richard,
finally got nanoXML to work.
I had to copy some import classes into the "\classes" folder of my MIDlet project.
NanoXML makes use of java.util.Locale, which isn't included in the MIDP API.
Thanks anyways!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic