Source:
<code>public void readFilter(InputStream input, OutputStream output, String charset, HashMap<String, String> otherParams, FilterCallback cb) throws DataFilterException, IOException { boolean isComment = false; boolean isBadUri = false; int numberOfDotsInUri = 0; int readcount; byte[] nextbyte = new byte[1]; byte[] fileUri; int fileIndex; String uriForcetypeMp3Suffix = "?type=audio/mpeg"; try (DataInputStream dis = new DataInputStream(input)) { readcount = dis.read(nextbyte); while (readcount != -1) { if (Arrays.equals(nextbyte, CHAR_COMMENT_START)) { isComment = true; } else { isComment = false; } numberOfDotsInUri = 0; isBadUri = false; fileIndex = 0; fileUri = new byte[MAX_URI_LENGTH]; while (readcount != -1) { if (!isComment && !Arrays.equals(nextbyte, CHAR_CARRIAGE_RETURN) && fileIndex <= MAX_URI_LENGTH) { fileUri[fileIndex] = nextbyte[0]; fileIndex += readcount; } readcount = dis.read(nextbyte); if (Arrays.equals(nextbyte, CHAR_NEWLINE)) { if (!isComment) { if (fileIndex <= MAX_URI_LENGTH) { for (int i = 0; i < fileIndex; i++) { byte b = fileUri[i]; if (!isAllowedInUri(b)) { isBadUri = true; break; } if ((byte)'.' == b) { numberOfDotsInUri += 1; } } if (numberOfDotsInUri != 1) { isBadUri = true; } String uri; if (isBadUri) { uri = badUriReplacement; } else { uri = new String(fileUri, 0, fileIndex, "UTF-8"); uri += uriForcetypeMp3Suffix; } output.write(uri.getBytes("UTF-8")); <START> output.write(nextbyte); <END> } } readcount = dis.read(nextbyte); break; } } } } output.flush(); }</code><technical_language>write straight output bucket here... Do want throw if find like... mangle output/truncate file</technical_language>

Target:
public void readFilter(InputStream input, OutputStream output, String charset, HashMap<String, String> otherParams, FilterCallback cb) throws DataFilterException, IOException { boolean isComment = false; boolean isBadUri = false; int numberOfDotsInUri = 0; int readcount; byte[] nextbyte = new byte[1]; byte[] fileUri; int fileIndex; String uriForcetypeMp3Suffix = "?type=audio/mpeg"; try (DataInputStream dis = new DataInputStream(input); DataOutputStream dos = new DataOutputStream(output)) { readcount = dis.read(nextbyte); while (readcount != -1) { if (isCommentStart(nextbyte)) { isComment = true; } else { isComment = false; } if (isNewline(nextbyte)) { readcount = dis.read(nextbyte); continue; } numberOfDotsInUri = 0; isBadUri = false; fileIndex = 0; fileUri = new byte[MAX_URI_LENGTH]; while (readcount != -1) { if (!isComment && !isCarriageReturn(nextbyte) && fileIndex <= MAX_URI_LENGTH) { fileUri[fileIndex] = nextbyte[0]; fileIndex += readcount; } readcount = dis.read(nextbyte); if (isNewline(nextbyte) || readcount == -1) { if (!isComment) { if (fileIndex <= MAX_URI_LENGTH) { String uriold = new String(fileUri, 0, fileIndex, "UTF-8"); String filtered; try { if (uriold.endsWith(".m3u") || uriold.endsWith(".m3u8")) { filtered = cb.processURI(uriold, "audio/mpegurl"); } else { filtered = cb.processURI(uriold, "audio/mpeg"); } } catch (CommentException e) { filtered = badUriReplacement; } if (filtered == null) { filtered = badUriReplacement; } dos.write(filtered.getBytes("UTF-8")); if (readcount != -1){ dos.write(nextbyte); } } } readcount = dis.read(nextbyte); break; } } } } }