// on Windows file paths that are longer than 260 characters cannot be opened
This commit is contained in:
parent
9b739b4f54
commit
0b5d9a3518
|
@ -42,8 +42,7 @@ public class MediaInfo implements Closeable {
|
|||
|
||||
String path = file.getCanonicalPath();
|
||||
|
||||
// on Mac files that contain accents cannot be opened via JNA WString file paths due to encoding differences so we use the buffer interface instead for these files
|
||||
if (Platform.isMac() && !US_ASCII.newEncoder().canEncode(path)) {
|
||||
if (preferOpenViaBuffer(path)) {
|
||||
try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
|
||||
if (openViaBuffer(raf)) {
|
||||
return this;
|
||||
|
@ -59,6 +58,18 @@ public class MediaInfo implements Closeable {
|
|||
throw new IOException("Failed to open media file: " + path);
|
||||
}
|
||||
|
||||
private boolean preferOpenViaBuffer(String path) {
|
||||
// on Windows file paths that are longer than 260 characters cannot be opened
|
||||
if (Platform.isWindows() && path.length() > 250)
|
||||
return true;
|
||||
|
||||
// on Mac files that contain accents cannot be opened via JNA WString file paths due to encoding differences so we use the buffer interface instead for these files
|
||||
if (Platform.isMac() && !US_ASCII.newEncoder().canEncode(path))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean openViaBuffer(RandomAccessFile f) throws IOException {
|
||||
byte[] buffer = new byte[4 * 1024 * 1024]; // use large buffer to reduce JNA calls
|
||||
int read = -1;
|
||||
|
|
Loading…
Reference in New Issue