View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  package org.eclipse.jetty.websocket.jsr356.encoders;
20  
21  import java.nio.ByteBuffer;
22  
23  import org.eclipse.jetty.websocket.jsr356.MessageType;
24  import org.eclipse.jetty.websocket.jsr356.metadata.EncoderMetadataSet;
25  
26  public class PrimitiveEncoderMetadataSet extends EncoderMetadataSet
27  {
28      public static final EncoderMetadataSet INSTANCE = new PrimitiveEncoderMetadataSet();
29  
30      public PrimitiveEncoderMetadataSet()
31      {
32          boolean streamed = false;
33          // TEXT based - Classes Based
34          MessageType msgType = MessageType.TEXT;
35          register(Boolean.class,BooleanEncoder.class,msgType,streamed);
36          register(Byte.class,ByteEncoder.class,msgType,streamed);
37          register(Character.class,CharacterEncoder.class,msgType,streamed);
38          register(Double.class,DoubleEncoder.class,msgType,streamed);
39          register(Float.class,FloatEncoder.class,msgType,streamed);
40          register(Integer.class,IntegerEncoder.class,msgType,streamed);
41          register(Long.class,LongEncoder.class,msgType,streamed);
42          register(Short.class,ShortEncoder.class,msgType,streamed);
43          register(String.class,StringEncoder.class,msgType,streamed);
44  
45          // TEXT based - Primitive Types
46          msgType = MessageType.TEXT;
47          register(Boolean.TYPE,BooleanEncoder.class,msgType,streamed);
48          register(Byte.TYPE,ByteEncoder.class,msgType,streamed);
49          register(Character.TYPE,CharacterEncoder.class,msgType,streamed);
50          register(Double.TYPE,DoubleEncoder.class,msgType,streamed);
51          register(Float.TYPE,FloatEncoder.class,msgType,streamed);
52          register(Integer.TYPE,IntegerEncoder.class,msgType,streamed);
53          register(Long.TYPE,LongEncoder.class,msgType,streamed);
54          register(Short.TYPE,ShortEncoder.class,msgType,streamed);
55  
56          // BINARY based
57          msgType = MessageType.BINARY;
58          register(ByteBuffer.class,ByteBufferEncoder.class,msgType,streamed);
59          register(byte[].class,ByteArrayEncoder.class,msgType,streamed);
60  
61      }
62  }