Java Code Examples for javax.websocket.Decoder#Binary

The following examples show how to use javax.websocket.Decoder#Binary . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Encoding.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
public Object decodeBinary(final Class<?> targetType, final byte[] bytes) throws DecodeException {
    List<InstanceHandle<? extends Decoder>> decoders = binaryDecoders.get(targetType);
    if (decoders != null) {
        for (InstanceHandle<? extends Decoder> decoderHandle : decoders) {
            Decoder decoder = decoderHandle.getInstance();
            if (decoder instanceof Decoder.Binary) {
                if (((Decoder.Binary) decoder).willDecode(ByteBuffer.wrap(bytes))) {
                    return ((Decoder.Binary) decoder).decode(ByteBuffer.wrap(bytes));
                }
            } else {
                try {
                    return ((Decoder.BinaryStream) decoder).decode(new ByteArrayInputStream(bytes));
                } catch (IOException e) {
                    throw new DecodeException(ByteBuffer.wrap(bytes), "Could not decode binary", e);
                }
            }
        }
    }
    throw new DecodeException(ByteBuffer.wrap(bytes), "Could not decode binary");
}
 
Example 2
Source File: ConvertingEncoderDecoderSupportTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void decodeFromBinaryCannotConvert() throws Exception {
	setup(NoConvertersConfig.class);
	Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
	assertThat(decoder.willDecode(CONVERTED_BYTES), is(false));
	assertThatExceptionOfType(DecodeException.class).isThrownBy(() ->
			decoder.decode(CONVERTED_BYTES))
		.withCauseInstanceOf(ConverterNotFoundException.class);
}
 
Example 3
Source File: ConvertingEncoderDecoderSupportTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void decodeFromBinaryCannotConvert() throws Exception {
	setup(NoConvertersConfig.class);
	Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
	assertThat(decoder.willDecode(CONVERTED_BYTES), is(false));
	thown.expect(DecodeException.class);
	thown.expectCause(isA(ConverterNotFoundException.class));
	decoder.decode(CONVERTED_BYTES);
}
 
Example 4
Source File: ConvertingEncoderDecoderSupportTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void decodeFromBinaryCannotConvert() throws Exception {
	setup(NoConvertersConfig.class);
	Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
	assertThat(decoder.willDecode(CONVERTED_BYTES), is(false));
	thown.expect(DecodeException.class);
	thown.expectCause(isA(ConverterNotFoundException.class));
	decoder.decode(CONVERTED_BYTES);
}
 
Example 5
Source File: ConvertingEncoderDecoderSupportTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void decodeFromBinary() throws Exception {
	Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
	assertThat(decoder.willDecode(CONVERTED_BYTES), is(true));
	assertThat(decoder.decode(CONVERTED_BYTES), equalTo(myType));
}
 
Example 6
Source File: ConvertingEncoderDecoderSupportTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void decodeFromBinary() throws Exception {
	Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
	assertThat(decoder.willDecode(CONVERTED_BYTES), is(true));
	assertThat(decoder.decode(CONVERTED_BYTES), equalTo(myType));
}
 
Example 7
Source File: ConvertingEncoderDecoderSupportTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void decodeFromBinary() throws Exception {
	Decoder.Binary<MyType> decoder = new MyBinaryDecoder();
	assertThat(decoder.willDecode(CONVERTED_BYTES), is(true));
	assertThat(decoder.decode(CONVERTED_BYTES), equalTo(myType));
}