--- android/Side9/src/dk/thoerup/side9/Side9Xml.java 2010/03/24 07:27:34 634 +++ android/Side9/src/dk/thoerup/side9/Side9Xml.java 2010/06/16 07:45:53 856 @@ -11,6 +11,7 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; + import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -22,23 +23,27 @@ public class Side9Xml { - static final int WIDTH = 300; + static final int WIDTH = 450; static final String BASEURL = "http://apps.todic.net/side9/"; - public static Document parseXML(String str) throws SAXException, IOException, ParserConfigurationException + public static Document parseXML(byte data[]) throws SAXException, IOException, ParserConfigurationException { DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); - return builder.parse( new ByteArrayInputStream(str.getBytes()) ); + + return builder.parse( new ByteArrayInputStream( data) ); } public static byte[] getContent(String uri) throws IOException { - byte buffer[] = new byte[256]; + byte buffer[] = new byte[4096]; + + ByteArrayOutputStream baos = new ByteArrayOutputStream(32768); //start buffer size - instead of default 32bytes URL url = new URL(uri); URLConnection connection = url.openConnection(); + connection.setConnectTimeout(2500); InputStream is = connection.getInputStream(); try { @@ -59,9 +64,8 @@ public static Side9Data loadXml() throws IOException, ParserConfigurationException, SAXException{ String dataURL = BASEURL + "xml.php?width=" + WIDTH; - byte data[] = getContent( dataURL ); - String xmlData = new String(data, "UTF-8"); - Document doc = parseXML(xmlData); + byte data[] = getContent( dataURL ); + Document doc = parseXML( data ); Node rootNode = doc.getDocumentElement(); // stations NodeList nodes = rootNode.getChildNodes();