You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2018/03/11 22:02:24 UTC

svn commit: r1826470 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java

Author: msahyoun
Date: Sun Mar 11 22:02:23 2018
New Revision: 1826470

URL: http://svn.apache.org/viewvc?rev=1826470&view=rev
Log:
PDFBOX-4071: handle SecurityException for FileWriter too

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java?rev=1826470&r1=1826469&r2=1826470&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/FileSystemFontProvider.java Sun Mar 11 22:02:23 2018
@@ -293,70 +293,71 @@ final class FileSystemFontProvider exten
         try
         {
             file = getDiskCacheFile();
-        }
-        catch (SecurityException e)
-        {
-            LOG.debug("Couldn't create writer for font cache file", e);
-            return;
-        }
 
-        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file)))
-        {
-            for (FSFontInfo fontInfo : fontInfoList)
+            try (BufferedWriter writer = new BufferedWriter(new FileWriter(file)))
             {
-                writer.write(fontInfo.postScriptName.trim());
-                writer.write("|");
-                writer.write(fontInfo.format.toString());
-                writer.write("|");
-                if (fontInfo.cidSystemInfo != null)
-                {
-                    writer.write(fontInfo.cidSystemInfo.getRegistry() + '-' +
-                                 fontInfo.cidSystemInfo.getOrdering() + '-' +
-                                 fontInfo.cidSystemInfo.getSupplement());
-                }
-                writer.write("|");
-                if (fontInfo.usWeightClass > -1)
-                {
-                    writer.write(Integer.toHexString(fontInfo.usWeightClass));
-                }
-                writer.write("|");
-                if (fontInfo.sFamilyClass > -1)
-                {
-                    writer.write(Integer.toHexString(fontInfo.sFamilyClass));
-                }
-                writer.write("|");
-                writer.write(Integer.toHexString(fontInfo.ulCodePageRange1));
-                writer.write("|");
-                writer.write(Integer.toHexString(fontInfo.ulCodePageRange2));
-                writer.write("|");
-                if (fontInfo.macStyle > -1)
-                {
-                    writer.write(Integer.toHexString(fontInfo.macStyle));
-                }
-                writer.write("|");
-                if (fontInfo.panose != null)
+                for (FSFontInfo fontInfo : fontInfoList)
                 {
-                    byte[] bytes = fontInfo.panose.getBytes();
-                    for (int i = 0; i < 10; i ++)
+                    writer.write(fontInfo.postScriptName.trim());
+                    writer.write("|");
+                    writer.write(fontInfo.format.toString());
+                    writer.write("|");
+                    if (fontInfo.cidSystemInfo != null)
                     {
-                        String str = Integer.toHexString(bytes[i]);
-                        if (str.length() == 1)
+                        writer.write(fontInfo.cidSystemInfo.getRegistry() + '-' +
+                                     fontInfo.cidSystemInfo.getOrdering() + '-' +
+                                     fontInfo.cidSystemInfo.getSupplement());
+                    }
+                    writer.write("|");
+                    if (fontInfo.usWeightClass > -1)
+                    {
+                        writer.write(Integer.toHexString(fontInfo.usWeightClass));
+                    }
+                    writer.write("|");
+                    if (fontInfo.sFamilyClass > -1)
+                    {
+                        writer.write(Integer.toHexString(fontInfo.sFamilyClass));
+                    }
+                    writer.write("|");
+                    writer.write(Integer.toHexString(fontInfo.ulCodePageRange1));
+                    writer.write("|");
+                    writer.write(Integer.toHexString(fontInfo.ulCodePageRange2));
+                    writer.write("|");
+                    if (fontInfo.macStyle > -1)
+                    {
+                        writer.write(Integer.toHexString(fontInfo.macStyle));
+                    }
+                    writer.write("|");
+                    if (fontInfo.panose != null)
+                    {
+                        byte[] bytes = fontInfo.panose.getBytes();
+                        for (int i = 0; i < 10; i ++)
                         {
-                            writer.write('0');
+                            String str = Integer.toHexString(bytes[i]);
+                            if (str.length() == 1)
+                            {
+                                writer.write('0');
+                            }
+                            writer.write(str);
                         }
-                        writer.write(str);
                     }
+                    writer.write("|");
+                    writer.write(fontInfo.file.getAbsolutePath());
+                    writer.newLine();
                 }
-                writer.write("|");
-                writer.write(fontInfo.file.getAbsolutePath());
-                writer.newLine();
             }
+            catch (IOException e)
+            {
+                LOG.warn("Could not write to font cache", e);
+                LOG.warn("Installed fonts information will have to be reloaded for each start");
+                LOG.warn("You can assign a directory to the 'pdfbox.fontcache' property");
+            }
+
         }
-        catch (IOException e)
+        catch (SecurityException e)
         {
-            LOG.warn("Could not write to font cache", e);
-            LOG.warn("Installed fonts information will have to be reloaded for each start");
-            LOG.warn("You can assign a directory to the 'pdfbox.fontcache' property");
+            LOG.debug("Couldn't create writer for font cache file", e);
+            return;
         }
     }