diff --git a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/URLAudioStream.java b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/URLAudioStream.java index 9c87a4f2431..ff176446f0d 100644 --- a/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/URLAudioStream.java +++ b/bundles/org.openhab.core.audio/src/main/java/org/openhab/core/audio/URLAudioStream.java @@ -17,11 +17,11 @@ import java.io.OutputStream; import java.net.MalformedURLException; import java.net.Socket; -import java.net.URI; import java.net.URL; import java.net.URLConnection; -import java.nio.file.Files; -import java.nio.file.Paths; +import java.nio.charset.StandardCharsets; +import java.util.NoSuchElementException; +import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -67,22 +67,32 @@ private InputStream createInputStream() throws AudioException { try { switch (extension) { case M3U_EXTENSION: - for (final String line : Files.readAllLines(Paths.get(URI.create(url)))) { - if (!line.isEmpty() && !line.startsWith("#")) { - url = line; - break; + try (Scanner scanner = new Scanner(new URL(url).openStream(), StandardCharsets.UTF_8.name())) { + while (true) { + String line = scanner.nextLine(); + if (!line.isEmpty() && !line.startsWith("#")) { + url = line; + break; + } } + } catch (NoSuchElementException e) { + // we reached the end of the file, this exception is thus expected } break; case PLS_EXTENSION: - for (final String line : Files.readAllLines(Paths.get(URI.create(url)))) { - if (!line.isEmpty() && line.startsWith("File")) { - final Matcher matcher = PLS_STREAM_PATTERN.matcher(line); - if (matcher.find()) { - url = matcher.group(1); - break; + try (Scanner scanner = new Scanner(new URL(url).openStream(), StandardCharsets.UTF_8.name())) { + while (true) { + String line = scanner.nextLine(); + if (!line.isEmpty() && line.startsWith("File")) { + final Matcher matcher = PLS_STREAM_PATTERN.matcher(line); + if (matcher.find()) { + url = matcher.group(1); + break; + } } } + } catch (NoSuchElementException e) { + // we reached the end of the file, this exception is thus expected } break; default: