Skip to content

Commit b790f77

Browse files
committed
Usage of ByteBufferUtils
1 parent f4f7954 commit b790f77

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

src/main/java/org/java_websocket/WebSocketImpl.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@
3535
* text frames, and receiving frames through an event-based model.
3636
*/
3737
public class WebSocketImpl implements WebSocket {
38-
39-
public static final List<Draft> defaultdraftlist = new ArrayList<Draft>( 1 );
4038
public static int RCVBUF = 16384;
41-
public static/*final*/ boolean DEBUG = false; // must be final in the future in order to take advantage of VM optimization
4239

43-
static {
44-
defaultdraftlist.add( new Draft_6455() );
45-
}
40+
/**
41+
* Activate debug mode for additional infos
42+
*/
43+
public static boolean DEBUG = false; // must be final in the future in order to take advantage of VM optimization
4644

4745
/**
4846
* Queue of buffers that need to be sent to the client.
@@ -70,12 +68,25 @@ public class WebSocketImpl implements WebSocket {
7068
*/
7169
private volatile boolean flushandclosestate = false;
7270
private READYSTATE readystate = READYSTATE.NOT_YET_CONNECTED;
71+
72+
/**
73+
* A list of drafts available for this websocket
74+
*/
7375
private List<Draft> knownDrafts;
7476

77+
/**
78+
* The draft which is used by this websocket
79+
*/
7580
private Draft draft = null;
7681

82+
/**
83+
* The role which this websocket takes in the connection
84+
*/
7785
private Role role;
7886

87+
/**
88+
* The frame which had the opcode Continous set
89+
*/
7990
private Framedata current_continuous_frame = null;
8091

8192
/**
@@ -110,7 +121,8 @@ public WebSocketImpl( WebSocketListener listener, List<Draft> drafts ) {
110121
this.role = Role.SERVER;
111122
// draft.copyInstance will be called when the draft is first needed
112123
if( drafts == null || drafts.isEmpty() ) {
113-
knownDrafts = defaultdraftlist;
124+
knownDrafts = new ArrayList<Draft>();
125+
knownDrafts.add(new Draft_6455());
114126
} else {
115127
knownDrafts = drafts;
116128
}

src/main/java/org/java_websocket/framing/CloseFrameBuilder.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
import org.java_websocket.exceptions.InvalidDataException;
44
import org.java_websocket.exceptions.InvalidFrameException;
5+
import org.java_websocket.util.ByteBufferUtils;
56
import org.java_websocket.util.Charsetfunctions;
67

78
import java.nio.ByteBuffer;
89

910
public class CloseFrameBuilder extends FramedataImpl1 implements CloseFrame {
10-
/**
11-
* Attribute for just an empty ByteBuffer
12-
*/
13-
static final ByteBuffer emptybytebuffer = ByteBuffer.allocate( 0 );
1411

1512
/**
1613
* The close code used in this close frame
@@ -150,7 +147,7 @@ public void setPayload( ByteBuffer payload ) throws InvalidDataException {
150147
@Override
151148
public ByteBuffer getPayloadData() {
152149
if( code == NOCODE )
153-
return emptybytebuffer;
150+
return ByteBufferUtils.getEmptyByteBuffer();
154151
return super.getPayloadData();
155152
}
156153

src/main/java/org/java_websocket/framing/FramedataImpl1.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
import java.util.Arrays;
55

66
import org.java_websocket.exceptions.InvalidDataException;
7-
import org.java_websocket.exceptions.InvalidFrameException;
7+
import org.java_websocket.util.ByteBufferUtils;
88
import org.java_websocket.util.Charsetfunctions;
99

1010
public class FramedataImpl1 implements FrameBuilder {
11-
/**
12-
* Attribute for just an empty array
13-
*/
14-
private static byte[] emptyarray = {};
1511

1612
/**
1713
* Indicates that this is the final fragment in a message.
@@ -44,7 +40,7 @@ public FramedataImpl1() {
4440
*/
4541
public FramedataImpl1( Opcode op ) {
4642
this.optcode = op;
47-
unmaskedpayload = ByteBuffer.wrap( emptyarray );
43+
unmaskedpayload = ByteBufferUtils.getEmptyByteBuffer();
4844
}
4945

5046
/**

0 commit comments

Comments
 (0)