Upload/Download 大文件,Apache Commons 4.5.5 Java 11

Upload/Download big file with Apache Commons 4.5.5 with Java 11

我有一个处理大文件(下载、上传)的应用程序。 我正在使用 apache-commons 来处理 http 传输。 问题是本地下载速度快了 100。但是,一旦部署了代码,文件下载速度就会变得太慢。 代码太简单了;

int lenghtBytes = 1024 * 1024;
File outFile = this.file.getDossier ();
out = new FileOutputStream (outFile);
this.panel.jProgressBarTransfert.setMaximum (100);
byte [] buffer = new byte [lenghtBytes];
int l;
long bitTransfered = 0;

while ((l = in.read (buffer, 0, buffer.length))! = -1) {
out.write (buffer, 0, l); // We write on the disc.
bitTransfered + = l; // Update the number of bits transferred.
this.update (bitTransfered, httpResponse.getEntity (). getContentLength ());
}
in.close ();

在本地:当我将 lenghtBytes 设置为 1024 * 1024 时,下载速度立即生效。
关于生产:如果 1024 或 1024 * 1024

没有变化

你有什么想法吗?

传递客户端可用的最大字节数(配置带宽);

HttpURLConnection httpConn  = (HttpURLConnection) url.openConnection();             httpConn.setChunkedStreamingMode(this.BufferAdapterBandwidth(url) / 100 );     

private int BufferAdapterBandwidth(String string) 抛出 IOException { // TODO 自动生成的方法存根

    HttpURLConnection httpConn2 = (HttpURLConnection) new URL(string.replace("https", "http")).openConnection();   
    BufferedInputStream streamBW =  new BufferedInputStream(httpConn2.getInputStream()); 
    AppletAWS.println("Nombre de bytes max qu'ont peut avoir :" +  ( streamBW.available() == 0 ? 1024*100   :   streamBW.available() )  ); 
    return  streamBW.available() == 0 ? 1024*100   :   streamBW.available()   ;
}

它适合我!