-
Notifications
You must be signed in to change notification settings - Fork 24
Make the temporary-file directory and in-memory buffer size configurable #728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
softvisionfd
wants to merge
2
commits into
veraPDF:integration
from
softvision-dev:configurable-temp-directory
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * This file is part of veraPDF Parser, a module of the veraPDF project. | ||
| * Copyright (c) 2015-2026, veraPDF Consortium <info@verapdf.org> | ||
| * All rights reserved. | ||
| * | ||
| * veraPDF Parser is free software: you can redistribute it and/or modify | ||
| * it under the terms of either: | ||
| * | ||
| * The GNU General public license GPLv3+. | ||
| * You should have received a copy of the GNU General Public License | ||
| * along with veraPDF Parser as the LICENSE.GPL file in the root of the source | ||
| * tree. If not, see http://www.gnu.org/licenses/ or | ||
| * https://www.gnu.org/licenses/gpl-3.0.en.html. | ||
| * | ||
| * The Mozilla Public License MPLv2+. | ||
| * You should have received a copy of the Mozilla Public License along with | ||
| * veraPDF Parser as the LICENSE.MPL file in the root of the source tree. | ||
| * If a copy of the MPL was not distributed with this file, you can obtain one at | ||
| * http://mozilla.org/MPL/2.0/. | ||
| */ | ||
| package org.verapdf.io; | ||
|
|
||
| import java.io.File; | ||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Central creation point for the temporary files that the parser writes while turning non-seekable | ||
| * input (embedded font programs, CMaps, decoded object streams, incremental-update output) into | ||
| * seekable data. | ||
| * | ||
| * <p>By default this behaves exactly like {@link File#createTempFile(String, String)} and writes into | ||
| * the JVM temporary directory ({@code java.io.tmpdir}). A caller that needs the temporary files in a | ||
| * specific directory - for example one directory per worker so files stay inside an isolated working | ||
| * area and can be removed deterministically - can configure a target directory. Two levels are offered: | ||
| * a process-wide default and a per-thread override that takes precedence. Both are optional; when | ||
| * neither is set the historical behaviour is preserved, so this change is backward compatible.</p> | ||
| * | ||
| * <p>The per-thread override is the natural fit for a server that validates one document per worker | ||
| * thread: set it before parsing, {@link #clearTempDirectory() clear} it afterwards.</p> | ||
| */ | ||
| public final class TempFileHandler { | ||
|
|
||
| private static volatile File defaultTempDirectory; | ||
|
|
||
| private static final ThreadLocal<File> TEMP_DIRECTORY = new ThreadLocal<>(); | ||
|
|
||
| private TempFileHandler() { | ||
| } | ||
|
|
||
| /** | ||
| * Sets the process-wide default directory for parser temporary files. {@code null} restores the | ||
| * JVM default ({@code java.io.tmpdir}). | ||
| * | ||
| * @param directory target directory, or {@code null} for the JVM default | ||
| */ | ||
| public static void setDefaultTempDirectory(File directory) { | ||
| defaultTempDirectory = directory; | ||
| } | ||
|
|
||
| /** | ||
| * @return the process-wide default directory, or {@code null} if none is configured | ||
| */ | ||
| public static File getDefaultTempDirectory() { | ||
| return defaultTempDirectory; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the temporary-file directory for the current thread only. It takes precedence over the | ||
| * process-wide default and should be cleared when the thread is done ({@link #clearTempDirectory()}). | ||
| * | ||
| * @param directory target directory for this thread, or {@code null} to fall back to the default | ||
| */ | ||
| public static void setTempDirectory(File directory) { | ||
| if (directory == null) { | ||
| TEMP_DIRECTORY.remove(); | ||
| } else { | ||
| TEMP_DIRECTORY.set(directory); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Removes the per-thread temporary-file directory, falling back to the process-wide default. | ||
| */ | ||
| public static void clearTempDirectory() { | ||
| TEMP_DIRECTORY.remove(); | ||
| } | ||
|
|
||
| /** | ||
| * @return the directory that will be used for new temporary files on the current thread: the | ||
| * per-thread override if set, otherwise the process-wide default, otherwise {@code null} (JVM default) | ||
| */ | ||
| public static File getTempDirectory() { | ||
| File perThread = TEMP_DIRECTORY.get(); | ||
| return perThread != null ? perThread : defaultTempDirectory; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a temporary file, honouring the configured directory. Equivalent to | ||
| * {@link File#createTempFile(String, String)} when no directory is configured. | ||
| * | ||
| * @param prefix file-name prefix, as for {@link File#createTempFile(String, String, File)} | ||
| * @param suffix file-name suffix, or {@code null} | ||
| * @return the newly created temporary file | ||
| * @throws IOException if the file could not be created | ||
| */ | ||
| public static File createTempFile(String prefix, String suffix) throws IOException { | ||
| File directory = getTempDirectory(); | ||
| return directory != null | ||
| ? File.createTempFile(prefix, suffix, directory) | ||
| : File.createTempFile(prefix, suffix); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win
Restore the opening Javadoc delimiter.
Line 50 starts Javadoc text outside a comment. Java cannot compile this file. Add
/**before the cap description so the existing*/closes the comment. The build checks report syntax errors at Line 50.🧰 Tools
🪛 GitHub Check: Checkout and Build (11)
[failure] 50-50:
';' expected
[failure] 50-50:
';' expected
[failure] 50-50:
';' expected
[failure] 50-50:
';' expected
[failure] 50-50:
';' expected
[failure] 50-50:
expected
[failure] 50-50:
';' expected
[failure] 50-50:
expected
[failure] 50-50:
';' expected
[failure] 50-50:
illegal start of type
🪛 GitHub Check: Checkout and Build (25)
[failure] 50-50:
';' expected
[failure] 50-50:
';' expected
[failure] 50-50:
';' expected
[failure] 50-50:
';' expected
[failure] 50-50:
';' expected
[failure] 50-50:
expected
[failure] 50-50:
';' expected
[failure] 50-50:
expected
[failure] 50-50:
';' expected
[failure] 50-50:
illegal start of type
🪛 PMD (7.27.0)
[High] 50-50: Parse Error: ParseException: Parse exception in file 'src/main/java/org/verapdf/io/SeekableInputStream.java' at line 50, column 6: Encountered "*".
Was expecting:
"}" ...
(Parse Error)
🤖 Prompt for AI Agents
Source: Linters/SAST tools