You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2024/12/05 10:44:29 UTC
svn commit: r1922317 - /pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java
Author: tilman
Date: Thu Dec 5 10:44:29 2024
New Revision: 1922317
URL: http://svn.apache.org/viewvc?rev=1922317&view=rev
Log:
PDFBOX-5913: don't spawn a cmd / command subprocess to get windir, as suggested by Jakob Heher
Modified:
pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java
Modified: pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java?rev=1922317&r1=1922316&r2=1922317&view=diff
==============================================================================
--- pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java (original)
+++ pdfbox/branches/3.0/fontbox/src/main/java/org/apache/fontbox/util/autodetect/WindowsFontDirFinder.java Thu Dec 5 10:44:29 2024
@@ -17,11 +17,7 @@
package org.apache.fontbox.util.autodetect;
-import java.io.BufferedReader;
import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.commons.logging.Log;
@@ -38,32 +34,6 @@ public class WindowsFontDirFinder implem
private static final Log LOG = LogFactory.getLog(WindowsFontDirFinder.class);
/**
- * Attempts to read windir environment variable on windows (disclaimer: This is a bit dirty but seems to work
- * nicely).
- */
- private String getWinDir(String osName) throws IOException
- {
- Process process;
- Runtime runtime = Runtime.getRuntime();
- String cmd;
- if (osName.startsWith("Windows 9"))
- {
- cmd = "command.com";
- }
- else
- {
- cmd = "cmd.exe";
- }
- String[] cmdArray = { cmd, "/c", "echo", "%windir%" };
- process = runtime.exec(cmdArray);
- try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
- process.getInputStream(), StandardCharsets.ISO_8859_1)))
- {
- return bufferedReader.readLine();
- }
- }
-
- /**
* {@inheritDoc}
*
* @return a list of detected font files
@@ -87,9 +57,9 @@ public class WindowsFontDirFinder implem
{
try
{
- windir = getWinDir(osName);
+ windir = System.getenv("windir");
}
- catch (IOException | SecurityException e)
+ catch (SecurityException e)
{
LOG.debug("Couldn't get Windows font directories - ignoring", e);
// should continue if this fails