1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-09-03 10:53:25 +02:00

new URL(string) replaced with new URI(string).toURL(), as deprecated in java-20

This commit is contained in:
soloturn
2023-06-12 00:27:18 +02:00
parent 9a2ee24ab0
commit 0b500354ca
3 changed files with 246 additions and 243 deletions

View File

@@ -2,6 +2,8 @@ package com.rarchives.ripme.ripper.rippers;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@@ -204,12 +206,12 @@ public class ListalRipper extends AbstractHTMLRipper {
String imageUrl = doc.getElementsByClass("pure-img").attr("src"); String imageUrl = doc.getElementsByClass("pure-img").attr("src");
if (imageUrl != "") { if (imageUrl != "") {
addURLToDownload(new URL(imageUrl), getPrefix(index), "", null, null, addURLToDownload(new URI(imageUrl).toURL(), getPrefix(index), "", null, null,
getImageName()); getImageName());
} else { } else {
LOGGER.error("Couldnt find image from url: " + url); LOGGER.error("Couldnt find image from url: " + url);
} }
} catch (IOException e) { } catch (IOException | URISyntaxException e) {
LOGGER.error("[!] Exception while downloading image: " + url, e); LOGGER.error("[!] Exception while downloading image: " + url, e);
} }
} }

View File

@@ -100,7 +100,7 @@ public class History {
public void fromFile(String filename) throws IOException { public void fromFile(String filename) throws IOException {
try (InputStream is = new FileInputStream(filename)) { try (InputStream is = new FileInputStream(filename)) {
String jsonString = IOUtils.toString(is); String jsonString = IOUtils.toString(is, "UTF-8");
JSONArray jsonArray = new JSONArray(jsonString); JSONArray jsonArray = new JSONArray(jsonString);
fromJSON(jsonArray); fromJSON(jsonArray);
} catch (JSONException e) { } catch (JSONException e) {
@@ -134,7 +134,7 @@ public class History {
public void toFile(String filename) throws IOException { public void toFile(String filename) throws IOException {
try (OutputStream os = new FileOutputStream(filename)) { try (OutputStream os = new FileOutputStream(filename)) {
IOUtils.write(toJSON().toString(2), os); IOUtils.write(toJSON().toString(2), os, "UTF-8");
} }
} }
} }

View File

@@ -4,7 +4,8 @@ import com.rarchives.ripme.ripper.AbstractRipper;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URI;
import java.net.URISyntaxException;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -12,20 +13,20 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
public class AbstractRipperTest { public class AbstractRipperTest {
@Test @Test
public void testGetFileName() throws IOException { public void testGetFileName() throws IOException, URISyntaxException {
String fileName = AbstractRipper.getFileName(new URL("http://www.tsumino.com/Image/Object?name=U1EieteEGwm6N1dGszqCpA%3D%3D"),null, "test", "test"); String fileName = AbstractRipper.getFileName(new URI("http://www.tsumino.com/Image/Object?name=U1EieteEGwm6N1dGszqCpA%3D%3D").toURL(),null, "test", "test");
assertEquals("test.test", fileName); assertEquals("test.test", fileName);
fileName = AbstractRipper.getFileName(new URL("http://www.tsumino.com/Image/Object?name=U1EieteEGwm6N1dGszqCpA%3D%3D"), null,"test", null); fileName = AbstractRipper.getFileName(new URI("http://www.tsumino.com/Image/Object?name=U1EieteEGwm6N1dGszqCpA%3D%3D").toURL(), null,"test", null);
assertEquals("test", fileName); assertEquals("test", fileName);
fileName = AbstractRipper.getFileName(new URL("http://www.tsumino.com/Image/Object?name=U1EieteEGwm6N1dGszqCpA%3D%3D"), null,null, null); fileName = AbstractRipper.getFileName(new URI("http://www.tsumino.com/Image/Object?name=U1EieteEGwm6N1dGszqCpA%3D%3D").toURL(), null,null, null);
assertEquals("Object", fileName); assertEquals("Object", fileName);
fileName = AbstractRipper.getFileName(new URL("http://www.test.com/file.png"), null,null, null); fileName = AbstractRipper.getFileName(new URI("http://www.test.com/file.png").toURL(), null,null, null);
assertEquals("file.png", fileName); assertEquals("file.png", fileName);
fileName = AbstractRipper.getFileName(new URL("http://www.test.com/file."), null,null, null); fileName = AbstractRipper.getFileName(new URI("http://www.test.com/file.").toURL(), null,null, null);
assertEquals("file.", fileName); assertEquals("file.", fileName);
} }