|
12 | 12 | import org.java_websocket.exceptions.InvalidHandshakeException; |
13 | 13 | import org.java_websocket.exceptions.LimitExedeedException; |
14 | 14 | import org.java_websocket.framing.CloseFrame; |
| 15 | +import org.java_websocket.framing.FrameBuilder; |
15 | 16 | import org.java_websocket.framing.Framedata; |
| 17 | +import org.java_websocket.framing.Framedata.Opcode; |
| 18 | +import org.java_websocket.framing.FramedataImpl1; |
16 | 19 | import org.java_websocket.handshake.ClientHandshake; |
17 | 20 | import org.java_websocket.handshake.ClientHandshakeBuilder; |
18 | 21 | import org.java_websocket.handshake.HandshakeBuilder; |
@@ -46,6 +49,8 @@ public enum CloseHandshakeType { |
46 | 49 | /** In some cases the handshake will be parsed different depending on whether */ |
47 | 50 | protected Role role = null; |
48 | 51 |
|
| 52 | + protected Opcode continuousFrameType = null; |
| 53 | + |
49 | 54 | public static ByteBuffer readLine( ByteBuffer buf ) { |
50 | 55 | ByteBuffer sbuf = ByteBuffer.allocate( buf.remaining() ); |
51 | 56 | byte prev = '0'; |
@@ -123,6 +128,34 @@ protected boolean basicAccept( Handshakedata handshakedata ) { |
123 | 128 |
|
124 | 129 | public abstract List<Framedata> createFrames( String text, boolean mask ); |
125 | 130 |
|
| 131 | + public List<Framedata> continuousFrame( Opcode op, ByteBuffer buffer, boolean fin ) { |
| 132 | + if( op != Opcode.BINARY && op != Opcode.TEXT && op != Opcode.TEXT ) { |
| 133 | + throw new IllegalArgumentException( "Only Opcode.BINARY or Opcode.TEXT are allowed" ); |
| 134 | + } |
| 135 | + |
| 136 | + if( continuousFrameType != null ) { |
| 137 | + continuousFrameType = Opcode.CONTINUOUS; |
| 138 | + } else if( fin ) { |
| 139 | + throw new IllegalArgumentException( "There is no continious frame to continue" ); |
| 140 | + } else { |
| 141 | + continuousFrameType = op; |
| 142 | + } |
| 143 | + |
| 144 | + FrameBuilder bui = new FramedataImpl1( continuousFrameType ); |
| 145 | + try { |
| 146 | + bui.setPayload( buffer ); |
| 147 | + } catch ( InvalidDataException e ) { |
| 148 | + throw new RuntimeException( e ); // can only happen when one builds close frames(Opcode.Close) |
| 149 | + } |
| 150 | + bui.setFin( fin ); |
| 151 | + if( fin ) { |
| 152 | + continuousFrameType = null; |
| 153 | + } else { |
| 154 | + continuousFrameType = op; |
| 155 | + } |
| 156 | + return Collections.singletonList( (Framedata) bui ); |
| 157 | + } |
| 158 | + |
126 | 159 | public abstract void reset(); |
127 | 160 |
|
128 | 161 | public List<ByteBuffer> createHandshake( Handshakedata handshakedata, Role ownrole ) { |
|
0 commit comments