Esempio n. 1
0
 public static CloseCode find(int value) {
   for (CloseCode code : values()) {
     if (code.getValue() == value) {
       return code;
     }
   }
   return null;
 }
Esempio n. 2
0
 private CloseFrame(WebSocketFrame wrap) throws CharacterCodingException {
   super(wrap);
   assert wrap.getOpCode() == OpCode.Close;
   if (wrap.getBinaryPayload().length >= 2) {
     this._closeCode =
         CloseCode.find(
             (wrap.getBinaryPayload()[0] & 0xFF) << 8 | wrap.getBinaryPayload()[1] & 0xFF);
     this._closeReason = binary2Text(getBinaryPayload(), 2, getBinaryPayload().length - 2);
   }
 }
Esempio n. 3
0
 private static byte[] generatePayload(CloseCode code, String closeReason)
     throws CharacterCodingException {
   if (code != null) {
     byte[] reasonBytes = text2Binary(closeReason);
     byte[] payload = new byte[reasonBytes.length + 2];
     payload[0] = (byte) (code.getValue() >> 8 & 0xFF);
     payload[1] = (byte) (code.getValue() & 0xFF);
     System.arraycopy(reasonBytes, 0, payload, 2, reasonBytes.length);
     return payload;
   } else {
     return new byte[0];
   }
 }