/** * Delegates to {@link ByteArrayIOUtil#asByteArray(java.io.InputStream)} * * @param in * @throws IllegalArgumentException * If the stream was not specified * @return the byte[] for the given InputStream */ public static byte[] asByteArray(final InputStream in) throws IllegalArgumentException { return ByteArrayIOUtil.asByteArray(in); }
/** * Creates a new {@link Asset} instance backed by the bytes contained in the the specified {@link InputStream} * * @param stream * @throws IllegalArgumentException * If the stream is not specified */ public ByteArrayAsset(final InputStream stream) { // Delegate this(ByteArrayIOUtil.asByteArray(stream)); }
/** * Creates a new {@link Asset} instance backed by the bytes contained in the the specified {@link InputStream} * * @param stream * @throws IllegalArgumentException * If the stream is not specified */ public ByteArrayAsset(final InputStream stream) { // Delegate this(ByteArrayIOUtil.asByteArray(stream)); }
/** * Delegates to {@link ByteArrayIOUtil#asByteArray(java.io.InputStream)} * * @param in * @throws IllegalArgumentException * If the stream was not specified * @return the byte[] for the given InputStream */ public static byte[] asByteArray(final InputStream in) throws IllegalArgumentException { return ByteArrayIOUtil.asByteArray(in); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionOnNullParameter() { ByteArrayIOUtil.asByteArray(null); }
@Test public void shouldReturnByteArrayWithSameContentAsPassedIntoInputStream() { final int length = 10; final byte[] contents = new byte[length]; for (int i = 0; i < length; i++) { contents[i] = (byte) i; } byte[] output = ByteArrayIOUtil.asByteArray(new ByteArrayInputStream(contents)); for (int i = 0; i < output.length; i++) { Assert.assertEquals("output content did not equal input content", output[i], contents[i]); } } }