Improve recording download from server
This commit is contained in:
parent
77e0a0737a
commit
e0f494d6da
|
@ -22,6 +22,7 @@ import ctbrec.Hmac;
|
|||
import ctbrec.Model;
|
||||
import ctbrec.OS;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.io.HttpException;
|
||||
import ctbrec.io.StreamRedirectThread;
|
||||
import ctbrec.recorder.ProgressListener;
|
||||
import ctbrec.recorder.RecordingManager;
|
||||
|
@ -150,21 +151,22 @@ public class MergedHlsDownload extends HlsDownload {
|
|||
private void downloadFile(String fileUri, File tempDir) throws IOException {
|
||||
LOG.trace("Downloading file {} to {}", fileUri, tempDir);
|
||||
Request request = new Request.Builder().url(fileUri).addHeader("connection", "keep-alive").build();
|
||||
Response response = client.execute(request);
|
||||
try (Response response = client.execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
InputStream in = null;
|
||||
File file = new File(request.url().encodedPath());
|
||||
try (FileOutputStream fos = new FileOutputStream(new File(tempDir, file.getName()))) {
|
||||
File downloadedSegment = new File(tempDir, file.getName());
|
||||
try (FileOutputStream fos = new FileOutputStream(downloadedSegment)) {
|
||||
in = response.body().byteStream();
|
||||
byte[] b = new byte[1024 * 100];
|
||||
int length = -1;
|
||||
while ((length = in.read(b)) >= 0) {
|
||||
fos.write(b, 0, length);
|
||||
}
|
||||
} finally {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
response.close();
|
||||
} else {
|
||||
throw new HttpException(response.code(), response.message());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue