开发者

Getting SAXException while using document.parse(string)

I want to reuse the Inputstream coming from HTTP response.resultset()...

  • I converted inputstream to byte[] array (also need to store so I create byte array.)
  • Than convert into string
  • when i pass it to document.parse(string) gave error saxparserException:---eof not found
  • working fine with document.parse(stream).

//------------Following methods are not helpfull for me ,each of them leads to

saxparserException protocl not found .

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.IOException;    

public static String readInputStreamAsString(InputStream in) 
    throws IOException {

    BufferedInputStream bis = new BufferedInputStream(in);
    ByteArrayOutputStream buf = new ByteArrayOutputStream();
    int result = bis.read();
    while(result != -1) {
      byte b = (byte)result;
      buf.write(b);
      result = bis.read();
    }        
    return buf.toString();
}



//--------------


byte[] bytes=new byte[inputStream.available()];
inputStream.read(bytes);
String s = new String(bytes);

//------------------

  StringBuilder response = new StringBuilder();
  int value = 0;
  boolean active = true;
  while (active) {
        value = is.read();
        if (value == -1) {
            throw new IOException("End of Stream");
        } else if (value != '\n') {
            response.append((char) value);
            continue;
        } else {
            active = false;
        }
    }
    return response.toString();

//--------------

开发者_StackOverflow BufferedInputStream ib = new BufferedInputStream(is,1024*1024);
 StringBuffer sb = new StringBuffer();
 String temp = ib.readLine();
 while (temp !=null){
     sb.append (temp);
     sb.append ("\n");
     temp = ib.readLine();
    }
 s = sb.toString()


I solved the issue by using:-

document.parse(new ByteArrayInputStream(stream))


If you got http response which includes xml data, you can parse xml data using saxparser.


I suspect you may have misunderstood the SAXParser.parse method signature.

The versions of the parse method that take a String argument expect that String to represent a URI referring to the content and not the content itself.

If you've saved your input in a String variable, you're best off opening a StringReader on the string, basing an InputSource on the StringReader, and passing that to the parser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜