我正在尝试使用Apache Commons IO从Jenkins下载一个fat jar(54MB)。代码方面,我认为我正在做正确的事情,但unexteptedly,下载的文件只有4.5MB。我的代码:
File dumpFile = new File(local_file_location); FileUtils.copyURLToFile(new URL(remoteURL), dumpFile, 300000, 300000);
字符串有什么建议吗?我错过了什么选择吗?
li9yvcax1#
我把它固定成这样:
private File downloadFromJenkins(String stringUrl) throws IOException { String[] jarParts = stringUrl.split("/"); String jarDump = Util.addTrailingSlash(config.getJarsTmpStorage()) + jarParts[jarParts.length - 1]; File dumpFile = new File(jarDump); logger.info("Downloading jar {} \n to: {}", stringUrl, jarDump); URL website = new URL(stringUrl); URLConnection connection = website.openConnection(); ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream()); FileOutputStream fos = new FileOutputStream(dumpFile); long expectedSize = connection.getContentLength(); logger.info("Expected size: {}", expectedSize); long transferedSize = 0L; while (transferedSize < expectedSize) { transferedSize += fos.getChannel().transferFrom(rbc, transferedSize, 1 << 24); logger.info( "{} bytes received", transferedSize); } fos.close(); return dumpFile; }
字符串
1条答案
按热度按时间li9yvcax1#
我把它固定成这样:
字符串