Пример #1
0
 public static CloseCode find(int value) {
   for (CloseCode code : values()) {
     if (code.getValue() == value) {
       return code;
     }
   }
   return null;
 }
Пример #2
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];
   }
 }