@Test public void createRandom() throws IOException { when(this.body.getDataType()).thenReturn(DataType.RANDOM); when(this.body.getSize()).thenReturn(1024L); final InputStream in = Streams.create(this.body); final byte[] buf = new byte[1024]; boolean nonZero = false; assertThat(in.read(buf), is(1024)); for (int i = 0; i < buf.length; i++) { if (buf[i] != 0) { nonZero = true; } } assertThat(nonZero, is(true)); }
public static InputStream create(final Body body) { checkNotNull(body); switch (body.getDataType()) { case NONE: return NONE_INPUTSTREAM; case ZEROES: return create(ZERO_BUF, body.getSize()); case CUSTOM: return create(body.getContent().getBytes(Charsets.UTF_8), body.getSize()); default: return create(createRandomBuffer(body.getRandomSeed()), body.getSize()); } }
Streams { public static InputStream create(final Body body) { checkNotNull(body); switch (body.getDataType()) { case NONE: return NONE_INPUTSTREAM; case ZEROES: return create(ZERO_BUF, body.getSize()); case CUSTOM: return create(body.getContent().getBytes(Charsets.UTF_8), body.getSize()); default: return create(createRandomBuffer(body.getRandomSeed()), body.getSize()); } } }
Streams { public static InputStream create(final Body body) { checkNotNull(body); switch (body.getDataType()) { case NONE: return NONE_INPUTSTREAM; case ZEROES: return create(ZERO_BUF, body.getSize()); case CUSTOM: return create(body.getContent().getBytes(Charsets.UTF_8), body.getSize()); default: return create(createRandomBuffer(body.getRandomSeed()), body.getSize()); } } private  Streams(); }
Streams { public static InputStream create(final Body body) { checkNotNull(body); switch (body.getDataType()) { case NONE: return NONE_INPUTSTREAM; case ZEROES: return create(ZERO_BUF, body.getSize()); case CUSTOM: return create(body.getContent().getBytes(Charsets.UTF_8), body.getSize()); default: return create(createRandomBuffer(body.getRandomSeed()), body.getSize()); } } private  Streams(); static InputStream create(final Body body); static InputStream throttle(final InputStream in, final long bytesPerSecond); static OutputStream throttle(final OutputStream out, final long bytesPerSecond); }
Streams { public static InputStream create(final Body body) { checkNotNull(body); switch (body.getDataType()) { case NONE: return NONE_INPUTSTREAM; case ZEROES: return create(ZERO_BUF, body.getSize()); case CUSTOM: return create(body.getContent().getBytes(Charsets.UTF_8), body.getSize()); default: return create(createRandomBuffer(body.getRandomSeed()), body.getSize()); } } private  Streams(); static InputStream create(final Body body); static InputStream throttle(final InputStream in, final long bytesPerSecond); static OutputStream throttle(final OutputStream out, final long bytesPerSecond); static final int REPEAT_LENGTH; }