Updated dependencies (1.19 ready)
This commit is contained in:
parent
96896bce49
commit
2f279a6ab6
2 changed files with 44 additions and 18 deletions
|
@ -3,7 +3,6 @@ package nl.sbdeveloper.mctpaudio.utils;
|
|||
import com.mpatric.mp3agic.InvalidDataException;
|
||||
import com.mpatric.mp3agic.Mp3File;
|
||||
import com.mpatric.mp3agic.UnsupportedTagException;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -78,7 +77,7 @@ public class HeadUtil {
|
|||
public static int getTicksOfFile(String input) throws IOException, InvalidDataException, UnsupportedTagException {
|
||||
URL url = new URL(input);
|
||||
|
||||
String result = downloadFromUrl(url, FilenameUtils.getName(url.getPath()));
|
||||
String result = downloadFromUrl(url, getName(url.getPath()));
|
||||
File file = new File(result);
|
||||
|
||||
if (!file.exists()) return 0;
|
||||
|
@ -90,4 +89,40 @@ public class HeadUtil {
|
|||
|
||||
return (int) (sec * 20);
|
||||
}
|
||||
|
||||
private static final int NOT_FOUND = -1;
|
||||
|
||||
/**
|
||||
* The Unix separator character.
|
||||
*/
|
||||
private static final char UNIX_NAME_SEPARATOR = '/';
|
||||
|
||||
/**
|
||||
* The Windows separator character.
|
||||
*/
|
||||
private static final char WINDOWS_NAME_SEPARATOR = '\\';
|
||||
|
||||
private static String getName(final String fileName) {
|
||||
if (fileName == null) {
|
||||
return null;
|
||||
}
|
||||
return requireNonNullChars(fileName).substring(indexOfLastSeparator(fileName) + 1);
|
||||
}
|
||||
|
||||
private static String requireNonNullChars(final String path) {
|
||||
if (path.indexOf(0) >= 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"Null character present in file/path name. There are no known legitimate use cases for such data, but several injection attacks may use it");
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
private static int indexOfLastSeparator(final String fileName) {
|
||||
if (fileName == null) {
|
||||
return NOT_FOUND;
|
||||
}
|
||||
final int lastUnixPos = fileName.lastIndexOf(UNIX_NAME_SEPARATOR);
|
||||
final int lastWindowsPos = fileName.lastIndexOf(WINDOWS_NAME_SEPARATOR);
|
||||
return Math.max(lastUnixPos, lastWindowsPos);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue