Replace deprecated calls
This commit is contained in:
parent
1e8de4d9e4
commit
14b019e87d
|
@ -2,6 +2,8 @@ package ctbrec.io;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -14,8 +16,11 @@ public class UrlUtil {
|
||||||
private UrlUtil() {}
|
private UrlUtil() {}
|
||||||
|
|
||||||
public static String addHmac(String url, Config config) throws MalformedURLException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, UnsupportedEncodingException {
|
public static String addHmac(String url, Config config) throws MalformedURLException, InvalidKeyException, NoSuchAlgorithmException, IllegalStateException, UnsupportedEncodingException {
|
||||||
URL u = new URL(url);
|
try {
|
||||||
|
URI uri = new URI(url);
|
||||||
|
URL u = uri.toURL();
|
||||||
String path = u.getPath();
|
String path = u.getPath();
|
||||||
|
|
||||||
if (!config.getContextPath().isEmpty()) {
|
if (!config.getContextPath().isEmpty()) {
|
||||||
path = path.substring(config.getContextPath().length());
|
path = path.substring(config.getContextPath().length());
|
||||||
}
|
}
|
||||||
|
@ -23,7 +28,8 @@ public class UrlUtil {
|
||||||
String hmac = Hmac.calculate(path, key);
|
String hmac = Hmac.calculate(path, key);
|
||||||
url = url + "?hmac=" + hmac;
|
url = url + "?hmac=" + hmac;
|
||||||
return url;
|
return url;
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IllegalArgumentException("Invalid URI format: " + url, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@ -199,7 +201,10 @@ public class HlsDownload extends AbstractHlsDownload {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected OutputStream getSegmentOutputStream(Segment segment) throws FileNotFoundException, MalformedURLException {
|
protected OutputStream getSegmentOutputStream(Segment segment) throws FileNotFoundException, MalformedURLException {
|
||||||
URL segmentUrl = new URL(segment.url);
|
try {
|
||||||
|
URI segmentUri = new URI(segment.url);
|
||||||
|
URL segmentUrl = segmentUri.toURL();
|
||||||
|
|
||||||
File tmp = new File(segmentUrl.getFile());
|
File tmp = new File(segmentUrl.getFile());
|
||||||
String prefixedFileName = segment.prefix + '_' + tmp.getName();
|
String prefixedFileName = segment.prefix + '_' + tmp.getName();
|
||||||
int questionMarkPosition = prefixedFileName.indexOf('?');
|
int questionMarkPosition = prefixedFileName.indexOf('?');
|
||||||
|
@ -211,6 +216,9 @@ public class HlsDownload extends AbstractHlsDownload {
|
||||||
}
|
}
|
||||||
segment.targetFile = FileSystems.getDefault().getPath(downloadDir.toAbsolutePath().toString(), prefixedFileName).toFile();
|
segment.targetFile = FileSystems.getDefault().getPath(downloadDir.toAbsolutePath().toString(), prefixedFileName).toFile();
|
||||||
return new FileOutputStream(segment.targetFile);
|
return new FileOutputStream(segment.targetFile);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IllegalArgumentException("Invalid URI format: " + segment.url, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,6 +15,8 @@ import org.slf4j.LoggerFactory;
|
||||||
import javax.crypto.NoSuchPaddingException;
|
import javax.crypto.NoSuchPaddingException;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
|
@ -48,7 +50,13 @@ public class SegmentDownload implements Callable<SegmentDownload> {
|
||||||
this.segment = segment;
|
this.segment = segment;
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.out = out;
|
this.out = out;
|
||||||
this.url = new URL(segment.url);
|
|
||||||
|
try {
|
||||||
|
URI uri = new URI(segment.url);
|
||||||
|
url = uri.toURL();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IllegalArgumentException("Invalid URI format: " + segment.url, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,8 +24,6 @@ import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import static ctbrec.ErrorMessages.HTTP_RESPONSE_BODY_IS_NULL;
|
import static ctbrec.ErrorMessages.HTTP_RESPONSE_BODY_IS_NULL;
|
||||||
import static ctbrec.Model.State.*;
|
import static ctbrec.Model.State.*;
|
||||||
|
|
|
@ -13,7 +13,6 @@ import org.json.JSONObject;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
Loading…
Reference in New Issue