Commit 839c8131 authored by Tony Schaller's avatar Tony Schaller

closing file stream after load of CDA

git-svn-id: https://svn.code.sf.net/p/ehealthconnector/code/trunk@1699 e99adb7c-5e35-42fd-8d1b-cdb378af05e8
parent c5155032
......@@ -65,10 +65,10 @@ public abstract class CdaChUtil extends CdaUtil {
*/
public static CdaChLrepV1GeneralReport loadCdaChLrepV1GeneralReportFromFile(String filePath)
throws Exception {
CdaChLrepV1GeneralReport retVal = null;
FileInputStream fs = new FileInputStream(filePath);
retVal = loadCdaChLrepV1GeneralReportFromStream(
IOUtils.toInputStream(IOUtils.toString(fs, Charsets.UTF_8)));
CdaChLrepV1GeneralReport retVal = loadCdaChLrepV1GeneralReportFromStream(
IOUtils.toInputStream(IOUtils.toString(new InputStreamReader(fs, "UTF-8")),
Charsets.UTF_8));
fs.close();
return retVal;
}
......@@ -96,9 +96,10 @@ public abstract class CdaChUtil extends CdaUtil {
*/
public static CdaChV2StructuredBody<org.openhealthtools.mdht.uml.cda.ch.CdaChV2StructuredBody> loadCdaChV2FromFile(
String filePath) throws Exception {
CdaChV2StructuredBody<org.openhealthtools.mdht.uml.cda.ch.CdaChV2StructuredBody> retVal = null;
FileInputStream fs = new FileInputStream(filePath);
retVal = loadCdaChV2FromStream(IOUtils.toInputStream(IOUtils.toString(fs, Charsets.UTF_8)));
CdaChV2StructuredBody<org.openhealthtools.mdht.uml.cda.ch.CdaChV2StructuredBody> retVal = loadCdaChV2FromStream(
IOUtils.toInputStream(IOUtils.toString(new InputStreamReader(fs, "UTF-8")),
Charsets.UTF_8));
fs.close();
return retVal;
}
......
......@@ -370,7 +370,9 @@ public class CdaChV2StructuredBodyTest {
// cleanup
File file = new File(fn);
file.delete();
if (!file.delete())
file.deleteOnExit();
}
/**
......
......@@ -227,7 +227,8 @@ public class CdaChLrepV1GeneralReportTest {
// cleanup
File file = new File(fn);
file.delete();
if (!file.delete())
file.deleteOnExit();
}
/**
......
......@@ -21,6 +21,7 @@ package org.ehealth_connector.cda;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collection;
......@@ -28,6 +29,7 @@ import java.util.Comparator;
import java.util.Date;
import java.util.List;
import org.apache.commons.io.Charsets;
import org.apache.commons.lang3.NotImplementedException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.util.EcoreUtil;
......@@ -978,7 +980,8 @@ public abstract class AbstractCda<EClinicalDocument extends ClinicalDocument>
if (!yourFile.exists()) {
yourFile.createNewFile();
}
final FileOutputStream oFile = new FileOutputStream(yourFile, false);
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(yourFile),
Charsets.UTF_8);
// create emf resource
final CDAResource resource = (CDAResource) CDAResource.Factory.INSTANCE
......@@ -989,8 +992,8 @@ public abstract class AbstractCda<EClinicalDocument extends ClinicalDocument>
resource.getContents().add(docRoot);
// save resource to file
resource.save(oFile, null);
oFile.close();
resource.save(writer, null);
writer.close();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment