forked from j62/ctbrec
Add try-with-resources blocks to free up the HLS playlist file handle
This commit is contained in:
parent
9df30b3342
commit
5b9b91d6e8
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue