X-Git-Url: http://git.nikiroo.be/?p=fanfix.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fstreams%2FReplaceInputStream.java;h=ae576e25e7a4833e9ce8f4bea25616ff018eca52;hp=5332e72d11651cb7da0588e817bbb10310a39449;hb=6d765e484c2f50fd8f5cb3af425b59c51adaca0d;hpb=7194ac50b29064a013f177fc9cfc5aaa131a8ec4 diff --git a/src/be/nikiroo/utils/streams/ReplaceInputStream.java b/src/be/nikiroo/utils/streams/ReplaceInputStream.java index 5332e72..ae576e2 100644 --- a/src/be/nikiroo/utils/streams/ReplaceInputStream.java +++ b/src/be/nikiroo/utils/streams/ReplaceInputStream.java @@ -3,6 +3,8 @@ package be.nikiroo.utils.streams; import java.io.IOException; import java.io.InputStream; +import be.nikiroo.utils.StringUtils; + /** * This {@link InputStream} will change some of its content by replacing it with * something else. @@ -40,7 +42,7 @@ public class ReplaceInputStream extends BufferedInputStream { * the {@link String} to replace with */ public ReplaceInputStream(InputStream in, String from, String to) { - this(in, StreamUtils.bytes(from), StreamUtils.bytes(to)); + this(in, StringUtils.getBytes(from), StringUtils.getBytes(to)); } /** @@ -73,7 +75,7 @@ public class ReplaceInputStream extends BufferedInputStream { * the values to replace with */ public ReplaceInputStream(InputStream in, String[] froms, String[] tos) { - this(in, StreamUtils.bytes(froms), StreamUtils.bytes(tos)); + this(in, StreamUtils.getBytes(froms), StreamUtils.getBytes(tos)); } /** @@ -112,7 +114,8 @@ public class ReplaceInputStream extends BufferedInputStream { } // We need at least maxFromSize so we can iterate and replace - source = new byte[Math.max(2 * maxFromSize, MIN_BUFFER_SIZE)]; + source = new byte[Math.max(2 * Math.max(maxToSize, maxFromSize), + MIN_BUFFER_SIZE)]; spos = 0; slen = 0; } @@ -139,11 +142,11 @@ public class ReplaceInputStream extends BufferedInputStream { 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, off + spos, + System.arraycopy(tos[i], 0, buffer, off + count, tos[i].length); count += tos[i].length; } - + spos += froms[i].length; replaced = true; break;