@Override public void process(final InputStream in, final OutputStream out) throws IOException { try (final LineDemarcator demarcator = new LineDemarcator(in, charset, maxBufferSize, 8192); final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, charset))) { String oneLine; while (null != (oneLine = demarcator.nextLine())) { final String updatedValue = replacementValue.concat(oneLine); bw.write(updatedValue); } } } });
@Override public void process(final InputStream in, final OutputStream out) throws IOException { try (final LineDemarcator demarcator = new LineDemarcator(in, charset, maxBufferSize, initialBufferSize); final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, charset))) { String oneLine; while (null != (oneLine = demarcator.nextLine())) { int matches = 0; int lastEnd = 0; final Matcher matcher = searchPattern.matcher(oneLine); while (matcher.find()) { bw.write(oneLine, lastEnd, matcher.start() - lastEnd); bw.write(replacementValue); matches++; lastEnd = matcher.end(); } if (matches > 0) { bw.write(oneLine, lastEnd, oneLine.length() - lastEnd); } else { bw.write(oneLine); } } } } });
@Override public void process(final InputStream in, final OutputStream out) throws IOException { try (final LineDemarcator demarcator = new LineDemarcator(in, charset, maxBufferSize, 8192); final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, charset))) { String line; while ((line = demarcator.nextLine()) != null) { // We need to determine what line ending was used and use that after our replacement value. lineEndingBuilder.setLength(0); for (int i = line.length() - 1; i >= 0; i--) { final char c = line.charAt(i); if (c == '\r' || c == '\n') { lineEndingBuilder.append(c); } else { break; } } bw.write(replacementValue); // Preserve original line endings. Reverse string because we iterated over original line ending in reverse order, appending to builder. // So if builder has multiple characters, they are now reversed from the original string's ordering. bw.write(lineEndingBuilder.reverse().toString()); } } } });
@Override public void process(final InputStream in, final OutputStream out) throws IOException { try (final LineDemarcator demarcator = new LineDemarcator(in, charset, maxBufferSize, 8192); final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, charset))) { String oneLine; while (null != (oneLine = demarcator.nextLine())) { // we need to find the first carriage return or new-line so that we can append the new value // before the line separate. However, we don't want to do this using a regular expression due // to performance concerns. So we will find the first occurrence of either \r or \n and use // that to insert the replacement value. boolean foundNewLine = false; for (int i = 0; i < oneLine.length(); i++) { final char c = oneLine.charAt(i); if (foundNewLine) { bw.write(c); continue; } if (c == '\r' || c == '\n') { bw.write(replacementValue); foundNewLine = true; } bw.write(c); } if (!foundNewLine) { bw.write(replacementValue); } } } } });
@Override public void process(final InputStream in, final OutputStream out) throws IOException { try (final LineDemarcator demarcator = new LineDemarcator(in, charset, maxBufferSize, 8192); final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out, charset))) {
@Override public void process(final InputStream in) throws IOException { try (final LineDemarcator demarcator = new LineDemarcator(in, charset, Integer.MAX_VALUE, 8192)) {