public void testToByteArray_emptyStream() throws IOException { InputStream in = newTestStream(0); byte[] b = ByteStreams.toByteArray(in); assertEquals(new byte[0], b); }
public void testExhaust() throws IOException { InputStream in = newTestStream(100); assertEquals(100, ByteStreams.exhaust(in)); assertEquals(-1, in.read()); assertEquals(0, ByteStreams.exhaust(in)); InputStream empty = newTestStream(0); assertEquals(0, ByteStreams.exhaust(empty)); assertEquals(-1, empty.read()); }
ByteStreams.readFully(newTestStream(10), null, 0, 10); fail("expected exception"); } catch (NullPointerException e) { ByteStreams.readFully(newTestStream(10), b, -1, 10); fail("expected exception"); } catch (IndexOutOfBoundsException e) { ByteStreams.readFully(newTestStream(10), b, 0, -1); fail("expected exception"); } catch (IndexOutOfBoundsException e) { ByteStreams.readFully(newTestStream(10), b, 0, -1); fail("expected exception"); } catch (IndexOutOfBoundsException e) { ByteStreams.readFully(newTestStream(10), b, 2, 10); fail("expected exception"); } catch (IndexOutOfBoundsException e) { ByteStreams.readFully(newTestStream(5), b, 0, 10); fail("expected exception"); } catch (EOFException e) { ByteStreams.readFully(newTestStream(10), b, 0, 0); assertEquals(new byte[10], b); ByteStreams.readFully(newTestStream(10), b, 0, 10); assertEquals(newPreFilledByteArray(10), b);
public void testToByteArray_withSize_givenLargerSize() throws IOException { InputStream in = newTestStream(100); byte[] b = ByteStreams.toByteArray(in, 120); assertEquals(100, b.length); }
public void testToByteArray_withSize_givenSizeZero() throws IOException { InputStream in = newTestStream(100); byte[] b = ByteStreams.toByteArray(in, 0); assertEquals(100, b.length); }
public void testToByteArray_withSize_givenCorrectSize() throws IOException { InputStream in = newTestStream(100); byte[] b = ByteStreams.toByteArray(in, 100); assertEquals(100, b.length); }
public void testToByteArray_withSize_givenSmallerSize() throws IOException { InputStream in = newTestStream(100); byte[] b = ByteStreams.toByteArray(in, 80); assertEquals(100, b.length); }
public void testExhaust() throws IOException { InputStream in = newTestStream(100); assertEquals(100, ByteStreams.exhaust(in)); assertEquals(-1, in.read()); assertEquals(0, ByteStreams.exhaust(in)); InputStream empty = newTestStream(0); assertEquals(0, ByteStreams.exhaust(empty)); assertEquals(-1, empty.read()); }
ByteStreams.readFully(newTestStream(10), null, 0, 10); fail("expected exception"); } catch (NullPointerException e) { ByteStreams.readFully(newTestStream(10), b, -1, 10); fail("expected exception"); } catch (IndexOutOfBoundsException e) { ByteStreams.readFully(newTestStream(10), b, 0, -1); fail("expected exception"); } catch (IndexOutOfBoundsException e) { ByteStreams.readFully(newTestStream(10), b, 0, -1); fail("expected exception"); } catch (IndexOutOfBoundsException e) { ByteStreams.readFully(newTestStream(10), b, 2, 10); fail("expected exception"); } catch (IndexOutOfBoundsException e) { ByteStreams.readFully(newTestStream(5), b, 0, 10); fail("expected exception"); } catch (EOFException e) { ByteStreams.readFully(newTestStream(10), b, 0, 0); assertEquals(new byte[10], b); ByteStreams.readFully(newTestStream(10), b, 0, 10); assertEquals(newPreFilledByteArray(10), b);