diff options
author | Sven Gothel <[email protected]> | 2014-09-30 23:07:50 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2014-09-30 23:07:50 +0200 |
commit | bd24599b21f9787ac989e65b44dc1ba762162f22 (patch) | |
tree | 48bf52d4ebdd5e4172dd83a4d6d7f75f961c7574 /src/jogl/classes/jogamp/graph/font/JavaFontLoader.java | |
parent | f197d38d0ea31416645ac69cebb3f9b3544d903f (diff) |
Refine Graph/Font InputStream Capabilities (commit 628509b39ea7c16210315d191860511d6be4aa69)
FontFactory Remove:
- Font get(final URLConnection conn)
- Font get(final InputStream stream)
FontFactory Add:
- [1] Font get(final InputStream stream, final int streamLen, final boolean closeStream)
- Direct usage of font InputStream w/ determined length,
may instantiate BufferedInputStream in case given stream
doesn't support mark/reset!
- [2] Font get(final InputStream stream, final boolean closeStream)
- Copy font InputStream w/o determined length,
resulting in BufferedInputStream supporting mark/reset!
Security Related:
- Only perform priviledged code on determine InputStream,
_not_ when parsing the font stream itself!
- Hence PrivilegedAction only happens in FontFactory's
InputStream preparation.
Misc:
- Use Uri class
Diffstat (limited to 'src/jogl/classes/jogamp/graph/font/JavaFontLoader.java')
-rw-r--r-- | src/jogl/classes/jogamp/graph/font/JavaFontLoader.java | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java b/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java index 1bb2bb5f3..da651cca9 100644 --- a/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java +++ b/src/jogl/classes/jogamp/graph/font/JavaFontLoader.java @@ -27,8 +27,11 @@ */ package jogamp.graph.font; +import java.io.BufferedInputStream; import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.security.AccessController; import java.security.PrivilegedAction; @@ -89,6 +92,9 @@ public class JavaFontLoader implements FontSet { @Override public Font get(final int family, final int style) throws IOException { + if(null == javaFontPath) { + throw new GLException("java font path undefined"); + } Font font = (Font)fontMap.get( ( family << 8 ) | style ); if (font != null) { return font; @@ -139,20 +145,41 @@ public class JavaFontLoader implements FontSet { } Font abspath(final String fname, final int family, final int style) throws IOException { - if(null == javaFontPath) { - throw new GLException("java font path undefined"); - } - final String err = "Problem loading font "+fname+", file "+javaFontPath+fname ; - try { - final Font f = FontFactory.get( new File(javaFontPath+fname) ); + final Font f = abspathImpl(javaFontPath+fname, family, style); if(null != f) { - fontMap.put( ( family << 8 ) | style, f ); return f; } - throw new IOException (err); + throw new IOException (String.format("Problem loading font %s, file %s%s", fname, javaFontPath, fname)); } catch (final IOException ioe) { - throw new IOException(err, ioe); + throw new IOException(String.format("Problem loading font %s, file %s%s", fname, javaFontPath, fname), ioe); + } + } + private Font abspathImpl(final String fname, final int family, final int style) throws IOException { + final Exception[] privErr = { null }; + final int[] streamLen = { 0 }; + final InputStream stream = AccessController.doPrivileged(new PrivilegedAction<InputStream>() { + @Override + public InputStream run() { + try { + final File file = new File(fname); + streamLen[0] = (int) file.length(); + return new BufferedInputStream(new FileInputStream(file), streamLen[0]); + } catch (final Exception e) { + privErr[0] = e; + return null; + } + } } ); + if( null != privErr[0] ) { + throw new IOException(privErr[0]); + } + if(null != stream) { + final Font f= FontFactory.get ( stream, streamLen[0], true ) ; + if(null != f) { + fontMap.put( ( family << 8 ) | style, f ); + return f; + } } + return null; } } |