Java Utililty Methods URL to

List of utility methods to do URL to

Description

The list of methods to do URL to are organized into topic(s).

Method

StringconvertURL(String url)
convert URL
String var1 = java.net.URLDecoder.decode(url, "ASCII");
String var2 = var1.replaceAll("%2C", ",");
return var2;
FileconvertURLToFile(URL url)
convert URL To File
if (url == null) {
    return null;
try {
    return new File(url.toURI());
} catch (URISyntaxException e) {
    try {
        return new File(URLDecoder.decode(url.getPath(), "UTF-8"));
...
StringconvertUrlToFilename(URL url)
convert Url To Filename
return convertUrlToFilename(url.getFile());
StringconvertUrlToFilePath(URL url)
convert Url To File Path
try {
    return URLDecoder.decode(url.getFile(), "UTF-8");
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e);
StringconvertUrlToHostNameAsNodeName(String url)
convert Url To Host Name As Node Name
String host = new URL(url).getHost().replace('.', '-');
return host;
FileconvertUrlToMp3Cmd(final String url)
convert Url To Mp Cmd
final String mp3Filename = UUID.randomUUID().toString() + ".mp3";
final String escFilename = URLEncoder.encode(url.substring(url.lastIndexOf("/") + 1), "UTF-8");
final String escUrl = url.substring(0, url.lastIndexOf("/") + 1) + escFilename;
final String cmd = "ffmpeg -i " + escUrl + " -ac 2 -codec:a libmp3lame -b:a 48k -ar 16000 -af volume=10dB "
        + mp3Filename;
System.out.println(cmd);
final Process p = Runtime.getRuntime().exec(cmd);
p.waitFor();
...
URLconvertURIToURL(URI uri)
Tries to convert the specified URI to a URL.
try {
    return uri.toURL();
} catch (MalformedURLException e) {
    return null;
voidcopyUrlToFile(URL url, File file)
copy Url To File
final InputStream inputStream;
final FileOutputStream fileOutputStream;
try {
    inputStream = url.openStream();
    fileOutputStream = new FileOutputStream(file);
} catch (final IOException e) {
    throw new RuntimeException(e);
copy(inputStream, fileOutputStream);
closeQuietly(inputStream);
closeQuietly(fileOutputStream);
voidcopyUrlToFile(URL url, File file)
Copies the content of the given url to the specified file.
final InputStream inputStream;
final FileOutputStream fileOutputStream;
try {
    inputStream = url.openStream();
    fileOutputStream = new FileOutputStream(file);
} catch (final IOException e) {
    throw new RuntimeException(e);
copy(inputStream, fileOutputStream);
closeQuietly(inputStream);
closeQuietly(fileOutputStream);