Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
<suppress checks="AbbreviationAsWordInName" files="."/>
<suppress checks="LineLength" files="."/>
<suppress checks="VariableDeclarationUsageDistance" files="."/>
</suppressions>
<suppress checks="OverloadMethodsDeclarationOrder" files="."/>
<suppress checks="NonEmptyAtclauseDescription" files="."/>
<suppress checks="TypeName" files="Draft_6455.java"/>
<suppress checks="RightCurly" files="Base64.java"/>
</suppressions>
3 changes: 2 additions & 1 deletion src/main/java/org/java_websocket/SocketChannelIOHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public static boolean batch(WebSocketImpl ws, ByteChannel sockchannel) throws IO
}
}
} else {
do {// FIXME writing as much as possible is unfair!!
do {
// FIXME writing as much as possible is unfair!!
/*int written = */
sockchannel.write(buffer);
if (buffer.remaining() > 0) {
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/org/java_websocket/WebSocketImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ public WebSocketImpl(WebSocketListener listener, List<Draft> drafts) {
* @param draft The draft which should be used
*/
public WebSocketImpl(WebSocketListener listener, Draft draft) {
if (listener == null || (draft == null && role
== Role.SERVER))// socket can be null because we want do be able to create the object without already having a bound channel
{
// socket can be null because we want do be able to create the object without already having a bound channel
if (listener == null || (draft == null && role == Role.SERVER)) {
throw new IllegalArgumentException("parameters must not be null");
}
this.outQueue = new LinkedBlockingQueue<ByteBuffer>();
Expand Down
33 changes: 15 additions & 18 deletions src/main/java/org/java_websocket/drafts/Draft_6455.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,12 @@ public HandshakeBuilder postProcessHandshakeResponseAsServer(ClientHandshake req
@Override
public Draft copyInstance() {
ArrayList<IExtension> newExtensions = new ArrayList<IExtension>();
for (IExtension iExtension : getKnownExtensions()) {
newExtensions.add(iExtension.copyInstance());
for (IExtension extension : getKnownExtensions()) {
newExtensions.add(extension.copyInstance());
}
ArrayList<IProtocol> newProtocols = new ArrayList<IProtocol>();
for (IProtocol iProtocol : getKnownProtocols()) {
newProtocols.add(iProtocol.copyInstance());
for (IProtocol protocol : getKnownProtocols()) {
newProtocols.add(protocol.copyInstance());
}
return new Draft_6455(newExtensions, newProtocols, maxFrameSize);
}
Expand Down Expand Up @@ -589,8 +589,8 @@ private Framedata translateSingleFrame(ByteBuffer buffer)
private TranslatedPayloadMetaData translateSingleFramePayloadLength(ByteBuffer buffer,
Opcode optcode, int oldPayloadlength, int maxpacketsize, int oldRealpacketsize)
throws InvalidFrameException, IncompleteException, LimitExceededException {
int payloadlength = oldPayloadlength,
realpacketsize = oldRealpacketsize;
int payloadlength = oldPayloadlength;
int realpacketsize = oldRealpacketsize;
if (optcode == Opcode.PING || optcode == Opcode.PONG || optcode == Opcode.CLOSING) {
log.trace("Invalid frame: more than 125 octets");
throw new InvalidFrameException("more than 125 octets");
Expand Down Expand Up @@ -660,19 +660,16 @@ private void translateSingleFrameCheckPacketSize(int maxpacketsize, int realpack
* @return byte that represents which RSV bit is set.
*/
private byte getRSVByte(int rsv) {
if (rsv == 1) // 0100 0000
{
return 0x40;
}
if (rsv == 2) // 0010 0000
{
return 0x20;
}
if (rsv == 3) // 0001 0000
{
return 0x10;
switch (rsv) {
case 1 : // 0100 0000
return 0x40;
case 2 : // 0010 0000
return 0x20;
case 3 : // 0001 0000
return 0x10;
default:
return 0;
}
return 0;
}

/**
Expand Down
34 changes: 17 additions & 17 deletions src/main/java/org/java_websocket/server/WebSocketServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,17 +361,17 @@ public void run() {
return;
}
try {
int iShutdownCount = 5;
int shutdownCount = 5;
int selectTimeout = 0;
while (!selectorthread.isInterrupted() && iShutdownCount != 0) {
while (!selectorthread.isInterrupted() && shutdownCount != 0) {
SelectionKey key = null;
try {
if (isclosed.get()) {
selectTimeout = 5;
}
int keyCount = selector.select(selectTimeout);
if (keyCount == 0 && isclosed.get()) {
iShutdownCount--;
shutdownCount--;
}
Set<SelectionKey> keys = selector.selectedKeys();
Iterator<SelectionKey> i = keys.iterator();
Expand Down Expand Up @@ -993,15 +993,15 @@ public void broadcast(String text, Collection<WebSocket> clients) {
* @param clients the clients to send the message to
*/
private void doBroadcast(Object data, Collection<WebSocket> clients) {
String sData = null;
String strData = null;
if (data instanceof String) {
sData = (String) data;
strData = (String) data;
}
ByteBuffer bData = null;
ByteBuffer byteData = null;
if (data instanceof ByteBuffer) {
bData = (ByteBuffer) data;
byteData = (ByteBuffer) data;
}
if (sData == null && bData == null) {
if (strData == null && byteData == null) {
return;
}
Map<Draft, List<Framedata>> draftFrames = new HashMap<Draft, List<Framedata>>();
Expand All @@ -1012,7 +1012,7 @@ private void doBroadcast(Object data, Collection<WebSocket> clients) {
for (WebSocket client : clientCopy) {
if (client != null) {
Draft draft = client.getDraft();
fillFrames(draft, draftFrames, sData, bData);
fillFrames(draft, draftFrames, strData, byteData);
try {
client.sendFrame(draftFrames.get(draft));
} catch (WebsocketNotConnectedException e) {
Expand All @@ -1027,18 +1027,18 @@ private void doBroadcast(Object data, Collection<WebSocket> clients) {
*
* @param draft The draft to use
* @param draftFrames The list of frames per draft to fill
* @param sData the string data, can be null
* @param bData the byte buffer data, can be null
* @param strData the string data, can be null
* @param byteData the byte buffer data, can be null
*/
private void fillFrames(Draft draft, Map<Draft, List<Framedata>> draftFrames, String sData,
ByteBuffer bData) {
private void fillFrames(Draft draft, Map<Draft, List<Framedata>> draftFrames, String strData,
ByteBuffer byteData) {
if (!draftFrames.containsKey(draft)) {
List<Framedata> frames = null;
if (sData != null) {
frames = draft.createFrames(sData, false);
if (strData != null) {
frames = draft.createFrames(strData, false);
}
if (bData != null) {
frames = draft.createFrames(bData, false);
if (byteData != null) {
frames = draft.createFrames(byteData, false);
}
if (frames != null) {
draftFrames.put(draft, frames);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/org/java_websocket/util/Base64.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ private static byte[] encode3to4(
byte[] source, int srcOffset, int numSigBytes,
byte[] destination, int destOffset, int options) {

byte[] ALPHABET = getAlphabet(options);
final byte[] ALPHABET = getAlphabet(options);

// 1 2 3
// 01234567890123456789012345678901 Bit position
Expand Down Expand Up @@ -691,18 +691,21 @@ public static byte[] encodeBytesToBytes(byte[] source, int off, int len, int opt
gzos.close();
}
} catch (Exception e) {
// do nothing
}
try {
if (b64os != null) {
b64os.close();
}
} catch (Exception e) {
// do nothing
}
try {
if (baos != null) {
baos.close();
}
} catch (Exception e) {
// do nothing
}
} // end finally

Expand Down Expand Up @@ -818,7 +821,7 @@ private static int decode4to3(
destination.length, destOffset));
} // end if

byte[] DECODABET = getDecodabet(options);
final byte[] DECODABET = getDecodabet(options);

// Example: Dk==
if (source[srcOffset + 2] == EQUALS_SIGN) {
Expand Down