2

Is it possible to set a timeout when loading an xml directly from a URL?

Builder parser = new Builder();
Document doc = parser.build("http://somehost");

This may take sometimes minutes, and would be really handy to be able to time this out directly in the library.

Kai
  • 38,985
  • 14
  • 88
  • 103
D_K
  • 1,410
  • 12
  • 35

1 Answers1

5

You need to use build(InputStream inStream) api instead of build(String systemID).

URL url = new URL("http://somehost");
con = url.openConnection();
con.setConnectTimeout(connectTimeout);
con.setReadTimeout(readTimeout);
inStream = con.getInputStream();
Builder parser = new Builder();
Document doc = parser.build(inStream);
Luca
  • 4,223
  • 1
  • 21
  • 24