Skip to content
Snippets Groups Projects
Commit da3fdd77 authored by jez04's avatar jez04
Browse files

fix: creating URL class

parent ae6eb333
Branches
No related merge requests found
......@@ -6,6 +6,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
......@@ -79,7 +81,7 @@ public class CopyTests {
}
private static void download(String urlString, Path destPath, boolean unzip, int cutoffParrent) {
try (InputStream inputStream = new URL(urlString).openStream()) {
try (InputStream inputStream = new URI(urlString).toURL().openStream()) {
if (unzip) {
destPath.toFile().mkdirs();
extractZipStream(inputStream, destPath, cutoffParrent);
......@@ -94,6 +96,8 @@ public class CopyTests {
log.log(Level.SEVERE, "Cannot connect to git", ex);
} catch (IOException ex) {
log.log(Level.SEVERE, "Cannot douwnload and extract multi project evaluator", ex);
} catch (URISyntaxException ex) {
log.log(Level.SEVERE, "Cannot parse URL", ex);
}
}
......
......@@ -6,6 +6,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
......@@ -69,7 +71,7 @@ public class Download {
}
private static void download(String urlString, Path destPath, boolean unzip, int cutoffParrent) {
try (InputStream inputStream = new URL(urlString).openStream()) {
try (InputStream inputStream = new URI(urlString).toURL().openStream()) {
if (unzip) {
destPath.toFile().mkdirs();
extractZipStream(inputStream, destPath, cutoffParrent);
......@@ -84,6 +86,8 @@ public class Download {
log.log(Level.SEVERE, "Cannot connect to git", ex);
} catch (IOException ex) {
log.log(Level.SEVERE, "Cannot douwnload and extract multi project evaluator", ex);
} catch (URISyntaxException ex) {
log.log(Level.SEVERE, "Cannot parse URL", ex);
}
}
......
......@@ -7,6 +7,8 @@ import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.channels.Channel;
import java.nio.channels.Channels;
......@@ -57,7 +59,8 @@ import org.xml.sax.SAXException;
public class FixDirStructure {
private static Logger log = java.util.logging.Logger.getLogger(FixDirStructure.class.getName());
public static final List<String> skipNames = List.of("target", ".settings", ".project", ".classpath", ".kelvin-utils");
public static final List<String> skipNames = List.of("target", ".settings", ".project", ".classpath",
".kelvin-utils");
public static final String TAR_GZ_PATTERN = ".*\\.tar\\.gz";
public static void main(String[] args) {
......@@ -167,10 +170,12 @@ public class FixDirStructure {
}
private static void downloadAndExpandMultiprojedctEvaluator(Path path) {
try (InputStream inputStream = new URL(
"https://gitlab.vsb.cz/jez04-vyuka/eval-multiproject/-/archive/main/eval-multiproject-main.zip")
try (InputStream inputStream = new URI(
"https://gitlab.vsb.cz/jez04-vyuka/eval-multiproject/-/archive/main/eval-multiproject-main.zip").toURL()
.openStream()) {
extractZipStream(inputStream, path, 1);
} catch (URISyntaxException ex) {
log.log(Level.SEVERE, "Cannot parse URL", ex);
} catch (MalformedURLException ex) {
log.log(Level.SEVERE, "Cannot connect to git", ex);
} catch (IOException ex) {
......@@ -270,7 +275,7 @@ public class FixDirStructure {
throws FileNotFoundException, IOException {
extractZipStream(zipInputStream, destDir, 0);
}
private static void extractZipStream(InputStream zipInputStream, Path destDir, int cutoffParent)
throws FileNotFoundException, IOException {
ZipInputStream zipIn = new ZipInputStream(zipInputStream);
......@@ -278,9 +283,9 @@ public class FixDirStructure {
// iterates over entries in the zip file
while (entry != null) {
Path entryPath = Paths.get(entry.getName());
if(entry.isDirectory() && entryPath.getNameCount() <= cutoffParent) {
if (entry.isDirectory() && entryPath.getNameCount() <= cutoffParent) {
entryPath = Paths.get("");
} else if(!entry.isDirectory() && entryPath.getNameCount() <= cutoffParent) {
} else if (!entry.isDirectory() && entryPath.getNameCount() <= cutoffParent) {
entryPath = entryPath.getFileName();
} else {
entryPath = entryPath.subpath(cutoffParent, entryPath.getNameCount());
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment