+ /**
+ * The minimum size of the internal buffer (could be more if at least one of
+ * the 'FROM' bytes arrays is > 2048 bytes — in that case the
+ * buffer will be twice the largest size of the 'FROM' bytes arrays).
+ * <p>
+ * This is a different buffer than the one from the inherited class.
+ */
+ static private final int MIN_BUFFER_SIZE = 4096;
+
* the {@link String} to replace with
*/
public ReplaceInputStream(InputStream in, String from, String to) {
* the {@link String} to replace with
*/
public ReplaceInputStream(InputStream in, String from, String to) {
* the values to replace with
*/
public ReplaceInputStream(InputStream in, String[] froms, String[] tos) {
* the values to replace with
*/
public ReplaceInputStream(InputStream in, String[] froms, String[] tos) {
for (int i = 0; i < tos.length; i++) {
maxToSize = Math.max(maxToSize, tos[i].length);
}
for (int i = 0; i < tos.length; i++) {
maxToSize = Math.max(maxToSize, tos[i].length);
}
- protected int read(InputStream in, byte[] buffer) throws IOException {
- if (buffer.length < maxToSize || source.length < maxToSize * 2) {
+ protected int read(InputStream in, byte[] buffer, int off, int len)
+ throws IOException {
+ if (len < maxToSize || source.length < maxToSize * 2) {
boolean replaced = false;
for (int i = 0; i < froms.length; i++) {
if (froms[i] != null && froms[i].length > 0
&& StreamUtils.startsWith(froms[i], source, spos, slen)) {
if (tos[i] != null && tos[i].length > 0) {
boolean replaced = false;
for (int i = 0; i < froms.length; i++) {
if (froms[i] != null && froms[i].length > 0
&& StreamUtils.startsWith(froms[i], source, spos, slen)) {
if (tos[i] != null && tos[i].length > 0) {
- System.arraycopy(tos[i], 0, buffer, spos, tos[i].length);
+ System.arraycopy(tos[i], 0, buffer, off + count,
+ tos[i].length);