d) {
44 | return new WebSocketImpl( a, d );
45 | }
46 | @Override
47 | public SocketChannel wrapChannel( SocketChannel channel, SelectionKey key ) {
48 | return channel;
49 | }
50 | @Override
51 | public void close() {
52 | //Nothing to do for a normal ws factory
53 | }
54 | }
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_ws/framing/ControlFrame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_ws.framing;
27 |
28 | import org.java_ws.enums.Opcode;
29 | import org.java_ws.exceptions.InvalidDataException;
30 | import org.java_ws.exceptions.InvalidFrameException;
31 |
32 | /**
33 | * Abstract class to represent control frames
34 | */
35 | public abstract class ControlFrame extends FramedataImpl1 {
36 |
37 | /**
38 | * Class to represent a control frame
39 | * @param opcode the opcode to use
40 | */
41 | public ControlFrame( Opcode opcode ) {
42 | super( opcode );
43 | }
44 |
45 | @Override
46 | public void isValid() throws InvalidDataException {
47 | if( !isFin() ) {
48 | throw new InvalidFrameException( "Control frame cant have fin==false set" );
49 | }
50 | if( isRSV1() ) {
51 | throw new InvalidFrameException( "Control frame cant have rsv1==true set" );
52 | }
53 | if( isRSV2() ) {
54 | throw new InvalidFrameException( "Control frame cant have rsv2==true set" );
55 | }
56 | if( isRSV3() ) {
57 | throw new InvalidFrameException( "Control frame cant have rsv3==true set" );
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_ws/exceptions/NotSendableException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_ws.exceptions;
27 |
28 | /**
29 | * exception which indicates the frame payload is not sendable
30 | */
31 | public class NotSendableException extends RuntimeException {
32 |
33 | /**
34 | * Serializable
35 | */
36 | private static final long serialVersionUID = -6468967874576651628L;
37 |
38 | /**
39 | * constructor for a NotSendableException
40 | *
41 | * @param s the detail message.
42 | */
43 | public NotSendableException(String s) {
44 | super(s);
45 | }
46 |
47 | /**
48 | * constructor for a NotSendableException
49 | *
50 | * @param t the throwable causing this exception.
51 | */
52 | public NotSendableException(Throwable t) {
53 | super(t);
54 | }
55 |
56 | /**
57 | * constructor for a NotSendableException
58 | *
59 | * @param s the detail message.
60 | * @param t the throwable causing this exception.
61 | */
62 | public NotSendableException(String s, Throwable t) {
63 | super(s, t);
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_websocket/exceptions/NotSendableException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_websocket.exceptions;
27 |
28 | /**
29 | * exception which indicates the frame payload is not sendable
30 | */
31 | public class NotSendableException extends RuntimeException {
32 |
33 | /**
34 | * Serializable
35 | */
36 | private static final long serialVersionUID = -6468967874576651628L;
37 |
38 | /**
39 | * constructor for a NotSendableException
40 | *
41 | * @param s the detail message.
42 | */
43 | public NotSendableException(String s) {
44 | super(s);
45 | }
46 |
47 | /**
48 | * constructor for a NotSendableException
49 | *
50 | * @param t the throwable causing this exception.
51 | */
52 | public NotSendableException(Throwable t) {
53 | super(t);
54 | }
55 |
56 | /**
57 | * constructor for a NotSendableException
58 | *
59 | * @param s the detail message.
60 | * @param t the throwable causing this exception.
61 | */
62 | public NotSendableException(String s, Throwable t) {
63 | super(s, t);
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_websocket/framing/ControlFrame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_websocket.framing;
27 |
28 | import org.java_websocket.enums.Opcode;
29 | import org.java_websocket.exceptions.InvalidDataException;
30 | import org.java_websocket.exceptions.InvalidFrameException;
31 |
32 | /**
33 | * Abstract class to represent control frames
34 | */
35 | public abstract class ControlFrame extends FramedataImpl1 {
36 |
37 | /**
38 | * Class to represent a control frame
39 | * @param opcode the opcode to use
40 | */
41 | public ControlFrame( Opcode opcode ) {
42 | super( opcode );
43 | }
44 |
45 | @Override
46 | public void isValid() throws InvalidDataException {
47 | if( !isFin() ) {
48 | throw new InvalidFrameException( "Control frame cant have fin==false set" );
49 | }
50 | if( isRSV1() ) {
51 | throw new InvalidFrameException( "Control frame cant have rsv1==true set" );
52 | }
53 | if( isRSV2() ) {
54 | throw new InvalidFrameException( "Control frame cant have rsv2==true set" );
55 | }
56 | if( isRSV3() ) {
57 | throw new InvalidFrameException( "Control frame cant have rsv3==true set" );
58 | }
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_ws/extensions/CompressionExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_ws.extensions;
27 |
28 | import org.java_ws.exceptions.InvalidDataException;
29 | import org.java_ws.exceptions.InvalidFrameException;
30 | import org.java_ws.framing.ControlFrame;
31 | import org.java_ws.framing.DataFrame;
32 | import org.java_ws.framing.Framedata;
33 |
34 | /**
35 | * Implementation for a compression extension specified by https://tools.ietf.org/html/rfc7692
36 | * @since 1.3.5
37 | */
38 | public abstract class CompressionExtension extends DefaultExtension {
39 |
40 | @Override
41 | public void isFrameValid( Framedata inputFrame ) throws InvalidDataException {
42 | if(( inputFrame instanceof DataFrame ) && ( inputFrame.isRSV2() || inputFrame.isRSV3() )) {
43 | throw new InvalidFrameException( "bad rsv RSV1: " + inputFrame.isRSV1() + " RSV2: " + inputFrame.isRSV2() + " RSV3: " + inputFrame.isRSV3() );
44 | }
45 | if(( inputFrame instanceof ControlFrame ) && ( inputFrame.isRSV1() || inputFrame.isRSV2() || inputFrame.isRSV3() )) {
46 | throw new InvalidFrameException( "bad rsv RSV1: " + inputFrame.isRSV1() + " RSV2: " + inputFrame.isRSV2() + " RSV3: " + inputFrame.isRSV3() );
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_websocket/extensions/CompressionExtension.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_websocket.extensions;
27 |
28 | import org.java_websocket.exceptions.InvalidDataException;
29 | import org.java_websocket.exceptions.InvalidFrameException;
30 | import org.java_websocket.framing.ControlFrame;
31 | import org.java_websocket.framing.DataFrame;
32 | import org.java_websocket.framing.Framedata;
33 |
34 | /**
35 | * Implementation for a compression extension specified by https://tools.ietf.org/html/rfc7692
36 | * @since 1.3.5
37 | */
38 | public abstract class CompressionExtension extends DefaultExtension {
39 |
40 | @Override
41 | public void isFrameValid( Framedata inputFrame ) throws InvalidDataException {
42 | if(( inputFrame instanceof DataFrame ) && ( inputFrame.isRSV2() || inputFrame.isRSV3() )) {
43 | throw new InvalidFrameException( "bad rsv RSV1: " + inputFrame.isRSV1() + " RSV2: " + inputFrame.isRSV2() + " RSV3: " + inputFrame.isRSV3() );
44 | }
45 | if(( inputFrame instanceof ControlFrame ) && ( inputFrame.isRSV1() || inputFrame.isRSV2() || inputFrame.isRSV3() )) {
46 | throw new InvalidFrameException( "bad rsv RSV1: " + inputFrame.isRSV1() + " RSV2: " + inputFrame.isRSV2() + " RSV3: " + inputFrame.isRSV3() );
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/exoplayer/src/main/assets/simple.json:
--------------------------------------------------------------------------------
1 | {"v":"4.11.1","fr":60,"ip":0,"op":68,"w":1920,"h":1080,"nm":"Comp 9","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 2","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"n":["0p667_1_0p333_0"],"t":0,"s":[0],"e":[360]},{"t":60}],"ix":10},"p":{"a":0,"k":[926,542,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[94.718,102.5,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[590.451,561.677],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"tm","s":{"a":0,"k":99.5,"ix":1},"e":{"a":0,"k":100,"ix":2},"o":{"a":0,"k":1,"ix":3},"m":1,"ix":2,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false},{"ty":"st","c":{"a":0,"k":[0.066178865731,0.826732218266,0.973008573055,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":75,"ix":5},"lc":2,"lj":2,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[35.211,-11.951],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 2","np":4,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":68,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"n":["0p667_1_0p333_0"],"t":0,"s":[0],"e":[-359]},{"t":60}],"ix":10},"p":{"a":0,"k":[962,540,0],"ix":2},"a":{"a":0,"k":[0,0,0],"ix":1},"s":{"a":0,"k":[100,100,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"rc","d":1,"s":{"a":0,"k":[116.344,347.531],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"r":{"a":0,"k":62,"ix":4},"nm":"Rectangle Path 1","mn":"ADBE Vector Shape - Rect","hd":false},{"ty":"gf","o":{"a":0,"k":100,"ix":10},"r":1,"g":{"p":3,"k":{"a":0,"k":[0.01,0.782,0.294,0.982,0.505,0.502,0.55,0.944,1,0.223,0.806,0.905],"ix":9}},"s":{"a":0,"k":[4.148,-124.836],"ix":5},"e":{"a":0,"k":[7.484,100.289],"ix":6},"t":1,"nm":"Gradient Fill 1","mn":"ADBE Vector Graphic - G-Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[-5.984,-11.859],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Rectangle 1","np":3,"cix":2,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":68,"st":0,"bm":0}]}
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_ws/exceptions/IncompleteHandshakeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_ws.exceptions;
27 |
28 | /**
29 | * exception which indicates that a incomplete handshake was recieved
30 | */
31 | public class IncompleteHandshakeException extends RuntimeException {
32 |
33 | /**
34 | * Serializable
35 | */
36 | private static final long serialVersionUID = 7906596804233893092L;
37 |
38 | /**
39 | * attribut which size of handshake would have been prefered
40 | */
41 | private final int preferredSize;
42 |
43 | /**
44 | * constructor for a IncompleteHandshakeException
45 | *
46 | * @param preferredSize the prefered size
47 | */
48 | public IncompleteHandshakeException(int preferredSize) {
49 | this.preferredSize = preferredSize;
50 | }
51 |
52 | /**
53 | * constructor for a IncompleteHandshakeException
54 | *
55 | * preferredSize will be 0
56 | */
57 | public IncompleteHandshakeException() {
58 | this.preferredSize = 0;
59 | }
60 |
61 | /**
62 | * Getter preferredSize
63 | *
64 | * @return the preferredSize
65 | */
66 | public int getPreferredSize() {
67 | return preferredSize;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_websocket/exceptions/IncompleteHandshakeException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_websocket.exceptions;
27 |
28 | /**
29 | * exception which indicates that a incomplete handshake was recieved
30 | */
31 | public class IncompleteHandshakeException extends RuntimeException {
32 |
33 | /**
34 | * Serializable
35 | */
36 | private static final long serialVersionUID = 7906596804233893092L;
37 |
38 | /**
39 | * attribut which size of handshake would have been prefered
40 | */
41 | private final int preferredSize;
42 |
43 | /**
44 | * constructor for a IncompleteHandshakeException
45 | *
46 | * @param preferredSize the prefered size
47 | */
48 | public IncompleteHandshakeException(int preferredSize) {
49 | this.preferredSize = preferredSize;
50 | }
51 |
52 | /**
53 | * constructor for a IncompleteHandshakeException
54 | *
55 | * preferredSize will be 0
56 | */
57 | public IncompleteHandshakeException() {
58 | this.preferredSize = 0;
59 | }
60 |
61 | /**
62 | * Getter preferredSize
63 | *
64 | * @return the preferredSize
65 | */
66 | public int getPreferredSize() {
67 | return preferredSize;
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_ws/util/ByteBufferUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_ws.util;
27 |
28 | import java.nio.ByteBuffer;
29 |
30 | /**
31 | * Utility class for ByteBuffers
32 | */
33 | public class ByteBufferUtils {
34 |
35 | /**
36 | * Private constructor for static class
37 | */
38 | private ByteBufferUtils() {
39 | }
40 |
41 | /**
42 | * Transfer from one ByteBuffer to another ByteBuffer
43 | *
44 | * @param source the ByteBuffer to copy from
45 | * @param dest the ByteBuffer to copy to
46 | * @return the number of transferred bytes
47 | */
48 | public static int transferByteBuffer( ByteBuffer source, ByteBuffer dest ) {
49 | if( source == null || dest == null ) {
50 | throw new IllegalArgumentException();
51 | }
52 | int fremain = source.remaining();
53 | int toremain = dest.remaining();
54 | if( fremain > toremain ) {
55 | int limit = Math.min( fremain, toremain );
56 | source.limit( limit );
57 | dest.put( source );
58 | return limit;
59 | } else {
60 | dest.put( source );
61 | return fremain;
62 | }
63 | }
64 |
65 | /**
66 | * Get a ByteBuffer with zero capacity
67 | *
68 | * @return empty ByteBuffer
69 | */
70 | public static ByteBuffer getEmptyByteBuffer() {
71 | return ByteBuffer.allocate( 0 );
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_websocket/util/ByteBufferUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_websocket.util;
27 |
28 | import java.nio.ByteBuffer;
29 |
30 | /**
31 | * Utility class for ByteBuffers
32 | */
33 | public class ByteBufferUtils {
34 |
35 | /**
36 | * Private constructor for static class
37 | */
38 | private ByteBufferUtils() {
39 | }
40 |
41 | /**
42 | * Transfer from one ByteBuffer to another ByteBuffer
43 | *
44 | * @param source the ByteBuffer to copy from
45 | * @param dest the ByteBuffer to copy to
46 | * @return the number of transferred bytes
47 | */
48 | public static int transferByteBuffer( ByteBuffer source, ByteBuffer dest ) {
49 | if( source == null || dest == null ) {
50 | throw new IllegalArgumentException();
51 | }
52 | int fremain = source.remaining();
53 | int toremain = dest.remaining();
54 | if( fremain > toremain ) {
55 | int limit = Math.min( fremain, toremain );
56 | source.limit( limit );
57 | dest.put( source );
58 | return limit;
59 | } else {
60 | dest.put( source );
61 | return fremain;
62 | }
63 | }
64 |
65 | /**
66 | * Get a ByteBuffer with zero capacity
67 | *
68 | * @return empty ByteBuffer
69 | */
70 | public static ByteBuffer getEmptyByteBuffer() {
71 | return ByteBuffer.allocate( 0 );
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_ws/WebSocketServerFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_ws;
27 |
28 | import org.java_ws.drafts.Draft;
29 |
30 | import java.io.IOException;
31 | import java.nio.channels.ByteChannel;
32 | import java.nio.channels.SelectionKey;
33 | import java.nio.channels.SocketChannel;
34 | import java.util.List;
35 |
36 | /**
37 | * Interface to encapsulate the required methods for a websocket factory
38 | */
39 | public interface WebSocketServerFactory extends WebSocketFactory {
40 | @Override
41 | WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d);
42 |
43 | @Override
44 | WebSocketImpl createWebSocket( WebSocketAdapter a, List drafts );
45 |
46 | /**
47 | * Allows to wrap the Socketchannel( key.channel() ) to insert a protocol layer( like ssl or proxy authentication) beyond the ws layer.
48 | *
49 | * @param channel The SocketChannel to wrap
50 | * @param key a SelectionKey of an open SocketChannel.
51 | * @return The channel on which the read and write operations will be performed.
52 | * @throws IOException may be thrown while writing on the channel
53 | */
54 | ByteChannel wrapChannel(SocketChannel channel, SelectionKey key ) throws IOException;
55 |
56 | /**
57 | * Allows to shutdown the websocket factory for a clean shutdown
58 | */
59 | void close();
60 | }
61 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_websocket/WebSocketServerFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_websocket;
27 |
28 | import org.java_websocket.drafts.Draft;
29 |
30 | import java.io.IOException;
31 | import java.nio.channels.ByteChannel;
32 | import java.nio.channels.SelectionKey;
33 | import java.nio.channels.SocketChannel;
34 | import java.util.List;
35 |
36 | /**
37 | * Interface to encapsulate the required methods for a websocket factory
38 | */
39 | public interface WebSocketServerFactory extends WebSocketFactory {
40 | @Override
41 | WebSocketImpl createWebSocket( WebSocketAdapter a, Draft d);
42 |
43 | @Override
44 | WebSocketImpl createWebSocket( WebSocketAdapter a, List drafts );
45 |
46 | /**
47 | * Allows to wrap the Socketchannel( key.channel() ) to insert a protocol layer( like ssl or proxy authentication) beyond the ws layer.
48 | *
49 | * @param channel The SocketChannel to wrap
50 | * @param key a SelectionKey of an open SocketChannel.
51 | * @return The channel on which the read and write operations will be performed.
52 | * @throws IOException may be thrown while writing on the channel
53 | */
54 | ByteChannel wrapChannel(SocketChannel channel, SelectionKey key ) throws IOException;
55 |
56 | /**
57 | * Allows to shutdown the websocket factory for a clean shutdown
58 | */
59 | void close();
60 | }
61 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/com/google/connectlib/ConnectService.java:
--------------------------------------------------------------------------------
1 | package com.google.connectlib;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.os.Handler;
6 | import android.os.IBinder;
7 | import android.os.Message;
8 | import android.support.annotation.Nullable;
9 |
10 | import java.io.IOException;
11 | import java.net.InetSocketAddress;
12 |
13 | public class ConnectService extends Service implements SimpleServer.MessageListener {
14 | private Thread thread;
15 | private SimpleServer server;
16 | private static MessageListener msgListener;
17 |
18 | @Nullable
19 | @Override
20 | public IBinder onBind(Intent intent) {
21 | return null;
22 | }
23 |
24 | @Override
25 | public void onCreate() {
26 | super.onCreate();
27 | if (thread != null) {
28 | thread = null;
29 | }
30 | thread = new Thread() {
31 | @Override
32 | public void run() {
33 | super.run();
34 | server = new SimpleServer(getBaseContext(), new InetSocketAddress(Constants.HOST, Constants.PORT));
35 | server.setMessageListener(ConnectService.this);
36 | server.run();
37 | }
38 | };
39 | thread.start();
40 | }
41 |
42 | private Handler handler = new Handler() {
43 | @Override
44 | public void handleMessage(Message msg) {
45 | super.handleMessage(msg);
46 | if (msgListener != null) {
47 | msgListener.onMessage(msg.obj.toString());
48 | }
49 | }
50 | };
51 |
52 | @Override
53 | public int onStartCommand(Intent intent, int flags, int startId) {
54 | return super.onStartCommand(intent, flags, startId);
55 | }
56 |
57 | @Override
58 | public void onDestroy() {
59 | super.onDestroy();
60 | if (server != null) {
61 | try {
62 | server.stop();
63 | } catch (IOException e) {
64 | e.printStackTrace();
65 | } catch (InterruptedException e) {
66 | e.printStackTrace();
67 | }
68 | }
69 | }
70 |
71 | @Override
72 | public void onMessage(String text) {
73 | Message message = new Message();
74 | message.obj = text;
75 | handler.sendMessage(message);
76 | }
77 |
78 | public static void setMessageListener(MessageListener messageListener) {
79 | msgListener = messageListener;
80 | }
81 |
82 | public interface MessageListener {
83 | void onMessage(String message);
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/app/src/main/java/com/td/exoplayerdemo/adapter/TVListAdapter.java:
--------------------------------------------------------------------------------
1 | package com.td.exoplayerdemo.adapter;
2 |
3 | import android.content.Context;
4 | import android.graphics.Paint;
5 | import android.graphics.Rect;
6 | import android.view.View;
7 | import android.widget.LinearLayout;
8 |
9 | import com.whatjay.recyclerview.adapter.BaseSmartAdapter;
10 | import com.whatjay.recyclerview.viewholder.SmarViewHolder;
11 |
12 | import java.util.List;
13 |
14 | import com.td.exoplayer.utils.Utils;
15 | import com.td.exoplayerdemo.R;
16 |
17 | /**
18 | * Created by office on 2017/8/17.
19 | */
20 |
21 | public class TVListAdapter extends BaseSmartAdapter {
22 | private Context context;
23 | private int currentPosition = 0;
24 | private int currentFocusPosition = 0;
25 | private String type;
26 | private Paint paint;
27 | private Rect rect;
28 | private LinearLayout.LayoutParams layoutParams;
29 | private String title = "";
30 |
31 | public TVListAdapter(Context context, int layoutId, List lists, String type) {
32 | super(context, layoutId, lists);
33 | this.context = context;
34 | this.type = type;
35 | paint = new Paint();
36 | paint.setTextSize(Utils.sp2px(context, 26));
37 | paint.setFakeBoldText(true);
38 | rect = new Rect();
39 | layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
40 | }
41 |
42 | @Override
43 | public void bindData(SmarViewHolder holder, String string) {
44 | paint.getTextBounds(title, 0, title.length(), rect);
45 | layoutParams.width = Utils.dp2px(context, 50) + Utils.dp2px(context, 38);
46 | holder.getView(R.id.ll_list).setLayoutParams(layoutParams);
47 | holder.setText(R.id.tv_tv_name, string);
48 | if (currentPosition == currentFocusPosition && holder.getAdapterPosition() == currentPosition) {
49 | holder.getView(R.id.ll_list).requestFocus();
50 | }
51 | if (holder.getAdapterPosition() == currentPosition) {
52 | holder.setVisible(R.id.v_select);
53 | } else {
54 | holder.getView(R.id.v_select).setVisibility(View.INVISIBLE);
55 | }
56 | if (currentPosition != currentFocusPosition && holder.getAdapterPosition() == currentFocusPosition) {
57 | holder.getView(R.id.ll_list).requestFocus();
58 | }
59 | }
60 |
61 | public void setPosition(int position) {
62 | this.currentPosition = position;
63 | notifyDataSetChanged();
64 | }
65 |
66 | public void setCurrentFocusPosition(int position) {
67 | this.currentFocusPosition = position;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
35 |
38 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
50 |
51 |
54 |
57 |
58 |
59 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_ws/handshake/HandshakedataImpl1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_ws.handshake;
27 |
28 | import java.util.Collections;
29 | import java.util.Iterator;
30 | import java.util.TreeMap;
31 |
32 | /**
33 | * Implementation of a handshake builder
34 | */
35 | public class HandshakedataImpl1 implements HandshakeBuilder {
36 |
37 | /**
38 | * Attribute for the content of the handshake
39 | */
40 | private byte[] content;
41 |
42 | /**
43 | * Attribute for the http fields and values
44 | */
45 | private TreeMap map;
46 |
47 | /**
48 | * Constructor for handshake implementation
49 | */
50 | public HandshakedataImpl1() {
51 | map = new TreeMap( String.CASE_INSENSITIVE_ORDER );
52 | }
53 |
54 | @Override
55 | public Iterator iterateHttpFields() {
56 | return Collections.unmodifiableSet( map.keySet() ).iterator();// Safety first
57 | }
58 |
59 | @Override
60 | public String getFieldValue( String name ) {
61 | String s = map.get( name );
62 | if ( s == null ) {
63 | return "";
64 | }
65 | return s;
66 | }
67 |
68 | @Override
69 | public byte[] getContent() {
70 | return content;
71 | }
72 |
73 | @Override
74 | public void setContent( byte[] content ) {
75 | this.content = content;
76 | }
77 |
78 | @Override
79 | public void put( String name, String value ) {
80 | map.put( name, value );
81 | }
82 |
83 | @Override
84 | public boolean hasFieldValue( String name ) {
85 | return map.containsKey( name );
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_websocket/handshake/HandshakedataImpl1.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_websocket.handshake;
27 |
28 | import java.util.Collections;
29 | import java.util.Iterator;
30 | import java.util.TreeMap;
31 |
32 | /**
33 | * Implementation of a handshake builder
34 | */
35 | public class HandshakedataImpl1 implements HandshakeBuilder {
36 |
37 | /**
38 | * Attribute for the content of the handshake
39 | */
40 | private byte[] content;
41 |
42 | /**
43 | * Attribute for the http fields and values
44 | */
45 | private TreeMap map;
46 |
47 | /**
48 | * Constructor for handshake implementation
49 | */
50 | public HandshakedataImpl1() {
51 | map = new TreeMap( String.CASE_INSENSITIVE_ORDER );
52 | }
53 |
54 | @Override
55 | public Iterator iterateHttpFields() {
56 | return Collections.unmodifiableSet( map.keySet() ).iterator();// Safety first
57 | }
58 |
59 | @Override
60 | public String getFieldValue( String name ) {
61 | String s = map.get( name );
62 | if ( s == null ) {
63 | return "";
64 | }
65 | return s;
66 | }
67 |
68 | @Override
69 | public byte[] getContent() {
70 | return content;
71 | }
72 |
73 | @Override
74 | public void setContent( byte[] content ) {
75 | this.content = content;
76 | }
77 |
78 | @Override
79 | public void put( String name, String value ) {
80 | map.put( name, value );
81 | }
82 |
83 | @Override
84 | public boolean hasFieldValue( String name ) {
85 | return map.containsKey( name );
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/connectlib/src/main/java/org/java_ws/WrappedByteChannel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2010-2019 Nathan Rajlich
3 | *
4 | * Permission is hereby granted, free of charge, to any person
5 | * obtaining a copy of this software and associated documentation
6 | * files (the "Software"), to deal in the Software without
7 | * restriction, including without limitation the rights to use,
8 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | * copies of the Software, and to permit persons to whom the
10 | * Software is furnished to do so, subject to the following
11 | * conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be
14 | * included in all copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 | * OTHER DEALINGS IN THE SOFTWARE.
24 | */
25 |
26 | package org.java_ws;
27 |
28 | import java.io.IOException;
29 | import java.nio.ByteBuffer;
30 | import java.nio.channels.ByteChannel;
31 |
32 | public interface WrappedByteChannel extends ByteChannel {
33 | /**
34 | * returns whether writeMore should be called write additional data.
35 |
36 | * @return is a additional write needed
37 | */
38 | boolean isNeedWrite();
39 |
40 | /**
41 | * Gets called when {@link #isNeedWrite()} ()} requires a additional rite
42 | * @throws IOException may be thrown due to an error while writing
43 | */
44 | void writeMore() throws IOException;
45 |
46 | /**
47 | * returns whether readMore should be called to fetch data which has been decoded but not yet been returned.
48 | *
49 | * @see #read(ByteBuffer)
50 | * @see #readMore(ByteBuffer)
51 | * @return is a additional read needed
52 | **/
53 | boolean isNeedRead();
54 | /**
55 | * This function does not read data from the underlying channel at all. It is just a way to fetch data which has already be received or decoded but was but was not yet returned to the user.
56 | * This could be the case when the decoded data did not fit into the buffer the user passed to {@link #read(ByteBuffer)}.
57 | * @param dst the destiny of the read
58 | * @return the amount of remaining data
59 | * @throws IOException when a error occurred during unwrapping
60 | **/
61 | int readMore( ByteBuffer dst ) throws IOException;
62 |
63 | /**
64 | * This function returns the blocking state of the channel
65 | * @return is the channel blocking
66 | */
67 | boolean isBlocking();
68 | }
69 |
--------------------------------------------------------------------------------