Package org.codehaus.preon.channel

Examples of org.codehaus.preon.channel.OutputStreamBitChannel


        encode(value, codec, out);
        return out.toByteArray();
    }

    public static <T> void encode(T value, Codec<T> codec, OutputStream out) throws IOException {
        encode(value, codec, new OutputStreamBitChannel(out));
    }
View Full Code Here


    @Test
    public void shouldEncodeCorrectly() throws IOException, NullPointerException {
    Charset charset = Charset.availableCharsets().get(BoundString.Encoding.ASCII);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        BitChannel channel = new OutputStreamBitChannel(out);
        when(sizeExpr.eval(Matchers.any(Resolver.class))).thenReturn(4);
        FixedLengthStringCodec codec =
                new FixedLengthStringCodec(charset, sizeExpr, null, new BoundString.NullConverter());
        codec.encode("Whatever", channel, resolver);
        out.flush();
View Full Code Here

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        FixedLengthStringCodec codec = new FixedLengthStringCodec(
                Charset.forName("UTF-16BE"), sizeExpr, "",
                new BoundString.NullConverter());

        codec.encode(original, new OutputStreamBitChannel(out), resolver);
        byte[] encoded = out.toByteArray();
        assertThat(encoded.length, is(size));

        BitBuffer buffer = new DefaultBitBuffer(ByteBuffer.wrap(encoded));
        String result = codec.decode(buffer, resolver, builder);
View Full Code Here

        when(metadata.getAnnotation(BoundBuffer.class)).thenReturn(boundBuffer);
        when(boundBuffer.match()).thenReturn(match);

        Codec<byte[]> codec = factory.create(metadata, byte[].class, null);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        codec.encode(match, new OutputStreamBitChannel(out), null);

        byte[] output = out.toByteArray();
        assertThat(output.length, is(match.length));
        assertArrayEquals(match, output);
    }
View Full Code Here

TOP

Related Classes of org.codehaus.preon.channel.OutputStreamBitChannel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.