Created
August 22, 2022 10:22
-
-
Save maxandersen/f7e79686ec085b15c43f1305249e16f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env jbang "$0" "$@" ; exit $? | |
import static java.lang.System.*; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.URI; | |
import java.net.http.HttpClient; | |
import java.net.http.HttpRequest; | |
import java.net.http.HttpResponse; | |
import java.nio.charset.StandardCharsets; | |
public class fetch { | |
private static final String URL = "https://%[email protected]/gsmet/github-action-playground/io/github/gsmet/github-action-playground/1.0.0-SNAPSHOT/github-action-playground-1.0.0-20220722.093742-12.jar"; | |
public static void main(String... args) throws IOException, InterruptedException { | |
if (args.length != 1) { | |
out.println("Usage: fetch <github PAT token with read-packages>"); | |
return; | |
} | |
String url = String.format(URL, args[0]); | |
HttpClient httpClient = HttpClient.newHttpClient(); | |
HttpRequest request = HttpRequest.newBuilder() | |
.uri(URI.create(url)) | |
.build(); | |
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); | |
System.out.println("java: " + response); | |
String command = "curl " + url; | |
try (InputStream stream = Runtime.getRuntime().exec(command).getInputStream()) { | |
String curlresponse = new String(stream.readAllBytes(), StandardCharsets.UTF_8); | |
System.out.println("curl: " + curlresponse); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment