21
21
import java .io .File ;
22
22
import java .io .IOException ;
23
23
import java .io .InputStream ;
24
+ import org .apache .pdfbox .io .IOUtils ;
24
25
25
26
import org .apache .pdfbox .io .RandomAccessRead ;
26
27
import org .apache .pdfbox .io .RandomAccessReadBuffer ;
@@ -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,7 +58,7 @@ 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
/**
@@ -68,7 +69,29 @@ public TrueTypeCollection(InputStream stream) throws IOException
68
69
*/
69
70
TrueTypeCollection (RandomAccessRead randomAccessRead ) throws IOException
70
71
{
71
- this .stream = new RandomAccessReadDataStream (randomAccessRead );
72
+ this (randomAccessRead , false );
73
+ }
74
+
75
+ /**
76
+ * Creates a new TrueTypeCollection from a RandomAccessRead.
77
+ *
78
+ * @param randomAccessRead
79
+ * @param closeAfterReading {@code true} to close randomAccessRead
80
+ * @throws IOException If the font could not be parsed.
81
+ */
82
+ private TrueTypeCollection (RandomAccessRead randomAccessRead , boolean closeAfterReading ) throws IOException
83
+ {
84
+ try
85
+ {
86
+ this .stream = new RandomAccessReadDataStream (randomAccessRead );
87
+ }
88
+ finally
89
+ {
90
+ if (closeAfterReading )
91
+ {
92
+ IOUtils .closeQuietly (randomAccessRead );
93
+ }
94
+ }
72
95
73
96
// TTC header
74
97
String tag = stream .readTag ();
0 commit comments