doesn't work if the output location contains a whitespace
elzoughby opened this issue · 7 comments
org.toilelibre.libe.curl.Curl$CurlException: java.util.concurrent.ExecutionException: org.toilelibre.libe.curl.Curl$Curl
Exception: java.lang.RuntimeException: Could not create the file. Does it already exist ?
at org.toilelibre.libe.curl.Curl.curl(Curl.java:37)
at LoadingController$1.call(LoadingController.java:78)
at LoadingController$1.call(LoadingController.java:42)
at javafx.concurrent.Task$TaskCallable.call(Task.java:1423)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.util.concurrent.ExecutionException: org.toilelibre.libe.curl.Curl$CurlException: java.lang.RuntimeExcept
ion: Could not create the file. Does it already exist ?
at java.util.concurrent.CompletableFuture.reportGet(Unknown Source)
at java.util.concurrent.CompletableFuture.get(Unknown Source)
at org.toilelibre.libe.curl.Curl.curl(Curl.java:35)
... 5 more
Caused by: org.toilelibre.libe.curl.Curl$CurlException: java.lang.RuntimeException: Could not create the file. Does it a
lready exist ?
at org.toilelibre.libe.curl.AfterResponse.createTheOutputFile(AfterResponse.java:54)
at org.toilelibre.libe.curl.AfterResponse.handle(AfterResponse.java:23)
at org.toilelibre.libe.curl.Curl.lambda$curlAsync$1(Curl.java:47)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(Unknown Source)
... 1 more
Caused by: java.lang.RuntimeException: Could not create the file. Does it already exist ?
... 5 more
Hello,
Thanks for that feedback,
I will try to test that scenario.
Hmm that is weird,
this unit test is green on my machine :
@Test
public void outputFileWithSpaces () {
File file = new File("target/classes/downloaded Curl With WhiteSpaces");
boolean fileDeleted = file.delete();
LOGGER.log(Level.FINE, "output file deleted : " + fileDeleted);
this.assertOk (this.curl ("-k -E src/test/resources/clients/libe/libe.pem -X GET -A 'toto' -H 'Accept: */*' -H 'Host: localhost' 'https://localhost:%d/public' -o 'target/classes/downloaded Curl With WhiteSpaces'"));
Assert.assertTrue (new File ("target/classes/downloaded Curl With WhiteSpaces").exists ());
}
Hmm,
I do not know why that exception happens, but here is my use of the library :
private static String appDataDirectory;
static {
// set nazel AppData directory path based on the user OS
if(System.getProperty("os.name").toLowerCase().contains("win"))
appDataDirectory = System.getenv("AppData").replaceAll("[/\\\\]$", "") +
System.getProperty("file.separator") + "nazel downloader";
else if(System.getProperty("os.name").toLowerCase().contains("mac"))
appDataDirectory = System.getProperty("user.home").replaceAll("[/\\\\]$", "") +
System.getProperty("file.separator") + "Library" + System.getProperty("file.separator") +
"Preferences" + System.getProperty("file.separator") + "nazel downloader";
else
appDataDirectory = System.getProperty("user.home").replaceAll("[/\\\\]$", "") +
System.getProperty("file.separator") + ".nazel Downloader";
}
// Then somewhere in a method
Curl.curl("-L http://yt-dl.org/downloads/latest/youtube-dl -o " + APP_DATA_DIRECTORY + System.getProperty("file.separator") + "youtube-dl.tmp");
I tested this code on windows and linux, but with the same error.
Am I wrong in somthing?
I have escaped from this error by using this workaround :
File tempFile = new File(APP_DATA_DIRECTORY + System.getProperty("file.separator") + "youtube-dl.tmp");
if(tempFile.exists())
tempFile.delete();
tempFile.getParentFile().mkdirs();
FileOutputStream fileOutputStream = new FileOutputStream(tempFile);
HttpResponse response = Curl.curl().lUpperCase().run("http://yt-dl.org/downloads/latest/youtube-dl");
response.getEntity().writeTo(fileOutputStream);
fileOutputStream.close();
Hello,
I think your forgot to surround the file name with simple quotes or double quotes.
" + APP_DATA_DIRECTORY + System.getProperty("file.separator") + "youtube-dl.tmp"
=>
/home/user/directory with space/youtube-dl.tmp (failing)
whereas
'" + APP_DATA_DIRECTORY + System.getProperty("file.separator") + "youtube-dl.tmp'"
=>
'/home/user/directory with space/youtube-dl.tmp' (working)
Don't hesitate to reopen that one if you need more help.
Ooh, you are right 👍
Thanks a lot.