protected void transferFileToRemoteLive( File file, long stagingRequestId, HttpPrincipal httpPrincipal) throws Exception { byte[] bytes = new byte[PropsValues.STAGING_REMOTE_TRANSFER_BUFFER_SIZE]; int i = 0; int j = 0; String numberFormat = String.format("%%0%dd", String.valueOf((int) (file.length() / bytes.length)).length() + 1); FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); while ((i = fileInputStream.read(bytes)) >= 0) { String fileName = file.getName() + String.format(numberFormat, j++); if (i < PropsValues.STAGING_REMOTE_TRANSFER_BUFFER_SIZE) { byte[] tempBytes = new byte[i]; System.arraycopy(bytes, 0, tempBytes, 0, i); StagingServiceHttp.updateStagingRequest( httpPrincipal, stagingRequestId, fileName, tempBytes); } else { StagingServiceHttp.updateStagingRequest(httpPrincipal, stagingRequestId, fileName, bytes); } bytes = new byte[PropsValues.STAGING_REMOTE_TRANSFER_BUFFER_SIZE]; } } finally { StreamUtil.cleanUp(fileInputStream); } }