X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FReplaceInputStream.java;fp=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FReplaceInputStream.java;h=b2187af09ce189dae52105733c10559f0db4aff0;hp=eea3a1ab9b74b42158d5b40e565b59c839cb690a;hb=028ff7c29a8fb07c702ffd34913a5dd22b688211;hpb=617ad86c825bf7fdc85b72c3a453d9c90bd8f770 diff --git a/src/be/nikiroo/utils/streams/ReplaceInputStream.java b/src/be/nikiroo/utils/streams/ReplaceInputStream.java index eea3a1a..b2187af 100644 --- a/src/be/nikiroo/utils/streams/ReplaceInputStream.java +++ b/src/be/nikiroo/utils/streams/ReplaceInputStream.java @@ -101,8 +101,9 @@ public class ReplaceInputStream extends BufferedInputStream { } @Override - 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) { throw new IOException( "An underlaying buffer is too small for these replace values"); } @@ -114,13 +115,14 @@ public class ReplaceInputStream extends BufferedInputStream { // Note: very simple, not efficient implementation, sorry. int count = 0; - while (spos < slen && count < buffer.length - maxToSize) { + while (spos < slen && count < len - maxToSize) { 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 + spos, + tos[i].length); count += tos[i].length; } @@ -131,7 +133,7 @@ public class ReplaceInputStream extends BufferedInputStream { } if (!replaced) { - buffer[count++] = source[spos++]; + buffer[off + count++] = source[spos++]; } }