commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niall Pemberton (JIRA)" <>
Subject [jira] Commented: (IO-94) New Mock InputStream & Writer implementations
Date Thu, 12 Oct 2006 16:44:39 GMT
    [ ] 
Niall Pemberton commented on IO-94:

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


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) {
        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:
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Streams/Writers
>            Reporter: Niall Pemberton
>         Assigned To: Niall Pemberton
>            Priority: Minor
>             Fix For: 1.3
>         Attachments:,
> 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:
For more information on JIRA, see:


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message