Balzanka / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Add ByteStreams.zeroInputStream #1370

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
This creates an infinite-length InputStream which returns zero bytes.  Combined 
with ByteStreams.limit this can create large input for tests without consuming 
large amounts of memory.

I created an example with tests here:

https://github.com/maginatics/guava-libraries/pull/1

Original issue reported on code.google.com by g...@maginatics.com on 16 Apr 2013 at 5:54

GoogleCodeExporter commented 9 years ago

Original comment by kak@google.com on 16 Apr 2013 at 5:57

GoogleCodeExporter commented 9 years ago
Updated pull request with more idiomatic Guava code:

https://github.com/maginatics/guava-libraries/pull/2

One could also expose an infinite length non-zero stream which I use for 
testing as well.

Original comment by g...@maginatics.com on 22 Aug 2013 at 4:45

GoogleCodeExporter commented 9 years ago
I made this utility method more generic and updated it for ByteSource:

    /**
     * @return an infinite-length ByteSource which repeats the contents of a
     *         byte array
     */
    public static ByteSource repeatingArrayByteSource(final byte[] input) {
        return ByteSource.concat(Iterables.cycle(ByteSource.wrap(input)));
    }

Callers can use ByteSource.slice to make make input the desired size.  The 
implementation was not obvious to me and perhaps this is useful to others.

Original comment by g...@maginatics.com on 27 Dec 2013 at 6:21

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:18

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08