@@ -93,10 +93,10 @@ public enum Role {
9393
9494 public List <Draft > known_drafts ;
9595
96- private static final byte [] FLASH_POLICY_REQUEST = "<policy-file-request/>" . getBytes ( Draft . UTF8_CHARSET );
96+ private static final byte [] FLASH_POLICY_REQUEST = Charsetfunctions . utf8Bytes ( "<policy-file-request/>" );
9797
9898 private int flash_policy_index = 0 ;
99-
99+
100100 SocketChannel sockchannel ;
101101
102102 // CONSTRUCTOR /////////////////////////////////////////////////////////////
@@ -111,12 +111,12 @@ public enum Role {
111111 * The {@link WebSocketListener} to notify of events when
112112 * they occur.
113113 */
114- public WebSocket ( WebSocketListener listener , Draft draft , SocketChannel sockchannel ) {
114+ public WebSocket ( WebSocketListener listener , Draft draft , SocketChannel sockchannel ) {
115115 init ( listener , draft , sockchannel );
116116 }
117117
118- public WebSocket ( WebSocketListener listener , List <Draft > drafts , SocketChannel sockchannel ) {
119- init ( listener , null , sockchannel );
118+ public WebSocket ( WebSocketListener listener , List <Draft > drafts , SocketChannel sockchannel ) {
119+ init ( listener , null , sockchannel );
120120 this .role = Role .SERVER ;
121121 if ( known_drafts == null || known_drafts .isEmpty () ) {
122122 known_drafts = new ArrayList <Draft >( 1 );
@@ -149,13 +149,14 @@ private void init( WebSocketListener listener, Draft draft, SocketChannel sockch
149149 * @throws InterruptedException
150150 * @throws LimitExceededException
151151 */
152- public void handleRead ( ) throws InterruptedException , IOException {
152+ public void handleRead () throws InterruptedException , IOException {
153153 if ( !socketBuffer .hasRemaining () ) {
154154 socketBuffer .rewind ();
155155 socketBuffer .limit ( socketBuffer .capacity () );
156156 if ( sockchannel .read ( socketBuffer ) == -1 ) {
157157 close ();
158158 }
159+
159160 socketBuffer .flip ();
160161 }
161162
@@ -168,7 +169,7 @@ public void handleRead( ) throws InterruptedException , IOException {
168169
169170 handshakestate = isFlashEdgeCase ( socketBuffer );
170171 if ( handshakestate == HandshakeState .MATCHED ) {
171- channelWrite ( ByteBuffer .wrap ( wsl .getFlashPolicy ( this ). getBytes ( Draft . UTF8_CHARSET ) ) );
172+ channelWrite ( ByteBuffer .wrap ( Charsetfunctions . utf8Bytes ( wsl .getFlashPolicy ( this ) ) ) );
172173 return ;
173174 }
174175 socketBuffer .mark ();
@@ -253,7 +254,7 @@ else if( curop == Opcode.CLOSING ) {
253254 if ( currentframe == null ) {
254255 if ( f .isFin () ) {
255256 if ( f .getOpcode () == Opcode .TEXT ) {
256- wsl .onMessage ( this , new String ( f .getPayloadData (), Draft . UTF8_CHARSET ) );
257+ wsl .onMessage ( this , Charsetfunctions . stingUtf8 ( f .getPayloadData () ) );
257258 } else if ( f .getOpcode () == Opcode .BINARY ) {
258259 wsl .onMessage ( this , f .getPayloadData () );
259260 } else {
@@ -271,7 +272,7 @@ else if( curop == Opcode.CLOSING ) {
271272 abort ( "invalid frame: " + e .getMessage () );
272273 }
273274 if ( f .isFin () ) {
274- wsl .onMessage ( this , new String ( f .getPayloadData (), Draft . UTF8_CHARSET ) );
275+ wsl .onMessage ( this , Charsetfunctions . stingUtf8 ( f .getPayloadData () ) );
275276 currentframe = null ;
276277 }
277278 }
@@ -349,7 +350,7 @@ boolean hasBufferedData() {
349350 * @return True if all data has been sent to the client, false if there
350351 * is still some buffered.
351352 */
352- public void handleWrite ( ) throws IOException {
353+ public void handleWrite () throws IOException {
353354 ByteBuffer buffer = this .bufferQueue .peek ();
354355 while ( buffer != null ) {
355356 sockchannel .write ( buffer );
@@ -402,17 +403,18 @@ private void open() throws InterruptedException , IOException {
402403 handshakeComplete = true ;
403404 wsl .onOpen ( this );
404405 }
405-
406- public InetSocketAddress getRemoteSocketAddress ( ) {
406+
407+ public InetSocketAddress getRemoteSocketAddress () {
407408 return (InetSocketAddress ) sockchannel .socket ().getRemoteSocketAddress ();
408409 }
409-
410- public InetSocketAddress getLocalSocketAddress ( ) {
410+
411+ public InetSocketAddress getLocalSocketAddress () {
411412 return (InetSocketAddress ) sockchannel .socket ().getLocalSocketAddress ();
412413 }
413414
414415 @ Override
415416 public String toString () {
416417 return super .toString (); // its nice to be able to set breakpoints here
417418 }
419+
418420}
0 commit comments