Skip to content

Commit 194418f

Browse files
committed
reformatted source code(trying to split up working copy changes...)
1 parent c1a1bd0 commit 194418f

12 files changed

Lines changed: 241 additions & 277 deletions
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package net.tootallnate.websocket;
22

3-
public interface FrameBuilder extends Framedata{
3+
public interface FrameBuilder extends Framedata {
44

55
public abstract void setFin( boolean fin );
66

@@ -10,5 +10,4 @@ public interface FrameBuilder extends Framedata{
1010

1111
public abstract void setTransferemasked( boolean transferemasked );
1212

13-
1413
}
Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
11
package net.tootallnate.websocket;
22

3-
import java.util.HashMap;
43
import net.tootallnate.websocket.exeptions.InvalidFrameException;
54

65
public interface Framedata {
7-
enum Opcode{
8-
CONTINIOUS,
9-
TEXT,
10-
BINARY,
11-
PING,
12-
PONG,
13-
CLOSING
14-
//more to come
6+
enum Opcode {
7+
CONTINIOUS , TEXT , BINARY , PING , PONG , CLOSING
8+
// more to come
159
}
1610
public boolean isFin();
1711
public boolean getTransfereMasked();
1812
public Opcode getOpcode();
19-
public byte[] getPayloadData();
20-
public abstract void append( Framedata nextframe ) throws InvalidFrameException;
13+
public byte[] getPayloadData();// TODO the separation of the application data and the extension data is yet to be done
14+
public abstract void append( Framedata nextframe ) throws InvalidFrameException;
2115
}

‎src/net/tootallnate/websocket/FramedataImpl1.java‎

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,73 +10,77 @@ public class FramedataImpl1 implements FrameBuilder {
1010
private Opcode optcode;
1111
private ByteBuffer unmaskedpayload;
1212
private boolean transferemasked;
13-
13+
1414
public FramedataImpl1() {
1515
}
16+
1617
public FramedataImpl1( Opcode op ) {
1718
this.optcode = op;
18-
unmaskedpayload = ByteBuffer.wrap ( emptyarray );
19+
unmaskedpayload = ByteBuffer.wrap( emptyarray );
20+
}
21+
22+
public FramedataImpl1( Framedata f ) {
23+
fin = f.isFin();
24+
optcode = f.getOpcode();
25+
unmaskedpayload = ByteBuffer.wrap( f.getPayloadData() );
26+
transferemasked = f.getTransfereMasked();
1927
}
2028

2129
@Override
22-
public boolean isFin( ) {
30+
public boolean isFin() {
2331
return fin;
2432
}
2533

2634
@Override
27-
public Opcode getOpcode( ) {
35+
public Opcode getOpcode() {
2836
return optcode;
2937
}
30-
38+
3139
@Override
32-
public boolean getTransfereMasked( ) {
40+
public boolean getTransfereMasked() {
3341
return transferemasked;
3442
}
3543

3644
@Override
37-
public byte[] getPayloadData( ) {
38-
return unmaskedpayload.array ();
45+
public byte[] getPayloadData() {
46+
return unmaskedpayload.array();
3947
}
40-
4148

4249
@Override
4350
public void setFin( boolean fin ) {
4451
this.fin = fin;
4552
}
46-
4753

4854
@Override
4955
public void setOptcode( Opcode optcode ) {
5056
this.optcode = optcode;
5157
}
52-
58+
5359
@Override
5460
public void setPayload( byte[] payload ) {
55-
unmaskedpayload=ByteBuffer.wrap ( payload );
61+
unmaskedpayload = ByteBuffer.wrap( payload );
5662
}
57-
5863

5964
@Override
6065
public void setTransferemasked( boolean transferemasked ) {
6166
this.transferemasked = transferemasked;
6267
}
6368

64-
6569
@Override
6670
public void append( Framedata nextframe ) throws InvalidFrameException {
67-
if( unmaskedpayload == null ){
68-
unmaskedpayload = ByteBuffer.wrap ( nextframe.getPayloadData () );
69-
}
70-
else{
71-
ByteBuffer tmp = ByteBuffer.allocate ( nextframe.getPayloadData ().length + unmaskedpayload.capacity () );
72-
tmp.put ( unmaskedpayload.array () );
73-
tmp.put ( nextframe.getPayloadData () );
71+
if( unmaskedpayload == null ) {
72+
unmaskedpayload = ByteBuffer.wrap( nextframe.getPayloadData() );
73+
} else {
74+
// TODO might be inefficient. Cosider a global buffer pool
75+
ByteBuffer tmp = ByteBuffer.allocate( nextframe.getPayloadData().length + unmaskedpayload.capacity() );
76+
tmp.put( unmaskedpayload.array() );
77+
tmp.put( nextframe.getPayloadData() );
7478
}
7579
}
76-
80+
7781
@Override
78-
public String toString( ) {
79-
return "Framedata{ optcode:" + getOpcode() + ", fin:" + isFin() + ", masked:" + getTransfereMasked() +", payloadlength:"+unmaskedpayload.limit()+", payload:" + new String ( unmaskedpayload.array () , Draft.UTF8_CHARSET ) + "}" ;
82+
public String toString() {
83+
return "Framedata{ optcode:" + getOpcode() + ", fin:" + isFin() + ", masked:" + getTransfereMasked() + ", payloadlength:" + unmaskedpayload.limit() + "}";
8084
}
8185

8286
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package net.tootallnate.websocket;
22

3-
public interface HandshakeBuilder extends Handshakedata{
3+
public interface HandshakeBuilder extends Handshakedata {
44

55
public abstract void setContent( byte[] content );
66

77
public abstract void setResourceDescriptor( String resourcedescriptor );
8-
8+
99
public abstract void setHttpStatusMessage( String message );
1010

11-
public abstract void put( String name , String value );
11+
public abstract void put( String name, String value );
1212

1313
}

‎src/net/tootallnate/websocket/Handshakedata.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ public interface Handshakedata {
1010
public String getFieldValue( String name );
1111
public boolean hasFieldValue( String name );
1212
public byte[] getContent();
13-
//public boolean isComplete();
13+
// public boolean isComplete();
1414
}
15-

‎src/net/tootallnate/websocket/HandshakedataImpl1.java‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
import java.util.Map;
88

99
public class HandshakedataImpl1 implements HandshakeBuilder {
10-
10+
1111
private String httpstatusmessage;
1212
private String resourcedescriptor;
1313
private byte[] content;
1414
private LinkedHashMap<String,String> map;
15-
15+
1616
public HandshakedataImpl1() {
1717
map = new LinkedHashMap<String,String>();
1818
}
@@ -21,51 +21,52 @@ public HandshakedataImpl1( Handshakedata h ) {
2121
httpstatusmessage = h.getHttpStatusMessage();
2222
resourcedescriptor = h.getResourceDescriptor();
2323
content = h.getContent();
24-
map = new LinkedHashMap<String,String>( );
24+
map = new LinkedHashMap<String,String>();
2525
Iterator<String> it = h.iterateHttpFields();
2626
while ( it.hasNext() ) {
27-
String key = ( String ) it.next();
28-
map.put( key , h.getFieldValue( key ) );
27+
String key = (String) it.next();
28+
map.put( key, h.getFieldValue( key ) );
2929
}
3030
}
3131

3232
@Override
33-
public String getResourceDescriptor( ) {
34-
return resourcedescriptor == null ? "" : resourcedescriptor ;
33+
public String getResourceDescriptor() {
34+
// validate resourcedescriptor
35+
return resourcedescriptor == null || resourcedescriptor.isEmpty() ? "" : resourcedescriptor;
3536
}
3637

3738
@Override
38-
public Iterator<String> iterateHttpFields( ) {
39-
return Collections.unmodifiableSet( map.keySet () ).iterator ();//Safety first
39+
public Iterator<String> iterateHttpFields() {
40+
return Collections.unmodifiableSet( map.keySet() ).iterator();// Safety first
4041
}
4142

4243
@Override
4344
public String getFieldValue( String name ) {
44-
String s = map.get ( name );
45-
if( s == null ){
45+
String s = map.get( name );
46+
if( s == null ) {
4647
return "";
4748
}
4849
return s;
4950
}
5051

5152
@Override
52-
public byte[] getContent( ) {
53+
public byte[] getContent() {
5354
return content;
5455
}
55-
56+
5657
@Override
5758
public void setContent( byte[] content ) {
5859
this.content = content;
5960
}
60-
61+
6162
@Override
62-
public void setResourceDescriptor( String resourcedescriptor ) {
63+
public void setResourceDescriptor( String resourcedescriptor ) throws IllegalArgumentException {
6364
this.resourcedescriptor = resourcedescriptor;
6465
}
65-
66+
6667
@Override
67-
public void put( String name, String value ){
68-
map.put ( name , value );
68+
public void put( String name, String value ) {
69+
map.put( name, value );
6970
}
7071

7172
@Override
@@ -74,14 +75,14 @@ public boolean hasFieldValue( String name ) {
7475
}
7576

7677
@Override
77-
public String getHttpStatusMessage( ) {
78+
public String getHttpStatusMessage() {
7879
return httpstatusmessage;
7980
}
8081

8182
@Override
8283
public void setHttpStatusMessage( String message ) {
83-
this.httpstatusmessage=message;
84-
84+
this.httpstatusmessage = message;
85+
8586
}
8687

8788
}

‎src/net/tootallnate/websocket/drafts/Draft_17.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public HandshakeState acceptHandshakeAsServer( Handshakedata handshakedata ) thr
1515
return HandshakeState.MATCHED;
1616
return HandshakeState.NOT_MATCHED;
1717
}
18-
18+
1919
@Override
2020
public HandshakeBuilder postProcessHandshakeRequestAsClient( HandshakeBuilder request ) {
21-
super.postProcessHandshakeRequestAsClient( request );
22-
request.put ( "Sec-WebSocket-Version" , "13" );//overwriting the previous
23-
return request;
21+
super.postProcessHandshakeRequestAsClient( request );
22+
request.put( "Sec-WebSocket-Version", "13" );// overwriting the previous
23+
return request;
2424
}
25-
25+
2626
}

0 commit comments

Comments
 (0)