aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/com/fasterxml/jackson/databind/util/ByteBufferUtilsTest.java
blob: da66aa47f73be3cfa9ea00ebd1451b5f32159b39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.fasterxml.jackson.databind.util;

import java.nio.ByteBuffer;

import com.fasterxml.jackson.databind.BaseMapTest;

public class ByteBufferUtilsTest extends BaseMapTest
{
    public void testByteBufferInput() throws Exception {
        byte[] input = new byte[] { 1, 2, 3 };
        ByteBufferBackedInputStream wrapped = new ByteBufferBackedInputStream(ByteBuffer.wrap(input));
        assertEquals(3, wrapped.available());
        assertEquals(1, wrapped.read());
        byte[] buffer = new byte[10];
        assertEquals(2, wrapped.read(buffer, 0, 5));
        wrapped.close();
    }

    public void testByteBufferOutput() throws Exception {
        ByteBuffer b = ByteBuffer.wrap(new byte[10]);
        ByteBufferBackedOutputStream wrappedOut = new ByteBufferBackedOutputStream(b);
        wrappedOut.write(1);
        wrappedOut.write(new byte[] { 2, 3 });
        assertEquals(3, b.position());
        assertEquals(7, b.remaining());
        wrappedOut.close();
    }
}