Skip to content
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

Avoid temporary file when loading cached Json-LD schema document #3284

Closed
ndr-brt opened this issue Jul 7, 2023 · 2 comments · Fixed by #3290
Closed

Avoid temporary file when loading cached Json-LD schema document #3284

ndr-brt opened this issue Jul 7, 2023 · 2 comments · Fixed by #3290
Assignees
Labels
enhancement New feature or request refactoring Cleaning up code and dependencies

Comments

@ndr-brt
Copy link
Member

ndr-brt commented Jul 7, 2023

Feature Request

Currently to load a cached document for the jsonld service, we copy the file from the classpath to a temporary place:

private Result<File> getResourceFile(String name) {
try (var stream = getClass().getClassLoader().getResourceAsStream(name)) {
if (stream == null) {
return Result.failure(format("Cannot find resource %s", name));
}
var filename = Path.of(name).getFileName().toString();
var parts = filename.split("\\.");
var tempFile = Files.createTempFile(parts[0], "." + parts[1]);
Files.copy(stream, tempFile, REPLACE_EXISTING);
return Result.success(tempFile.toFile());
} catch (Exception e) {
return Result.failure(format("Cannot read resource %s: ", name));
}
}

this could be avoided passing the URI directly

Which Areas Would Be Affected?

json-ld service

Why Is the Feature Desired?

simplification

ref @wolf4ood

@ndr-brt ndr-brt added enhancement New feature or request refactoring Cleaning up code and dependencies labels Jul 7, 2023
@bscholtes1A
Copy link
Contributor

This means that in tests going through this code we will fetch a file from an URL?

@ndr-brt
Copy link
Member Author

ndr-brt commented Jul 10, 2023

This means that in tests going through this code we will fetch a file from an URL?

no, the cache behavior will continue to be the same, but currently (as shown in the code fragment in the issue description) to load the cached document, a temporary file is created, but it is an unnecessary step that could be avoided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request refactoring Cleaning up code and dependencies
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants