try {
// save page to cache
ObjectOutputStream tempstream;
- String fname = "fop-page-" + page.getPageIndex() + ".ser";
- URI tempURI = tempBaseURI.resolve(fname);
+ String fname = "/fop-page-" + page.getPageIndex() + ".ser";
+ URI tempURI = URI.create(tempBaseURI + fname);
OutputStream outStream = renderer.getUserAgent().getResourceResolver().getOutputStream(tempURI);
tempstream = new ObjectOutputStream(new BufferedOutputStream(outStream));
try {
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
public class ConserveMemoryTestCase {
@Test
- public void testLink() throws TransformerException, SAXException {
- String fo = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n"
+ public void testLink() throws Throwable {
+ final String fo = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n"
+ " <fo:layout-master-set>\n"
+ " <fo:simple-page-master master-name=\"simple\" page-height=\"27.9cm\" page-width=\"21.6cm\">\n"
+ " <fo:region-body />\n"
+ " </fo:flow>\n"
+ " </fo:page-sequence>\n"
+ "</fo:root>";
- foToOutput(fo);
+
+ ExecutorService es = Executors.newCachedThreadPool();
+ final Throwable[] ex = new Throwable[1];
+ for (int i = 0; i < 5; i++) {
+ Runnable thread = new Runnable() {
+ public void run() {
+ try {
+ foToOutput(fo);
+ } catch (Throwable e) {
+ ex[0] = e;
+ }
+ }
+ };
+ es.execute(thread);
+ }
+ es.shutdown();
+ es.awaitTermination(1, TimeUnit.MINUTES);
+ if (ex[0] != null) {
+ throw ex[0];
+ }
}
private void foToOutput(String fo) throws SAXException, TransformerException {