@Test public void parseNullInputStream() { expectedException.expect(IllegalArgumentException.class); PlaylistParser.parse((InputStream) null); }
public static Playlist parse(final InputStream inputStream) { if (inputStream == null) { throw new IllegalArgumentException("Input stream is null!"); } List<Playlist.Track> tracks = new ArrayList<>(); int version = -1, entries = -1; BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); try { String line; while ((line = reader.readLine()) != null) { Matcher fileMatcher = FILE_PATTERN.matcher(line); if (fileMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, fileMatcher); tracks.get(trackIndex).file = fileMatcher.group(2).trim(); continue; } Matcher titleMatcher = TITLE_PATTERN.matcher(line); if (titleMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, titleMatcher); tracks.get(trackIndex).title = titleMatcher.group(2).trim(); continue; } Matcher lengthMatcher = LENGTH_PATTERN.matcher(line); if (lengthMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, lengthMatcher); tracks.get(trackIndex).length = Long.valueOf(lengthMatcher.group(2).trim()); continue; } Matcher numberOfEntries = FOOTER_NUMBER_OF_ENTRIES_PATTERN.matcher(line); if (numberOfEntries.matches()) { entries = Integer.valueOf(numberOfEntries.group(1).trim()); continue; } Matcher versionMatcher = FOOTER_VERSION_PATTERN.matcher(line); if (versionMatcher.matches()) { version = Integer.valueOf(versionMatcher.group(1).trim()); } } } catch (IOException e) { Log.e(TAG, "Failed to parse playlist file: " + e); } if (tracks.size() != entries) { Log.w(TAG, "Parsed track count doesn't match proclaimed NumberOfEntries"); } return new Playlist(tracks, version); }
PlaylistParser { public static Playlist parse(final InputStream inputStream) { if (inputStream == null) { throw new IllegalArgumentException("Input stream is null!"); } List<Playlist.Track> tracks = new ArrayList<>(); int version = -1, entries = -1; BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); try { String line; while ((line = reader.readLine()) != null) { Matcher fileMatcher = FILE_PATTERN.matcher(line); if (fileMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, fileMatcher); tracks.get(trackIndex).file = fileMatcher.group(2).trim(); continue; } Matcher titleMatcher = TITLE_PATTERN.matcher(line); if (titleMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, titleMatcher); tracks.get(trackIndex).title = titleMatcher.group(2).trim(); continue; } Matcher lengthMatcher = LENGTH_PATTERN.matcher(line); if (lengthMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, lengthMatcher); tracks.get(trackIndex).length = Long.valueOf(lengthMatcher.group(2).trim()); continue; } Matcher numberOfEntries = FOOTER_NUMBER_OF_ENTRIES_PATTERN.matcher(line); if (numberOfEntries.matches()) { entries = Integer.valueOf(numberOfEntries.group(1).trim()); continue; } Matcher versionMatcher = FOOTER_VERSION_PATTERN.matcher(line); if (versionMatcher.matches()) { version = Integer.valueOf(versionMatcher.group(1).trim()); } } } catch (IOException e) { Log.e(TAG, "Failed to parse playlist file: " + e); } if (tracks.size() != entries) { Log.w(TAG, "Parsed track count doesn't match proclaimed NumberOfEntries"); } return new Playlist(tracks, version); } }
PlaylistParser { public static Playlist parse(final InputStream inputStream) { if (inputStream == null) { throw new IllegalArgumentException("Input stream is null!"); } List<Playlist.Track> tracks = new ArrayList<>(); int version = -1, entries = -1; BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); try { String line; while ((line = reader.readLine()) != null) { Matcher fileMatcher = FILE_PATTERN.matcher(line); if (fileMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, fileMatcher); tracks.get(trackIndex).file = fileMatcher.group(2).trim(); continue; } Matcher titleMatcher = TITLE_PATTERN.matcher(line); if (titleMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, titleMatcher); tracks.get(trackIndex).title = titleMatcher.group(2).trim(); continue; } Matcher lengthMatcher = LENGTH_PATTERN.matcher(line); if (lengthMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, lengthMatcher); tracks.get(trackIndex).length = Long.valueOf(lengthMatcher.group(2).trim()); continue; } Matcher numberOfEntries = FOOTER_NUMBER_OF_ENTRIES_PATTERN.matcher(line); if (numberOfEntries.matches()) { entries = Integer.valueOf(numberOfEntries.group(1).trim()); continue; } Matcher versionMatcher = FOOTER_VERSION_PATTERN.matcher(line); if (versionMatcher.matches()) { version = Integer.valueOf(versionMatcher.group(1).trim()); } } } catch (IOException e) { Log.e(TAG, "Failed to parse playlist file: " + e); } if (tracks.size() != entries) { Log.w(TAG, "Parsed track count doesn't match proclaimed NumberOfEntries"); } return new Playlist(tracks, version); } private  PlaylistParser(); }
PlaylistParser { public static Playlist parse(final InputStream inputStream) { if (inputStream == null) { throw new IllegalArgumentException("Input stream is null!"); } List<Playlist.Track> tracks = new ArrayList<>(); int version = -1, entries = -1; BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); try { String line; while ((line = reader.readLine()) != null) { Matcher fileMatcher = FILE_PATTERN.matcher(line); if (fileMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, fileMatcher); tracks.get(trackIndex).file = fileMatcher.group(2).trim(); continue; } Matcher titleMatcher = TITLE_PATTERN.matcher(line); if (titleMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, titleMatcher); tracks.get(trackIndex).title = titleMatcher.group(2).trim(); continue; } Matcher lengthMatcher = LENGTH_PATTERN.matcher(line); if (lengthMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, lengthMatcher); tracks.get(trackIndex).length = Long.valueOf(lengthMatcher.group(2).trim()); continue; } Matcher numberOfEntries = FOOTER_NUMBER_OF_ENTRIES_PATTERN.matcher(line); if (numberOfEntries.matches()) { entries = Integer.valueOf(numberOfEntries.group(1).trim()); continue; } Matcher versionMatcher = FOOTER_VERSION_PATTERN.matcher(line); if (versionMatcher.matches()) { version = Integer.valueOf(versionMatcher.group(1).trim()); } } } catch (IOException e) { Log.e(TAG, "Failed to parse playlist file: " + e); } if (tracks.size() != entries) { Log.w(TAG, "Parsed track count doesn't match proclaimed NumberOfEntries"); } return new Playlist(tracks, version); } private  PlaylistParser(); static Playlist parse(final InputStream inputStream); static Playlist parse(final String string, final String encoding); static Playlist parse(final String string); }
PlaylistParser { public static Playlist parse(final InputStream inputStream) { if (inputStream == null) { throw new IllegalArgumentException("Input stream is null!"); } List<Playlist.Track> tracks = new ArrayList<>(); int version = -1, entries = -1; BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); try { String line; while ((line = reader.readLine()) != null) { Matcher fileMatcher = FILE_PATTERN.matcher(line); if (fileMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, fileMatcher); tracks.get(trackIndex).file = fileMatcher.group(2).trim(); continue; } Matcher titleMatcher = TITLE_PATTERN.matcher(line); if (titleMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, titleMatcher); tracks.get(trackIndex).title = titleMatcher.group(2).trim(); continue; } Matcher lengthMatcher = LENGTH_PATTERN.matcher(line); if (lengthMatcher.matches()) { int trackIndex = getTrackIndexAndAddIfMissing(tracks, lengthMatcher); tracks.get(trackIndex).length = Long.valueOf(lengthMatcher.group(2).trim()); continue; } Matcher numberOfEntries = FOOTER_NUMBER_OF_ENTRIES_PATTERN.matcher(line); if (numberOfEntries.matches()) { entries = Integer.valueOf(numberOfEntries.group(1).trim()); continue; } Matcher versionMatcher = FOOTER_VERSION_PATTERN.matcher(line); if (versionMatcher.matches()) { version = Integer.valueOf(versionMatcher.group(1).trim()); } } } catch (IOException e) { Log.e(TAG, "Failed to parse playlist file: " + e); } if (tracks.size() != entries) { Log.w(TAG, "Parsed track count doesn't match proclaimed NumberOfEntries"); } return new Playlist(tracks, version); } private  PlaylistParser(); static Playlist parse(final InputStream inputStream); static Playlist parse(final String string, final String encoding); static Playlist parse(final String string);  }