Commit 92861224 authored by Mihai Nita's avatar Mihai Nita

Eliminate memory leaks (as reported by Eclipse)

parent 10b2157f
...@@ -231,8 +231,8 @@ public final class IntegrationtestUtils { ...@@ -231,8 +231,8 @@ public final class IntegrationtestUtils {
if (paramters != null) { if (paramters != null) {
filter.setParameters((IParameters) paramters); filter.setParameters((IParameters) paramters);
} }
try { try (RawDocument rawDoc = new RawDocument(snippet, LocaleId.ENGLISH)) {
filter.open(new RawDocument(snippet, LocaleId.ENGLISH)); filter.open(rawDoc);
while (filter.hasNext()) { while (filter.hasNext()) {
Event event = filter.next(); Event event = filter.next();
list.add(event); list.add(event);
......
...@@ -79,31 +79,33 @@ public final class RoundTripUtils { ...@@ -79,31 +79,33 @@ public final class RoundTripUtils {
// Filter events to raw document final step (using the XLIFF writer) // Filter events to raw document final step (using the XLIFF writer)
FilterEventsWriterStep fewStep = new FilterEventsWriterStep(); FilterEventsWriterStep fewStep = new FilterEventsWriterStep();
XLIFFWriter writer = new XLIFFWriter(); try (XLIFFWriter writer = new XLIFFWriter();
fewStep.setFilterWriter(writer); RawDocument originalDoc = new RawDocument(Util.toURI(originalPath), StandardCharsets.UTF_8.name(), source, target)) {
XLIFFWriterParameters params = (XLIFFWriterParameters)writer.getParameters();
params.setPlaceholderMode(false); fewStep.setFilterWriter(writer);
params.setIncludeAltTrans(true); XLIFFWriterParameters params = writer.getParameters();
params.setEscapeGt(true); params.setPlaceholderMode(false);
params.setIncludeCodeAttrs(true); params.setIncludeAltTrans(true);
params.setCopySource(true); params.setEscapeGt(true);
params.setIncludeIts(true); params.setIncludeCodeAttrs(true);
params.setIncludeNoTranslate(true); params.setCopySource(true);
params.setToolId("okapi"); params.setIncludeIts(true);
params.setToolName("okapi-tests"); params.setIncludeNoTranslate(true);
params.setToolCompany("okapi"); params.setToolId("okapi");
params.setToolVersion("M29"); params.setToolName("okapi-tests");
params.setToolCompany("okapi");
fewStep.setDocumentRoots(Util.getDirectoryName(originalPath)); params.setToolVersion("M29");
driver.addStep(fewStep);
RawDocument originalDoc = new RawDocument(Util.toURI(originalPath), StandardCharsets.UTF_8.name(), source, target); fewStep.setDocumentRoots(Util.getDirectoryName(originalPath));
originalDoc.setFilterConfigId(filterConfig); driver.addStep(fewStep);
originalDoc.setFilterConfigId(filterConfig);
driver.addBatchItem(originalDoc, new File(outputPath).toURI(), StandardCharsets.UTF_8.name()); driver.addBatchItem(originalDoc, new File(outputPath).toURI(), StandardCharsets.UTF_8.name());
// Process // Process
driver.processBatch(); driver.processBatch();
}
} }
public static void merge(LocaleId source, LocaleId target, Boolean legacy, String originalPath, String xlfPath, String outputPath, String filterConfig, String customConfigPath) throws URISyntaxException { public static void merge(LocaleId source, LocaleId target, Boolean legacy, String originalPath, String xlfPath, String outputPath, String filterConfig, String customConfigPath) throws URISyntaxException {
...@@ -120,25 +122,27 @@ public final class RoundTripUtils { ...@@ -120,25 +122,27 @@ public final class RoundTripUtils {
mapper.updateCustomConfigurations(); mapper.updateCustomConfigurations();
} }
RawDocument originalDoc = new RawDocument(Util.toURI(originalPath), StandardCharsets.UTF_8.name(), source, target); try (RawDocument originalDoc = new RawDocument(Util.toURI(originalPath), StandardCharsets.UTF_8.name(), source, target);
originalDoc.setFilterConfigId(filterConfig); RawDocument xlfDoc = new RawDocument(Util.toURI(xlfPath), StandardCharsets.UTF_8.name(), source, target)) {
originalDoc.setFilterConfigId(filterConfig);
IPipelineDriver driver = new PipelineDriver(); IPipelineDriver driver = new PipelineDriver();
driver.setFilterConfigurationMapper(mapper); driver.setFilterConfigurationMapper(mapper);
BatchItemContext bic = new BatchItemContext( BatchItemContext bic = new BatchItemContext(
new RawDocument(Util.toURI(xlfPath), StandardCharsets.UTF_8.name(), source, target), xlfDoc,
Util.toURI(outputPath), Util.toURI(outputPath),
StandardCharsets.UTF_8.name(), StandardCharsets.UTF_8.name(),
originalDoc); originalDoc);
driver.addBatchItem(bic); driver.addBatchItem(bic);
if (legacy) { if (legacy) {
driver.addStep(new LegacyXliffMergerStep()); driver.addStep(new LegacyXliffMergerStep());
} else { } else {
driver.addStep(new OriginalDocumentXliffMergerStep()); driver.addStep(new OriginalDocumentXliffMergerStep());
}
driver.addStep(new RawDocumentWriterStep());
driver.processBatch();
driver.destroy();
} }
driver.addStep(new RawDocumentWriterStep());
driver.processBatch();
driver.destroy();
} }
/** /**
......
package net.sf.okapi.common.pipeline.integration; package net.sf.okapi.common.pipeline.integration;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
...@@ -43,54 +44,58 @@ public class FilterEventsToRawDocumentStepTestIT ...@@ -43,54 +44,58 @@ public class FilterEventsToRawDocumentStepTestIT
Event event = null; Event event = null;
eventToDoc = new FilterEventsToRawDocumentStep(); eventToDoc = new FilterEventsToRawDocumentStep();
RawDocument rawDoc = new RawDocument(htmlSnippet, locEN); try (RawDocument rawDoc = new RawDocument(htmlSnippet, locEN)) {
File tmpFile = File.createTempFile("~okapi-1_", ".tmp"); File tmpFile = File.createTempFile("~okapi-1_", ".tmp");
eventToDoc.setOutputURI(tmpFile.toURI()); eventToDoc.setOutputURI(tmpFile.toURI());
eventToDoc.setOutputEncoding("UTF-8"); eventToDoc.setOutputEncoding("UTF-8");
htmlFilter.open(rawDoc); htmlFilter.open(rawDoc);
while (htmlFilter.hasNext()) { while (htmlFilter.hasNext()) {
event = eventToDoc.handleEvent(htmlFilter.next()); event = eventToDoc.handleEvent(htmlFilter.next());
} }
htmlFilter.close(); htmlFilter.close();
// last event should be RawDocument assertNotNull(event);
assertTrue(event.getEventType() == EventType.RAW_DOCUMENT); // last event should be RawDocument
// Get the EventsToRawDocumentStep output and compare it to our input assertTrue(event.getEventType() == EventType.RAW_DOCUMENT);
assertEquals(htmlSnippet, convertRawDocumentToString((RawDocument)event.getResource())); // Get the EventsToRawDocumentStep output and compare it to our input
eventToDoc.destroy(); assertEquals(htmlSnippet, convertRawDocumentToString((RawDocument)event.getResource()));
eventToDoc.destroy();
}
} }
@Test @Test
public void htmlEventsToRawDocument() throws IOException { public void htmlEventsToRawDocument() throws IOException {
Event event = null; Event event = null;
eventToDoc = new FilterEventsToRawDocumentStep(); eventToDoc = new FilterEventsToRawDocumentStep();
RawDocument rawDoc = new RawDocument(htmlSnippet, locEN); try (RawDocument rawDoc = new RawDocument(htmlSnippet, locEN)) {
eventToDoc.setOutputEncoding("UTF-8"); eventToDoc.setOutputEncoding("UTF-8");
htmlFilter.open(rawDoc); htmlFilter.open(rawDoc);
while ( htmlFilter.hasNext() ) { while ( htmlFilter.hasNext() ) {
event = eventToDoc.handleEvent(htmlFilter.next()); event = eventToDoc.handleEvent(htmlFilter.next());
} }
htmlFilter.close(); htmlFilter.close();
// last event should be RawDocument assertNotNull(event);
assertTrue(event.getEventType() == EventType.RAW_DOCUMENT); // last event should be RawDocument
// Get the EventsToRawDocumentStep output and compare it to our input assertTrue(event.getEventType() == EventType.RAW_DOCUMENT);
assertEquals(htmlSnippet, convertRawDocumentToString((RawDocument)event.getResource())); // Get the EventsToRawDocumentStep output and compare it to our input
eventToDoc.destroy(); assertEquals(htmlSnippet, convertRawDocumentToString((RawDocument)event.getResource()));
eventToDoc.destroy();
}
} }
private String convertRawDocumentToString(RawDocument d) throws IOException { private String convertRawDocumentToString(RawDocument d) throws IOException {
int c; int c;
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
Reader r = d.getReader(); try (Reader r = d.getReader()) {
while ( true ) { while ( true ) {
c = r.read(); c = r.read();
if (c == -1) break; if (c == -1) break;
sw.append((char) c); sw.append((char) c);
}
} }
d.getReader().close();
return sw.toString(); return sw.toString();
} }
} }
...@@ -63,27 +63,27 @@ public class FilterRoundtripTestIT ...@@ -63,27 +63,27 @@ public class FilterRoundtripTestIT
@Test @Test
public void runPipelineFromString() { public void runPipelineFromString() {
driver.clearItems(); driver.clearItems();
RawDocument rd = new RawDocument( try (RawDocument rd = new RawDocument(
"<p>Before <input type=\"radio\" name=\"FavouriteFare\" value=\"spam\" checked=\"checked\"/> after.</p>", "<p>Before <input type=\"radio\" name=\"FavouriteFare\" value=\"spam\" checked=\"checked\"/> after.</p>",
locEN, locES); locEN, locES);
rd.setFilterConfigId("okf_html"); RawDocument rawDoc = new RawDocument((new File(root, "genericOutput.txt")).toURI(), "UTF-8", locES)) {
driver.addBatchItem(rd, (new File(root, "genericOutput.txt")).toURI(), "UTF-8"); rd.setFilterConfigId("okf_html");
driver.processBatch(); driver.addBatchItem(rd, (new File(root, "genericOutput.txt")).toURI(), "UTF-8");
assertEquals("spam", driver.processBatch();
PipelineTestUtil.getFirstTUSource(new RawDocument((new File(root, "genericOutput.txt")).toURI(), assertEquals("spam", PipelineTestUtil.getFirstTUSource(rawDoc));
"UTF-8", locES))); }
} }
@Test @Test
public void runPipelineFromStream() { public void runPipelineFromStream() {
driver.clearItems(); driver.clearItems();
RawDocument rd = new RawDocument("\nX\n\nY\n", locEN, locFR); try (RawDocument rd = new RawDocument("\nX\n\nY\n", locEN, locFR);
rd.setFilterConfigId("okf_html"); RawDocument rawDoc = new RawDocument((new File(root, "genericOutput.txt")).toURI(), "UTF-8", locFR)) {
driver.addBatchItem(rd, (new File(root, "genericOutput.txt")).toURI(), "UTF-8"); rd.setFilterConfigId("okf_html");
driver.processBatch(); driver.addBatchItem(rd, (new File(root, "genericOutput.txt")).toURI(), "UTF-8");
assertEquals("X Y", driver.processBatch();
PipelineTestUtil.getFirstTUSource(new RawDocument((new File(root, "genericOutput.txt")).toURI(), assertEquals("X Y", PipelineTestUtil.getFirstTUSource(rawDoc));
"UTF-8", locFR))); }
} }
@Test @Test
...@@ -91,22 +91,24 @@ public class FilterRoundtripTestIT ...@@ -91,22 +91,24 @@ public class FilterRoundtripTestIT
String snippet = "<b>TEST ME</b>"; String snippet = "<b>TEST ME</b>";
// First pass // First pass
driver.clearItems(); driver.clearItems();
RawDocument rd = new RawDocument(snippet, locEN, locES); try (RawDocument rd = new RawDocument(snippet, locEN, locES)) {
rd.setFilterConfigId("okf_html"); rd.setFilterConfigId("okf_html");
driver.addBatchItem(rd, (new File(root, "output1.html")).toURI(), "UTF-8"); driver.addBatchItem(rd, (new File(root, "output1.html")).toURI(), "UTF-8");
driver.processBatch(); driver.processBatch();
}
// Second pass // Second pass
driver.clearItems(); driver.clearItems();
rd = new RawDocument((new File(root, "output1.html")).toURI(), "UTF-8", locES, locEN); try (RawDocument rd = new RawDocument((new File(root, "output1.html")).toURI(), "UTF-8", locES, locEN)) {
rd.setFilterConfigId("okf_html"); rd.setFilterConfigId("okf_html");
driver.addBatchItem(rd, (new File(root, "output2.html")).toURI(), "UTF-8"); driver.addBatchItem(rd, (new File(root, "output2.html")).toURI(), "UTF-8");
driver.processBatch(); driver.processBatch();
}
// Check result // Check result
assertEquals(snippet, try (RawDocument rd = new RawDocument((new File(root, "output2.html")).toURI(), "UTF-8", locES)) {
PipelineTestUtil.getFirstTUSource(new RawDocument((new File(root, "output2.html")).toURI(), assertEquals(snippet, PipelineTestUtil.getFirstTUSource(rd));
"UTF-8", locES))); }
} }
@After @After
......
...@@ -81,18 +81,22 @@ public class MultistepPipelineTestIT ...@@ -81,18 +81,22 @@ public class MultistepPipelineTestIT
RawDocument rawDoc = new RawDocument(getUri("test01.xml"), "UTF-8", locEN, locFR); RawDocument rawDoc = new RawDocument(getUri("test01.xml"), "UTF-8", locEN, locFR);
rawDoc.setFilterConfigId("okf_xml"); rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test01.xml"), "UTF-8"); driver.addBatchItem(rawDoc, getOutputUri("test01.xml"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("test02.xml"), "UTF-8", locEN, locFR); rawDoc = new RawDocument(getUri("test02.xml"), "UTF-8", locEN, locFR);
rawDoc.setFilterConfigId("okf_xml"); rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test02.xml"), "UTF-8"); driver.addBatchItem(rawDoc, getOutputUri("test02.xml"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("test03.xml"), "UTF-8", locEN, locFR); rawDoc = new RawDocument(getUri("test03.xml"), "UTF-8", locEN, locFR);
rawDoc.setFilterConfigId("okf_xml"); rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test03.xml"), "UTF-8"); driver.addBatchItem(rawDoc, getOutputUri("test03.xml"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("test04.xml"), "UTF-8", locEN, locFR); rawDoc = new RawDocument(getUri("test04.xml"), "UTF-8", locEN, locFR);
rawDoc.setFilterConfigId("okf_xml"); rawDoc.setFilterConfigId("okf_xml");
driver.addBatchItem(rawDoc, getOutputUri("test04.xml"), "UTF-8"); driver.addBatchItem(rawDoc, getOutputUri("test04.xml"), "UTF-8");
rawDoc.close();
driver.processBatch(); driver.processBatch();
...@@ -119,16 +123,17 @@ public class MultistepPipelineTestIT ...@@ -119,16 +123,17 @@ public class MultistepPipelineTestIT
driver.addStep(step3); driver.addStep(step3);
// Set the info for the input and output // Set the info for the input and output
RawDocument rawDoc = new RawDocument(getUri("okapi_intro_test.html"), "UTF-8", locEN, locFR); try (RawDocument rawDoc = new RawDocument(getUri("okapi_intro_test.html"), "UTF-8", locEN, locFR)) {
rawDoc.setFilterConfigId("okf_html"); rawDoc.setFilterConfigId("okf_html");
driver.addBatchItem(rawDoc); driver.addBatchItem(rawDoc);
driver.processBatch(); driver.processBatch();
assertTrue(step3.isFound()); assertTrue(step3.isFound());
driver.clearItems(); driver.clearItems();
driver.clearSteps(); driver.clearSteps();
}
} }
@Test @Test
...@@ -149,16 +154,17 @@ public class MultistepPipelineTestIT ...@@ -149,16 +154,17 @@ public class MultistepPipelineTestIT
driver.addStep(findStep); driver.addStep(findStep);
// Set the info for the input and output // Set the info for the input and output
RawDocument rawDoc = new RawDocument(getUri("okapi_intro_test.html"), "UTF-8", locEN, locFR); try (RawDocument rawDoc = new RawDocument(getUri("okapi_intro_test.html"), "UTF-8", locEN, locFR)) {
rawDoc.setFilterConfigId("okf_html"); rawDoc.setFilterConfigId("okf_html");
driver.addBatchItem(rawDoc, getOutputUri("okapi_intro_test.html"), "UTF-8"); driver.addBatchItem(rawDoc, getOutputUri("okapi_intro_test.html"), "UTF-8");
driver.processBatch(); driver.processBatch();
assertTrue(findStep.isFound()); assertTrue(findStep.isFound());
driver.clearItems(); driver.clearItems();
driver.clearSteps(); driver.clearSteps();
}
} }
@Test @Test
...@@ -173,14 +179,17 @@ public class MultistepPipelineTestIT ...@@ -173,14 +179,17 @@ public class MultistepPipelineTestIT
RawDocument rawDoc = new RawDocument(getUri("Test01.properties"), "UTF-8", locEN, locEUES); RawDocument rawDoc = new RawDocument(getUri("Test01.properties"), "UTF-8", locEN, locEUES);
rawDoc.setFilterConfigId("okf_properties"); rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test01.properties"), "UTF-8"); driver.addBatchItem(rawDoc, getOutputUri("Test01.properties"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("Test02.properties"), "UTF-8", locEN, locEUES); rawDoc = new RawDocument(getUri("Test02.properties"), "UTF-8", locEN, locEUES);
rawDoc.setFilterConfigId("okf_properties"); rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test02.properties"), "UTF-8"); driver.addBatchItem(rawDoc, getOutputUri("Test02.properties"), "UTF-8");
rawDoc.close();
rawDoc = new RawDocument(getUri("Test03.properties"), "UTF-8", locEN, locEUES); rawDoc = new RawDocument(getUri("Test03.properties"), "UTF-8", locEN, locEUES);
rawDoc.setFilterConfigId("okf_properties"); rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test03.properties"), "UTF-8"); driver.addBatchItem(rawDoc, getOutputUri("Test03.properties"), "UTF-8");
rawDoc.close();
driver.processBatch(); driver.processBatch();
...@@ -203,16 +212,17 @@ public class MultistepPipelineTestIT ...@@ -203,16 +212,17 @@ public class MultistepPipelineTestIT
driver.addStep(new FilterEventsWriterStep()); driver.addStep(new FilterEventsWriterStep());
// Set the info for the input and output // Set the info for the input and output
RawDocument rawDoc = new RawDocument(getUri("Test01.properties"), "UTF-8", locEN); try (RawDocument rawDoc = new RawDocument(getUri("Test01.properties"), "UTF-8", locEN)) {
rawDoc.setFilterConfigId("okf_properties"); rawDoc.setFilterConfigId("okf_properties");
driver.addBatchItem(rawDoc, getOutputUri("Test01.properties"), "UTF-8"); driver.addBatchItem(rawDoc, getOutputUri("Test01.properties"), "UTF-8");
driver.processBatch(); driver.processBatch();
assertTrue((new File(getOutputUri("Test01.properties"))).exists()); assertTrue((new File(getOutputUri("Test01.properties"))).exists());
driver.clearItems(); driver.clearItems();
driver.clearSteps(); driver.clearSteps();
}
} }
private URI getUri(String fileName) throws URISyntaxException { private URI getUri(String fileName) throws URISyntaxException {
......
...@@ -29,6 +29,7 @@ import org.junit.Test; ...@@ -29,6 +29,7 @@ import org.junit.Test;
public class QueryManagerTestIT public class QueryManagerTestIT
{ {
private QueryManager qm; private QueryManager qm;
private PensieveTMConnector pensieveConnector;
private final LocaleId locENUS = LocaleId.fromString("EN-US"); private final LocaleId locENUS = LocaleId.fromString("EN-US");
private final LocaleId locFRFR = LocaleId.fromString("FR-FR"); private final LocaleId locFRFR = LocaleId.fromString("FR-FR");
...@@ -51,7 +52,7 @@ public class QueryManagerTestIT ...@@ -51,7 +52,7 @@ public class QueryManagerTestIT
qm.setRootDirectory(rootDir); qm.setRootDirectory(rootDir);
qm.setLanguages(locENUS, locFRFR); qm.setLanguages(locENUS, locFRFR);
PensieveTMConnector pensieveConnector = new PensieveTMConnector(); pensieveConnector = new PensieveTMConnector();
net.sf.okapi.connectors.pensieve.Parameters p = new net.sf.okapi.connectors.pensieve.Parameters(); net.sf.okapi.connectors.pensieve.Parameters p = new net.sf.okapi.connectors.pensieve.Parameters();
p.setDbDirectory(Util.ROOT_DIRECTORY_VAR); p.setDbDirectory(Util.ROOT_DIRECTORY_VAR);
qm.addAndInitializeResource( qm.addAndInitializeResource(
...@@ -66,6 +67,10 @@ public class QueryManagerTestIT ...@@ -66,6 +67,10 @@ public class QueryManagerTestIT
qm.close(); qm.close();
qm = null; qm = null;
} }
if (pensieveConnector != null) {
pensieveConnector.close();
pensieveConnector = null;
}
} }
@Test @Test
......
...@@ -53,44 +53,44 @@ public class XsltPipelineTestIT ...@@ -53,44 +53,44 @@ public class XsltPipelineTestIT
// Input resource // Input resource
URL inputXml = XsltPipelineTestIT.class.getResource("test.xml"); URL inputXml = XsltPipelineTestIT.class.getResource("test.xml");
// Make copy of input try (InputStream in1 = XsltPipelineTestIT.class.getResourceAsStream("identity.xsl");
InputStream in1 = XsltPipelineTestIT.class.getResourceAsStream("identity.xsl"); InputStream in2 = XsltPipelineTestIT.class.getResourceAsStream("remove_b_tags.xsl");
driver.addStep(new XsltTransformStep(in1)); RawDocument rd = new RawDocument(inputXml.toURI(), "UTF-8", locEN)) {
// Make copy of input
driver.addStep(new XsltTransformStep(in1));
// Remove b tags from input // Remove b tags from input
InputStream in2 = XsltPipelineTestIT.class.getResourceAsStream("remove_b_tags.xsl"); driver.addStep(new XsltTransformStep(in2));
driver.addStep(new XsltTransformStep(in2));
// Filtering step - converts resource to events // Filtering step - converts resource to events
driver.addStep(new RawDocumentToFilterEventsStep()); driver.addStep(new RawDocumentToFilterEventsStep());
// Writer step - converts events to a resource // Writer step - converts events to a resource
driver.addStep(new FilterEventsWriterStep()); driver.addStep(new FilterEventsWriterStep());
RawDocument rd = new RawDocument(inputXml.toURI(), "UTF-8", locEN); rd.setFilterConfigId("okf_xml");
rd.setFilterConfigId("okf_xml"); File outFile = new File(root, "output.xml");
File outFile = new File(root, "output.xml"); driver.addBatchItem(rd, outFile.toURI(), "UTF-8");
driver.addBatchItem(rd, outFile.toURI(), "UTF-8"); driver.processBatch();
driver.processBatch();
// Read the result and compare // Read the result and compare
StringBuilder tmp = new StringBuilder(); StringBuilder tmp = new StringBuilder();
BufferedReader reader; try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(outFile), "UTF-8"))) {
reader = new BufferedReader( char[] buf = new char[2048];
new InputStreamReader(new FileInputStream(outFile), "UTF-8")); int count;
char[] buf = new char[2048]; while ((count = reader.read(buf)) != -1) {
int count; tmp.append(buf, 0, count);
while ((count = reader.read(buf)) != -1) { }
tmp.append(buf, 0, count);
} }
//Remove new lines so this test will pass on all OSes // Remove new lines so this test will pass on all OSes
String tmpStr = tmp.toString().replaceAll("\n", ""); String tmpStr = tmp.toString().replaceAll("\n", "").replaceAll("\r", "");
tmpStr = tmpStr.replaceAll("\r", "");
reader.close();
assertEquals( assertEquals(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?><start fileID=\"02286_000_000\"><para id=\"1\">This is a test with .</para></start>", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<start fileID=\"02286_000_000\">"
+ "<para id=\"1\">This is a test with .</para>"
+ "</start>",
tmpStr); tmpStr);
}
} }
} }
...@@ -2,6 +2,7 @@ package net.sf.okapi.common.pipeline.integration; ...@@ -2,6 +2,7 @@ package net.sf.okapi.common.pipeline.integration;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Reader; import java.io.Reader;
...@@ -62,30 +63,26 @@ public class XsltTransformStep ...@@ -62,30 +63,26 @@ public class XsltTransformStep
ByteArrayOutputStream tempStream = new ByteArrayOutputStream(); ByteArrayOutputStream tempStream = new ByteArrayOutputStream();
// get the input xml and xslt streams