added a finally block to ensure that the InputStream is closed if an exception is raised

master
Mohammed Le Doze 15 years ago
parent 5367907eee
commit 635c7017a9

@ -10,14 +10,11 @@
* For any reuse or distribution, you must make clear to others the
* license terms of this work.
*/
package com.moviejukebox.themoviedb.tools;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@ -35,6 +32,7 @@ import org.xml.sax.SAXException;
*
*/
public class DOMHelper {
/**
* Gets the string value of the tag element name passed
* @param element
@ -60,22 +58,27 @@ public class DOMHelper {
* Get a DOM document from the supplied URL
* @param url
* @return
* @throws MalformedURLException
* @throws IOException
* @throws ParserConfigurationException
* @throws SAXException
*/
public static Document getEventDocFromUrl(String url)
throws MalformedURLException, IOException, ParserConfigurationException, SAXException, UnsupportedEncodingException {
//InputStream in = (new URL(url)).openStream();
String webPage = WebBrowser.request(url);
InputStream in = new ByteArrayInputStream(webPage.getBytes("UTF-8"));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(in);
throws IOException, ParserConfigurationException, SAXException {
Document doc = null;
InputStream in = null;
try {
String webPage = WebBrowser.request(url);
in = new ByteArrayInputStream(webPage.getBytes("UTF-8"));
doc.getDocumentElement().normalize();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
doc = db.parse(in);
doc.getDocumentElement().normalize();
} finally {
if (in != null) {
in.close();
}
}
return doc;
}
}

Loading…
Cancel
Save