|
5 | 5 | import java.io.IOException;
|
6 | 6 | import java.io.InputStream;
|
7 | 7 | import java.net.URL;
|
| 8 | +import java.net.URLConnection; |
8 | 9 | import java.nio.channels.Channels;
|
9 | 10 | import java.nio.channels.FileChannel;
|
10 | 11 | import java.nio.channels.ReadableByteChannel;
|
|
28 | 29 | import java.util.zip.ZipInputStream;
|
29 | 30 | import java.util.zip.ZipOutputStream;
|
30 | 31 |
|
| 32 | +import org.mcphackers.mcp.MCP; |
| 33 | + |
31 | 34 | public abstract class FileUtil {
|
32 | 35 |
|
33 | 36 | public static void delete(Path path) throws IOException {
|
@@ -128,13 +131,19 @@ public static void downloadFile(String url, Path output) throws IOException {
|
128 | 131 | }
|
129 | 132 |
|
130 | 133 | public static void downloadFile(URL url, Path output) throws IOException {
|
131 |
| - ReadableByteChannel channel = Channels.newChannel(url.openStream()); |
| 134 | + ReadableByteChannel channel = Channels.newChannel(openURLStream(url)); |
132 | 135 | try (FileOutputStream stream = new FileOutputStream(output.toAbsolutePath().toString())) {
|
133 | 136 | FileChannel fileChannel = stream.getChannel();
|
134 | 137 | fileChannel.transferFrom(channel, 0, Long.MAX_VALUE);
|
135 | 138 | }
|
136 | 139 | }
|
137 | 140 |
|
| 141 | + public static InputStream openURLStream(URL url) throws IOException { |
| 142 | + URLConnection connection = url.openConnection(); |
| 143 | + connection.setRequestProperty("User-Agent", "RetroMCP/" + MCP.VERSION); |
| 144 | + return connection.getInputStream(); |
| 145 | + } |
| 146 | + |
138 | 147 | public static void deleteDirectoryIfExists(Path path) throws IOException {
|
139 | 148 | if (Files.isDirectory(path)) {
|
140 | 149 | deleteDirectory(path);
|
|
0 commit comments