@@ -44,9 +44,13 @@ This file is part of the iText (R) project.
44
44
package com .itextpdf .io .font ;
45
45
46
46
import com .itextpdf .io .IOException ;
47
+ import com .itextpdf .io .source .IRandomAccessSource ;
48
+ import com .itextpdf .io .source .RandomAccessFileOrArray ;
49
+ import com .itextpdf .io .source .RandomAccessSourceFactory ;
47
50
import com .itextpdf .io .util .StreamUtil ;
48
51
49
52
import java .io .FileInputStream ;
53
+ import java .text .MessageFormat ;
50
54
import java .util .Set ;
51
55
52
56
/**
@@ -199,7 +203,7 @@ public static FontProgram createFont(String name, byte[] fontProgram, boolean ca
199
203
} else if (".ttf" .equals (fontFileExtension ) || ".otf" .equals (fontFileExtension ) || ".woff" .equals (fontFileExtension )) {
200
204
if (".woff" .equals (fontFileExtension )) {
201
205
if (fontProgram == null ) {
202
- fontProgram = StreamUtil . inputStreamToArray ( new FileInputStream ( name ) );
206
+ fontProgram = readBytesFromPath ( name );
203
207
}
204
208
try {
205
209
fontProgram = WoffConverter .convert (fontProgram );
@@ -485,4 +489,15 @@ private static FontCacheKey createFontCacheKey(String name, byte[] fontProgram)
485
489
public static void clearRegisteredFonts () { fontRegisterProvider .clearRegisteredFonts (); }
486
490
487
491
public static void clearRegisteredFontFamilies () { fontRegisterProvider .clearRegisteredFontFamilies (); }
492
+
493
+ private static byte [] readBytesFromPath (String path ) throws java .io .IOException {
494
+ RandomAccessFileOrArray raf = new RandomAccessFileOrArray (new RandomAccessSourceFactory ().createBestSource (path ));
495
+ int bufLen = (int ) raf .length ();
496
+ if (bufLen < raf .length ()) {
497
+ throw new IOException (MessageFormat .format ("Source data from \" {0}\" is bigger than byte array can hold." , path ));
498
+ }
499
+ byte [] buf = new byte [bufLen ];
500
+ raf .readFully (buf );
501
+ return buf ;
502
+ }
488
503
}
0 commit comments