2222import java .io .IOException ;
2323import java .io .InputStream ;
2424
25+ import org .apache .pdfbox .io .IOUtils ;
2526import org .apache .pdfbox .io .RandomAccessRead ;
2627import org .apache .pdfbox .io .RandomAccessReadBuffer ;
2728import org .apache .pdfbox .io .RandomAccessReadBufferedFile ;
@@ -46,7 +47,7 @@ public class TrueTypeCollection implements Closeable
4647 */
4748 public TrueTypeCollection (File file ) throws IOException
4849 {
49- this (new RandomAccessReadBufferedFile (file ));
50+ this (new RandomAccessReadBufferedFile (file ), true );
5051 }
5152
5253 /**
@@ -57,18 +58,29 @@ public TrueTypeCollection(File file) throws IOException
5758 */
5859 public TrueTypeCollection (InputStream stream ) throws IOException
5960 {
60- this (new RandomAccessReadBuffer (stream ));
61+ this (new RandomAccessReadBuffer (stream ), false );
6162 }
6263
6364 /**
6465 * Creates a new TrueTypeCollection from a RandomAccessRead.
6566 *
66- * @param randomAccessRead
67+ * @param randomAccessRead
68+ * @param closeAfterReading {@code true} to close randomAccessRead
6769 * @throws IOException If the font could not be parsed.
6870 */
69- TrueTypeCollection (RandomAccessRead randomAccessRead ) throws IOException
71+ private TrueTypeCollection (RandomAccessRead randomAccessRead , boolean closeAfterReading ) throws IOException
7072 {
71- this .stream = new RandomAccessReadDataStream (randomAccessRead );
73+ try
74+ {
75+ this .stream = new RandomAccessReadDataStream (randomAccessRead );
76+ }
77+ finally
78+ {
79+ if (closeAfterReading )
80+ {
81+ IOUtils .closeQuietly (randomAccessRead );
82+ }
83+ }
7284
7385 // TTC header
7486 String tag = stream .readTag ();
0 commit comments