使用apache FileUtils从Jenkins安装中下载大文件(54MB)仅下载9%

sc4hvdpw  于 12个月前  发布在  Jenkins
关注(0)|答案(1)|浏览(157)

我正在尝试使用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);

字符串
有什么建议吗?我错过了什么选择吗?

li9yvcax

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;
  }

字符串

相关问题