When copying a file, jdk pushes it completely into memory. Code:
HttpURLConnection conn = null; URL urlSt = new URL(urlString); conn = (HttpURLConnection) urlSt.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestProperty("Content-Type", "application/octet-stream"); conn.setRequestMethod("PUT"); conn.setRequestProperty("Content-Length", Long.toString(fileSize)); OutputStream out = conn.getOutputStream(); InputStream in = new FileInputStream(fileName); byte[] buf = new byte[1024]; int len = 0; while ((len = in.read(buf)) >0) { out.write(buf, 0, len); } in.close(); out.close(); On the Internet, I found some solutions, but they did not help, but just started to throw out new ones that correspond to them.
conn.setFixedLengthStreamingMode(); conn.setChunkedStreamingMode(); EXAMPLE: when using the second block I get this
java.lang.IllegalStateException: Fixed length streaming mode set if a
fileSize=1,7Гб setFixedLengthStreamingMode(fileSize) setChunkedStreamingMode(1024) When testing, we used the following data:
- 800MB - RAM: 1024MB = Java heap space;
- 970MB - RAM: 2024 = OK;
- 1.7GB - RAM: 6144Mb = OK;
- 4.1GB - RAM: 6144Mb = Java heap space;
QUESTION: how to send a large file and do not get the check.