public void testToByteArray_withSize_givenLargerSize() throws IOException { InputStream in = new ByteArrayInputStream(PRE_FILLED_100); byte[] b = ByteStreams.toByteArray(in, 120); assertEquals(PRE_FILLED_100, b); }
public void testToByteArray_withSize_givenSizeOneSmallerThanActual() throws IOException { InputStream in = new ByteArrayInputStream(PRE_FILLED_100); // this results in toByteArrayInternal being called when the stream is actually exhausted byte[] b = ByteStreams.toByteArray(in, 99); assertEquals(PRE_FILLED_100, b); }
public void testToByteArray() throws IOException { InputStream in = new ByteArrayInputStream(PRE_FILLED_100); byte[] b = ByteStreams.toByteArray(in); assertEquals(PRE_FILLED_100, b); }
public void testToByteArray_withSize_givenSmallerSize() throws IOException { InputStream in = new ByteArrayInputStream(PRE_FILLED_100); byte[] b = ByteStreams.toByteArray(in, 80); assertEquals(PRE_FILLED_100, b); }
public void testToByteArray_emptyStream() throws IOException { InputStream in = newTestStream(0); byte[] b = ByteStreams.toByteArray(in); assertEquals(new byte[0], b); }
public void testCopyChannel() throws IOException { byte[] expected = newPreFilledByteArray(100); ByteArrayOutputStream out = new ByteArrayOutputStream(); WritableByteChannel outChannel = Channels.newChannel(out); ReadableByteChannel inChannel = Channels.newChannel(new ByteArrayInputStream(expected)); ByteStreams.copy(inChannel, outChannel); assertEquals(expected, out.toByteArray()); }
public void testToByteArray_largeStream() throws IOException { // well, large enough to require multiple buffers byte[] expected = newPreFilledByteArray(10000000); InputStream in = new ByteArrayInputStream(expected); byte[] b = ByteStreams.toByteArray(in); assertEquals(expected, b); }
public void testNewDataInput_readChar() { byte[] data = "qed".getBytes(Charsets.UTF_16BE); ByteArrayDataInput in = ByteStreams.newDataInput(data); assertEquals('q', in.readChar()); assertEquals('e', in.readChar()); assertEquals('d', in.readChar()); }
public void testNewDataInput_readFloat() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; ByteArrayDataInput in = ByteStreams.newDataInput(data); assertEquals(Float.intBitsToFloat(0x12345678), in.readFloat(), 0.0); assertEquals(Float.intBitsToFloat(0x76543210), in.readFloat(), 0.0); }
public void testNewDataInput_readUTF() { byte[] data = new byte[17]; data[1] = 15; System.arraycopy("Kilroy was here".getBytes(Charsets.UTF_8), 0, data, 2, 15); ByteArrayDataInput in = ByteStreams.newDataInput(data); assertEquals("Kilroy was here", in.readUTF()); }
public void testNewDataInput_BAIS() { ByteArrayInputStream bais = new ByteArrayInputStream(new byte[] {0x12, 0x34, 0x56, 0x78}); ByteArrayDataInput in = ByteStreams.newDataInput(bais); assertEquals(0x12345678, in.readInt()); }
public void testNewDataInput_readLong() { byte[] data = {0x12, 0x34, 0x56, 0x78, 0x76, 0x54, 0x32, 0x10}; ByteArrayDataInput in = ByteStreams.newDataInput(data); assertEquals(0x1234567876543210L, in.readLong()); }
public void testNewDataOutput_writeDouble() { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeDouble(Double.longBitsToDouble(0x1234567876543210L)); assertEquals(bytes, out.toByteArray()); }
public void testNewDataInput_normal() { ByteArrayDataInput in = ByteStreams.newDataInput(bytes); assertEquals(0x12345678, in.readInt()); assertEquals(0x76543210, in.readInt()); try { in.readInt(); fail("expected exception"); } catch (IllegalStateException expected) { } }
public void testNewDataOutput_writeChar() { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeChar('a'); assertEquals(new byte[] {0, 97}, out.toByteArray()); }
public void testNewDataOutput_writeByteArray() { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.write(bytes); assertEquals(bytes, out.toByteArray()); }
public void testNewDataOutput_writeShort() { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeShort(0x1234); assertEquals(new byte[] {0x12, 0x34}, out.toByteArray()); }
public void testNewDataOutput_writeLong() { ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeLong(0x1234567876543210L); assertEquals(bytes, out.toByteArray()); }
public void testNewDataOutput_sized() { ByteArrayDataOutput out = ByteStreams.newDataOutput(4); out.writeInt(0x12345678); out.writeInt(0x76543210); assertEquals(bytes, out.toByteArray()); }
public void testNewDataInput_offset() { ByteArrayDataInput in = ByteStreams.newDataInput(bytes, 2); assertEquals(0x56787654, in.readInt()); try { in.readInt(); fail("expected exception"); } catch (IllegalStateException expected) { } }