Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: swizzle-stream-1.0.2
-
Fix Version/s: swizzle-1.6.2
-
Component/s: swizzle-stream
-
Labels:None
-
Environment:Java 1.6
-
Patch Submitted:Yes
-
Number of attachments :
Description
The 'ReplacementInputStream' classes forming part of Swizzle Stream (for example, DelimitedTokenReplacementInputStream, FixedTokenListReplacementInputStream, and FixedTokenReplacementInputStream) all are subclasses of FilterInputStream.
However, they only seem to override the "int read()" single-byte read method, and do NOT seem to override the "int read(byte[] buf,int off,int len)" method from FilterInputStream.
The end result is that if:
a. You don't use the byte-by-byte read method, OR
b. You wrap this in nearly any other FilterInputStream (which generally do not use the byte-by-byte read method).
then the ReplacementInputStream will appear to have no effect at all.
The solution to this is to properly override the "int read(byte[] buf,int off,int len)".
I've attached a patch ("swizzle-fix-read-bug.patch") which includes a 'fix' for this problem, but is likely not the most efficient way to manage things.
What this patch does is:
a. Change each affected class to extend "_FixFilterInputStream" instead of "FilterInputStream".
b. Create a "int read(byte[] buf,int off,int len)" in "_FixFilterInputStream" that calls the "int read()" method iteratively to fulfill the request.
As I've said, this is not the best or most efficient solution to the problem, but it is a pretty non-invasive solution.
Attached patch file "swizzle-fix-read-bug-with-tests.patch", updated to include a test for the case being fixed.
This patch includes only tests for:
I was unfortunately unable to find any tests for the other classes affected by this fix:
If someone can point me to where these tests might be, I can update those tests as well (the adjustment to the test case is quite simple).
Please note that this patch is based on swizzle-stream 1.0.2