22
22
import java .io .IOException ;
23
23
import java .io .InputStream ;
24
24
25
+ import org .apache .pdfbox .io .IOUtils ;
25
26
import org .apache .pdfbox .io .RandomAccessRead ;
26
27
import org .apache .pdfbox .io .RandomAccessReadBuffer ;
27
28
import org .apache .pdfbox .io .RandomAccessReadBufferedFile ;
@@ -46,7 +47,7 @@ public class TrueTypeCollection implements Closeable
46
47
*/
47
48
public TrueTypeCollection (File file ) throws IOException
48
49
{
49
- this (new RandomAccessReadBufferedFile (file ));
50
+ this (new RandomAccessReadBufferedFile (file ), true );
50
51
}
51
52
52
53
/**
@@ -57,18 +58,29 @@ public TrueTypeCollection(File file) throws IOException
57
58
*/
58
59
public TrueTypeCollection (InputStream stream ) throws IOException
59
60
{
60
- this (new RandomAccessReadBuffer (stream ));
61
+ this (new RandomAccessReadBuffer (stream ), false );
61
62
}
62
63
63
64
/**
64
65
* Creates a new TrueTypeCollection from a RandomAccessRead.
65
66
*
66
- * @param randomAccessRead
67
+ * @param randomAccessRead
68
+ * @param closeAfterReading {@code true} to close randomAccessRead
67
69
* @throws IOException If the font could not be parsed.
68
70
*/
69
- TrueTypeCollection (RandomAccessRead randomAccessRead ) throws IOException
71
+ private TrueTypeCollection (RandomAccessRead randomAccessRead , boolean closeAfterReading ) throws IOException
70
72
{
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
+ }
72
84
73
85
// TTC header
74
86
String tag = stream .readTag ();
0 commit comments