Skip to content

Commit

Permalink
'#1861: use workaround just if needed, convert relative path to absolute
Browse files Browse the repository at this point in the history
  • Loading branch information
lfcnassif committed Sep 21, 2023
1 parent 264a33c commit 4fd4ace
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions iped-utils/src/main/java/iped/utils/FileInputStreamFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,36 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.nio.file.Paths;

import iped.io.SeekableInputStream;

public class FileInputStreamFactory extends SeekableInputStreamFactory {

private static final boolean IS_WINDOWS = System.getProperty("os.name").toLowerCase().startsWith("windows");

public FileInputStreamFactory(Path dataSource) {
super(dataSource.toUri());
}

public File getFile(String subPath) {
if (System.getProperty("os.name").toLowerCase().startsWith("windows")) {
//this is a workaround to support cases where there are folders with trailing spaces on the name
return new File("\\\\?\\" + new File(subPath).getAbsolutePath());
} else {
return new File(subPath);
Path source = Paths.get(this.dataSource);
try {
return source.resolve(subPath).toFile();

} catch (InvalidPathException e) {
File file = new File(subPath);
if (!file.isAbsolute()) {
file = new File(source.toFile(), subPath);
}
if (IS_WINDOWS) {
//this is a workaround to support cases where there are folders with trailing spaces on the name
return new File("\\\\?\\" + file.getAbsolutePath());
} else {
return file;
}
}
}

Expand Down

0 comments on commit 4fd4ace

Please sign in to comment.