Skip to content

Commit

Permalink
throw error if expectged file is not found in folder
Browse files Browse the repository at this point in the history
  • Loading branch information
connoratrug committed Oct 24, 2024
1 parent ae22fdb commit dbd14c1
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,16 @@ public Collection<String> getTableNames() {

@Override
public BinaryFileWrapper getBinaryFileWrapper(String name) {

Optional<String> fileName =
storefiles.stream().filter(f -> f.startsWith(name + ".")).findFirst();

try {
String fileName =
storefiles.stream().filter(f -> f.startsWith(name + ".")).findFirst().orElseThrow();
byte[] bytes;
try (InputStream stream =
getClass().getResourceAsStream(directoryPath + "/_files/" + fileName.orElseThrow())) {
getClass().getResourceAsStream(directoryPath + "/_files/" + fileName)) {
bytes = Objects.requireNonNull(stream).readAllBytes();
}
String mimetype = URLConnection.getFileNameMap().getContentTypeFor(fileName.get());
return new BinaryFileWrapper(mimetype, fileName.get(), bytes);
String mimetype = URLConnection.getFileNameMap().getContentTypeFor(fileName);
return new BinaryFileWrapper(mimetype, fileName, bytes);

} catch (Exception ioe) {
throw new MolgenisException("Import '" + name + "' failed: " + ioe.getMessage(), ioe);
Expand Down

0 comments on commit dbd14c1

Please sign in to comment.