Author: adietish
Date: 2012-01-17 09:35:47 -0500 (Tue, 17 Jan 2012)
New Revision: 37896
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/OpenShiftMavenProfile.java
Log:
[JBIDE-10479] added closing of outputstream
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/OpenShiftMavenProfile.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/OpenShiftMavenProfile.java 2012-01-17
14:34:38 UTC (rev 37895)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.express.ui/src/org/jboss/tools/openshift/express/internal/ui/wizard/appimport/OpenShiftMavenProfile.java 2012-01-17
14:35:47 UTC (rev 37896)
@@ -17,6 +17,7 @@
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
+import java.io.Writer;
import java.text.MessageFormat;
import javax.xml.parsers.DocumentBuilder;
@@ -142,7 +143,8 @@
}
}
- private Element createOpenShiftProfileElement(String finalName) throws
ParserConfigurationException, SAXException, IOException {
+ private Element createOpenShiftProfileElement(String finalName) throws
ParserConfigurationException, SAXException,
+ IOException {
DocumentBuilder documentBuilder =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
String openShiftProfile = MessageFormat.format(OPENSHIFT_PROFILE, finalName);
Document document = documentBuilder.parse(new
ByteArrayInputStream(openShiftProfile.getBytes()));
@@ -282,6 +284,7 @@
}
public void savePom() throws CoreException {
+ Writer writer = null;
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setAttribute("indent-number", new Integer(4));
@@ -291,9 +294,8 @@
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- Result out =
- new StreamResult(
- new OutputStreamWriter(new FileOutputStream(pomFile.getLocation().toString()),
"UTF-8"));
+ writer = new OutputStreamWriter(new
FileOutputStream(pomFile.getLocation().toString()), "UTF-8");
+ Result out = new StreamResult(writer);
transformer.transform(new DOMSource(getDocument()), out);
} catch (TransformerConfigurationException e) {
throw new CoreException(createStatus(e));
@@ -303,8 +305,22 @@
throw new CoreException(createStatus(e));
} catch (FileNotFoundException e) {
throw new CoreException(createStatus(e));
+ } finally {
+ safeClose(writer);
}
}
+
+ private void safeClose(Writer writer) {
+ if (writer == null) {
+ return;
+ }
+ try {
+ writer.flush();
+ writer.close();
+ } catch (IOException e) {
+ // ignore;
+ }
+ }
public static boolean isMavenProject(IProject project) {
return project.getFile(POM_FILENAME).exists();
Show replies by date