mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-30 17:20:20 +02:00
shortenSaveAsWindows now uses java.nio
This commit is contained in:
@@ -5,6 +5,7 @@ import java.net.HttpURLConnection;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@@ -237,7 +238,7 @@ class DownloadFileThread extends Thread {
|
||||
} else if (saveAs.getAbsolutePath().length() > 259 && Utils.isWindows()) {
|
||||
// This if is for when the file path has gone above 260 chars which windows does
|
||||
// not allow
|
||||
fos = new FileOutputStream(
|
||||
fos = Files.newOutputStream(
|
||||
Utils.shortenSaveAsWindows(saveAs.getParentFile().getPath(), saveAs.getName()));
|
||||
}
|
||||
}
|
||||
|
@@ -891,7 +891,7 @@ public class Utils {
|
||||
return fileNameToSan.replaceAll("[\\\\/:*?\"<>|]", "_");
|
||||
}
|
||||
|
||||
public static File shortenSaveAsWindows(String ripsDirPath, String fileName) throws FileNotFoundException {
|
||||
public static Path shortenSaveAsWindows(String ripsDirPath, String fileName) throws FileNotFoundException {
|
||||
LOGGER.error("The filename " + fileName + " is to long to be saved on this file system.");
|
||||
LOGGER.info("Shortening filename");
|
||||
String fullPath = ripsDirPath + File.separator + fileName;
|
||||
@@ -909,7 +909,7 @@ public class Utils {
|
||||
fullPath = fullPath.substring(0, 259 - pathLength - fileExt.length() + 1) + "." + fileExt;
|
||||
LOGGER.info(fullPath);
|
||||
LOGGER.info(fullPath.length());
|
||||
return new File(fullPath);
|
||||
return Paths.get(fullPath);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,7 +1,8 @@
|
||||
package com.rarchives.ripme.tst;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.rarchives.ripme.utils.Utils;
|
||||
@@ -60,8 +61,8 @@ public class UtilsTest {
|
||||
public void testShortenFileNameWindows() throws FileNotFoundException {
|
||||
String filename = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.png";
|
||||
// Test filename shortening for windows
|
||||
File f = Utils.shortenSaveAsWindows("D:/rips/test/reddit/deep", filename);
|
||||
Assertions.assertEquals(new File(
|
||||
Path f = Utils.shortenSaveAsWindows("D:/rips/test/reddit/deep", filename);
|
||||
Assertions.assertEquals(Paths.get(
|
||||
"D:/rips/test/reddit/deep/ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff.png"),
|
||||
f);
|
||||
}
|
||||
|
Reference in New Issue
Block a user