Skip to content

Commit 954ab37

Browse files
authored
Merge pull request #571 from marci4/master
Code cleanups
2 parents 739375e + dc1204e commit 954ab37

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

src/main/example/ChatServer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.io.InputStreamReader;
2929
import java.net.InetSocketAddress;
3030
import java.net.UnknownHostException;
31-
import java.util.Collection;
31+
import java.nio.ByteBuffer;
3232

3333
import org.java_websocket.WebSocket;
3434
import org.java_websocket.WebSocketImpl;
@@ -66,6 +66,12 @@ public void onMessage( WebSocket conn, String message ) {
6666
broadcast( message );
6767
System.out.println( conn + ": " + message );
6868
}
69+
@Override
70+
public void onMessage( WebSocket conn, ByteBuffer message ) {
71+
broadcast( message.array() );
72+
System.out.println( conn + ": " + message );
73+
}
74+
6975

7076
@Override
7177
public void onFragment( WebSocket conn, Framedata fragment ) {

src/main/example/ExampleClient.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ public void onMessage( String message ) {
5454
System.out.println( "received: " + message );
5555
}
5656

57-
@Override
58-
public void onFragment( Framedata fragment ) {
59-
System.out.println( "received fragment: " + new String( fragment.getPayloadData().array() ) );
60-
}
61-
6257
@Override
6358
public void onClose( int code, String reason, boolean remote ) {
6459
// The codecodes are documented in class org.java_websocket.framing.CloseFrame

src/main/java/org/java_websocket/WebSocketAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer( WebSocket co
5555

5656
@Override
5757
public void onWebsocketHandshakeReceivedAsClient( WebSocket conn, ClientHandshake request, ServerHandshake response ) throws InvalidDataException {
58+
//To overwrite
5859
}
5960

6061
/**
@@ -64,6 +65,7 @@ public void onWebsocketHandshakeReceivedAsClient( WebSocket conn, ClientHandshak
6465
*/
6566
@Override
6667
public void onWebsocketHandshakeSentAsClient( WebSocket conn, ClientHandshake request ) throws InvalidDataException {
68+
//To overwrite
6769
}
6870

6971
/**
@@ -72,7 +74,9 @@ public void onWebsocketHandshakeSentAsClient( WebSocket conn, ClientHandshake re
7274
* @see org.java_websocket.WebSocketListener#onWebsocketMessageFragment(WebSocket, Framedata)
7375
*/
7476
@Override
77+
@Deprecated
7578
public void onWebsocketMessageFragment( WebSocket conn, Framedata frame ) {
79+
//To overwrite
7680
}
7781

7882
/**
@@ -93,6 +97,7 @@ public void onWebsocketPing( WebSocket conn, Framedata f ) {
9397
*/
9498
@Override
9599
public void onWebsocketPong( WebSocket conn, Framedata f ) {
100+
//To overwrite
96101
}
97102

98103
/**

src/main/java/org/java_websocket/client/WebSocketClient.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,10 @@ private int getPort() {
294294
String scheme = uri.getScheme();
295295
if( "wss".equals( scheme ) ) {
296296
return WebSocket.DEFAULT_WSS_PORT;
297-
} else if( scheme.equals( "ws" ) ) {
297+
} else if( "ws".equals( scheme ) ) {
298298
return WebSocket.DEFAULT_PORT;
299299
} else {
300-
throw new RuntimeException( "unknown scheme: " + scheme );
300+
throw new IllegalArgumentException( "unknown scheme: " + scheme );
301301
}
302302
}
303303
return port;
@@ -411,6 +411,7 @@ public void onWebsocketClosing( WebSocket conn, int code, String reason, boolean
411411
* @param reason Additional information string
412412
*/
413413
public void onCloseInitiated( int code, String reason ) {
414+
//To overwrite
414415
}
415416

416417
/** Called as soon as no further frames are accepted
@@ -420,6 +421,7 @@ public void onCloseInitiated( int code, String reason ) {
420421
* @param remote Returns whether or not the closing of the connection was initiated by the remote host.
421422
*/
422423
public void onClosing( int code, String reason, boolean remote ) {
424+
//To overwrite
423425
}
424426

425427
/**
@@ -450,8 +452,11 @@ public InetSocketAddress getRemoteSocketAddress( WebSocket conn ) {
450452
public abstract void onClose( int code, String reason, boolean remote );
451453
public abstract void onError( Exception ex );
452454
public void onMessage( ByteBuffer bytes ) {
455+
//To overwrite
453456
}
457+
@Deprecated
454458
public void onFragment( Framedata frame ) {
459+
//To overwrite
455460
}
456461

457462
private class WebsocketWriteThread implements Runnable {

src/main/java/org/java_websocket/handshake/HandshakeImpl1Client.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
public class HandshakeImpl1Client extends HandshakedataImpl1 implements ClientHandshakeBuilder {
2929
private String resourceDescriptor = "*";
3030

31-
public HandshakeImpl1Client() {
32-
}
33-
3431
public void setResourceDescriptor( String resourceDescriptor ) throws IllegalArgumentException {
3532
if(resourceDescriptor==null)
3633
throw new IllegalArgumentException( "http resource descriptor must not be null" );

src/main/java/org/java_websocket/handshake/HandshakeImpl1Server.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public class HandshakeImpl1Server extends HandshakedataImpl1 implements ServerHa
2929
private short httpstatus;
3030
private String httpstatusmessage;
3131

32-
public HandshakeImpl1Server() {
33-
}
34-
3532
@Override
3633
public String getHttpStatusMessage() {
3734
return httpstatusmessage;

0 commit comments

Comments
 (0)