Skip to content

Commit

Permalink
Merge pull request #1087 from soot-oss/downloadjarpathinputlocation
Browse files Browse the repository at this point in the history
changed the storing logic in download jar input location
  • Loading branch information
stschott authored Sep 26, 2024
2 parents 2d7ee55 + bdf9950 commit 13a7637
Showing 1 changed file with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Collection;
import java.util.List;
import sootup.core.model.SourceType;
Expand Down Expand Up @@ -36,8 +37,6 @@

public class DownloadJarAnalysisInputLocation extends ArchiveBasedAnalysisInputLocation {

private static final int BUFFER_SIZE = 1024;

public DownloadJarAnalysisInputLocation(
String downloadURL, List<BodyInterceptor> bodyInterceptors, Collection<Path> ignoredPaths) {
super(
Expand All @@ -56,13 +55,9 @@ private static Path downloadAndConstructPath(String downloadURL) {
if (responseCode != HttpURLConnection.HTTP_OK) {
throw new IOException("HTTP request failed with response code " + responseCode);
}
try (InputStream inputStream = new BufferedInputStream(connection.getInputStream());
OutputStream outputStream = Files.newOutputStream(Paths.get(file.getAbsolutePath()))) {
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = inputStream.read(buffer, 0, BUFFER_SIZE)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
try (InputStream inputStream = connection.getInputStream()) {
Path outputPath = Paths.get(file.getAbsolutePath());
Files.copy(inputStream, outputPath, StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down

0 comments on commit 13a7637

Please sign in to comment.