2020package org .apache .fop .svg ;
2121
2222import java .io .ByteArrayInputStream ;
23- import java .io .File ;
24- import java .io .FileOutputStream ;
23+ import java .io .ByteArrayOutputStream ;
2524import java .io .IOException ;
26- import java .io .OutputStream ;
2725import java .util .HashMap ;
2826import java .util .Map ;
2927
30- import org .junit .Rule ;
3128import org .junit .Test ;
32- import org .junit .rules .TemporaryFolder ;
3329import static org .junit .Assert .assertEquals ;
3430
3531import org .apache .pdfbox .Loader ;
5248 */
5349public class BasicPDFTranscoderTestCase extends AbstractBasicTranscoderTest {
5450
55- @ Rule
56- public TemporaryFolder tempFolder = new TemporaryFolder ();
57-
5851 @ Override
5952 protected Transcoder createTranscoder () {
6053 return new PDFTranscoder ();
@@ -101,8 +94,7 @@ public void testFontSubstitution() throws ConfigurationException, IOException, T
10194 + "</svg>" ;
10295 TranscoderInput input = new TranscoderInput (new ByteArrayInputStream (svgFragment .getBytes ()));
10396
104- File outputFile = tempFolder .newFile ("output.pdf" );
105- OutputStream os = new FileOutputStream (outputFile );
97+ ByteArrayOutputStream os = new ByteArrayOutputStream ();
10698 TranscoderOutput output = new TranscoderOutput (os );
10799
108100 try {
@@ -111,20 +103,14 @@ public void testFontSubstitution() throws ConfigurationException, IOException, T
111103 os .close ();
112104 }
113105
114- PDDocument pdfDocument = null ;
115- try {
116- pdfDocument = Loader .loadPDF (outputFile );
106+ try (PDDocument pdfDocument = Loader .loadPDF (os .toByteArray ())) {
117107 FontExtractor fontExtractor = new FontExtractor ();
118108 fontExtractor .getText (pdfDocument );
119109 assertEquals ("Courier" , fontExtractor .getFontUsage ().get ("H" ));
120- } finally {
121- if (pdfDocument != null ) {
122- pdfDocument .close ();
123- }
124110 }
125111 }
126112
127- class FontExtractor extends PDFTextStripper {
113+ static class FontExtractor extends PDFTextStripper {
128114
129115 private Map <String , String > fontUsage = new HashMap <>();
130116
0 commit comments