commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <j...@apache.org>
Subject [jira] Commented: (IO-94) New Mock InputStream & Writer implementations
Date Thu, 12 Oct 2006 16:44:39 GMT
    [ http://issues.apache.org/jira/browse/IO-94?page=comments#action_12441792 ] 
            
Niall Pemberton commented on IO-94:
-----------------------------------

>From what you describe this is what MockInputStream and MockReader do out of the box:

MockInputStream: http://tinyurl.com/yk26nc
MockReader:  http://tinyurl.com/yd72ct

For MockInputStream, the read() method returns 0 but can be overriden to return any value
by implementing the processByte() method. The read(byte[]) methods return the bytes array
passed unchanged - so if its initialized to zero values, thats what you get back - but you
can override the processBytes(byte[], offset, length) method to fill the array with whatever
you want.

So a custom implementation would look like the following:

    public class FooInputStream extends MockInputStream {
        public TestMockInputStream(int size) {
            super(size);
        }
        protected int processByte() {
            return ...  // return whatever value required here
        }
        protected void processBytes(byte[] bytes, int offset, int length) {
            int startPos = (int)getPosition() - length;
            for (int i = offset; i < length; i++) {
                bytes[i] =  ... // initialize whatever value here
            }
        }
        
    }

Maybe "mock" is an unfortunate choice of names and should be renamed - they are fully functional
streams which as well as supporting the read methods also properly implement skip(), mark()
and reset(). In my view they're the equivalent of the NullOutputStream/NullReader - but those
implementations are far simpler since they just have to ignore everything rather than function
as a proper InputStram / Reader. I'd be happy to call them NullInputStream and NullReader
instead if that is preferable.

> New Mock InputStream & Writer implementations
> ---------------------------------------------
>
>                 Key: IO-94
>                 URL: http://issues.apache.org/jira/browse/IO-94
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>
>         Attachments: MockInputStream.java, MockInputStreamTestCase.java
>
>
> I have created a MockInputStream which can be plugged in for testing parts of systems
where the data doesn't matter - the main use I've had for it was testing large files - without
actually having the InputStream process large amounts of bytes.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message