View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2013 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.decoders;
20  
21  import java.io.InputStream;
22  import java.io.Reader;
23  import java.nio.ByteBuffer;
24  
25  import org.eclipse.jetty.websocket.jsr356.MessageType;
26  import org.eclipse.jetty.websocket.jsr356.metadata.DecoderMetadataSet;
27  
28  public class PrimitiveDecoderMetadataSet extends DecoderMetadataSet
29  {
30      public static final DecoderMetadataSet INSTANCE = new PrimitiveDecoderMetadataSet();
31  
32      public PrimitiveDecoderMetadataSet()
33      {
34          boolean streamed = false;
35          // TEXT based - Classes Based
36          MessageType msgType = MessageType.TEXT;
37          register(Boolean.class,BooleanDecoder.class,msgType,streamed);
38          register(Byte.class,ByteDecoder.class,msgType,streamed);
39          register(Character.class,CharacterDecoder.class,msgType,streamed);
40          register(Double.class,DoubleDecoder.class,msgType,streamed);
41          register(Float.class,FloatDecoder.class,msgType,streamed);
42          register(Integer.class,IntegerDecoder.class,msgType,streamed);
43          register(Long.class,LongDecoder.class,msgType,streamed);
44          register(Short.class,ShortDecoder.class,msgType,streamed);
45          register(String.class,StringDecoder.class,msgType,streamed);
46  
47          // TEXT based - Primitive Types
48          msgType = MessageType.TEXT;
49          register(Boolean.TYPE,BooleanDecoder.class,msgType,streamed);
50          register(Byte.TYPE,ByteDecoder.class,msgType,streamed);
51          register(Character.TYPE,CharacterDecoder.class,msgType,streamed);
52          register(Double.TYPE,DoubleDecoder.class,msgType,streamed);
53          register(Float.TYPE,FloatDecoder.class,msgType,streamed);
54          register(Integer.TYPE,IntegerDecoder.class,msgType,streamed);
55          register(Long.TYPE,LongDecoder.class,msgType,streamed);
56          register(Short.TYPE,ShortDecoder.class,msgType,streamed);
57  
58          // BINARY based
59          msgType = MessageType.BINARY;
60          register(ByteBuffer.class,ByteBufferDecoder.class,msgType,streamed);
61          register(byte[].class,ByteArrayDecoder.class,msgType,streamed);
62  
63          // STREAMING based
64          streamed = true;
65          msgType = MessageType.TEXT;
66          register(Reader.class,ReaderDecoder.class,msgType,streamed);
67          msgType = MessageType.BINARY;
68          register(InputStream.class,InputStreamDecoder.class,msgType,streamed);
69      }
70  }