forked from j62/ctbrec
1
0
Fork 0

Add try-with-resources blocks to free up the HLS playlist file handle

This commit is contained in:
0xboobface 2019-12-22 15:01:49 +01:00
parent 9df30b3342
commit 5b9b91d6e8
2 changed files with 29 additions and 25 deletions

View File

@ -135,7 +135,8 @@ public class PlaylistGenerator {
public void validate(File recDir) throws IOException, ParseException, PlaylistException {
File playlist = new File(recDir, "playlist.m3u8");
if(playlist.exists()) {
PlaylistParser playlistParser = new PlaylistParser(new FileInputStream(playlist), Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
try(FileInputStream fin = new FileInputStream(playlist)) {
PlaylistParser playlistParser = new PlaylistParser(fin, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
Playlist m3u = playlistParser.parse();
MediaPlaylist mediaPlaylist = m3u.getMediaPlaylist();
int playlistSize = mediaPlaylist.getTracks().size();
@ -152,6 +153,7 @@ public class PlaylistGenerator {
} else {
LOG.debug("Generated playlist looks good");
}
}
} else {
throw new FileNotFoundException(playlist.getAbsolutePath() + " does not exist");
}

View File

@ -332,7 +332,8 @@ public class HlsDownload extends AbstractHlsDownload {
private double getPlaylistLength(File playlist) throws IOException, ParseException, PlaylistException {
if (playlist.exists()) {
PlaylistParser playlistParser = new PlaylistParser(new FileInputStream(playlist), Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
try(FileInputStream fin = new FileInputStream(playlist)) {
PlaylistParser playlistParser = new PlaylistParser(fin, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
Playlist m3u = playlistParser.parse();
MediaPlaylist mediaPlaylist = m3u.getMediaPlaylist();
double length = 0;
@ -340,6 +341,7 @@ public class HlsDownload extends AbstractHlsDownload {
length += trackData.getTrackInfo().duration;
}
return length;
}
} else {
throw new FileNotFoundException(playlist.getAbsolutePath() + " does not exist");
}