Example #1
0
  public void go() throws Exception {
    String input, action;
    String[] tokens;

    while (true) {
      System.out.print("TTT > ");
      input = ParserUtils.getKeyInput();
      tokens = ParserUtils.getTokens(input);
      if (tokens.length == 0) {
        continue;
      }
      action = tokens[0];

      if (action.equalsIgnoreCase("exit")) System.exit(1);
      else if (action.equalsIgnoreCase("move")) {
        byte row, col;
        try {
          col = Byte.parseByte(tokens[1]);
          row = Byte.parseByte(tokens[2]);
        } catch (Exception e) {
          System.out.println(e.getMessage());
          System.out.println("usage: move row col");
          continue;
        }
        boolean verify = game.placeMark(col, row, playerID);
        System.out.println(verify);
        if (!verify) {
          System.out.println("error moving, try again");
        } else {
          System.out.println();
          System.out.println(game.showBoard());
          winner = game.checkWinner();
          if (winner) {
            System.out.println("WINNING MOVE: game over");
            System.out.println(game.showBoard());
            game.reset();
          }
        }

      } else if (action.equalsIgnoreCase("show")) {
        System.out.println(game.showBoard());
      } else if (action.equalsIgnoreCase("restart")) {
        game.reset();
      } else {
        System.out.println("invalid command");
        continue;
      }
    }
  }
  // [Issue#381]
  public void testSingleElementArray() throws Exception {
    final int intTest = 932832;
    final double doubleTest = 32.3234;
    final long longTest = 2374237428374293423L;
    final short shortTest = (short) intTest;
    final float floatTest = 84.3743f;
    final byte byteTest = (byte) 43;
    final char charTest = 'c';

    final ObjectMapper mapper = new ObjectMapper();
    mapper.enable(DeserializationFeature.UNWRAP_SINGLE_VALUE_ARRAYS);

    final int intValue = mapper.readValue(asArray(intTest), Integer.TYPE);
    assertEquals(intTest, intValue);
    final Integer integerWrapperValue =
        mapper.readValue(asArray(Integer.valueOf(intTest)), Integer.class);
    assertEquals(Integer.valueOf(intTest), integerWrapperValue);

    final double doubleValue = mapper.readValue(asArray(doubleTest), Double.class);
    assertEquals(doubleTest, doubleValue);
    final Double doubleWrapperValue =
        mapper.readValue(asArray(Double.valueOf(doubleTest)), Double.class);
    assertEquals(Double.valueOf(doubleTest), doubleWrapperValue);

    final long longValue = mapper.readValue(asArray(longTest), Long.TYPE);
    assertEquals(longTest, longValue);
    final Long longWrapperValue = mapper.readValue(asArray(Long.valueOf(longTest)), Long.class);
    assertEquals(Long.valueOf(longTest), longWrapperValue);

    final short shortValue = mapper.readValue(asArray(shortTest), Short.TYPE);
    assertEquals(shortTest, shortValue);
    final Short shortWrapperValue =
        mapper.readValue(asArray(Short.valueOf(shortTest)), Short.class);
    assertEquals(Short.valueOf(shortTest), shortWrapperValue);

    final float floatValue = mapper.readValue(asArray(floatTest), Float.TYPE);
    assertEquals(floatTest, floatValue);
    final Float floatWrapperValue =
        mapper.readValue(asArray(Float.valueOf(floatTest)), Float.class);
    assertEquals(Float.valueOf(floatTest), floatWrapperValue);

    final byte byteValue = mapper.readValue(asArray(byteTest), Byte.TYPE);
    assertEquals(byteTest, byteValue);
    final Byte byteWrapperValue = mapper.readValue(asArray(Byte.valueOf(byteTest)), Byte.class);
    assertEquals(Byte.valueOf(byteTest), byteWrapperValue);

    final char charValue =
        mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.TYPE);
    assertEquals(charTest, charValue);
    final Character charWrapperValue =
        mapper.readValue(asArray(quote(String.valueOf(charTest))), Character.class);
    assertEquals(Character.valueOf(charTest), charWrapperValue);

    final boolean booleanTrueValue = mapper.readValue(asArray(true), Boolean.TYPE);
    assertTrue(booleanTrueValue);

    final boolean booleanFalseValue = mapper.readValue(asArray(false), Boolean.TYPE);
    assertFalse(booleanFalseValue);

    final Boolean booleanWrapperTrueValue =
        mapper.readValue(asArray(Boolean.valueOf(true)), Boolean.class);
    assertEquals(Boolean.TRUE, booleanWrapperTrueValue);
  }
  myIP(int temp_local_port) throws UnknownHostException, SocketException, IOException {
    try {
      local_port = temp_local_port;
      short length_message = 0;
      short temp_short;
      int temp_int;
      byte[] temp_byte = null;

      // STUN Massage Type
      temp_short = 0x0001;
      temp_byte = myFunc.ShortToByte(temp_short);
      data[0] = temp_byte[0];
      data[1] = temp_byte[1];

      // Massage Length
      temp_short = length_message;
      temp_byte = myFunc.ShortToByte(temp_short);
      data[2] = temp_byte[0];
      data[3] = temp_byte[1];

      // Magic Cookie
      temp_int = 0x2112A442;
      temp_byte = myFunc.IntToByte(temp_int);
      data[4] = temp_byte[0];
      data[5] = temp_byte[1];
      data[6] = temp_byte[2];
      data[7] = temp_byte[3];

      // Translation ID
      for (int i = 0; i < 3; i++) {
        temp_int = 12314 + i;
        temp_byte = myFunc.IntToByte(temp_int);
        data[8 + i * 4] = temp_byte[0];
        data[9 + i * 4] = temp_byte[1];
        data[10 + i * 4] = temp_byte[2];
        data[11 + i * 4] = temp_byte[3];
      }

      ia = InetAddress.getByName(STUN_host);
      DatagramSocket ds = new DatagramSocket(local_port);
      DatagramPacket pack = new DatagramPacket(data, data.length, ia, getport);
      for (int i = 0; i < data.length; i++) {
        System.out.println(data[i]);
      }
      ds.send(pack);
      int btlength = 64;
      short Res_type_message = 0,
          Res_length_message = 0,
          Res_atribute_type = 0,
          Res_atribute_length = 0;
      int Res_magic_cookie = 0;
      byte Res_family = 0;
      int Res_port = 0;
      int[] Res_IP = new int[4];
      int[] Res_translationID = new int[3];
      DatagramPacket packet = new DatagramPacket(new byte[btlength], btlength);
      ds.receive(packet);
      byte[] arr = packet.getData();

      temp_byte = new byte[2];
      temp_byte[0] = arr[0];
      temp_byte[1] = arr[1];
      Res_type_message = myFunc.ByteToShort(temp_byte);

      temp_byte = new byte[2];
      temp_byte[0] = arr[2];
      temp_byte[1] = arr[3];
      Res_length_message = myFunc.ByteToShort(temp_byte);

      temp_byte = new byte[4];
      temp_byte[0] = arr[4];
      temp_byte[1] = arr[5];
      temp_byte[2] = arr[6];
      temp_byte[3] = arr[7];
      Res_magic_cookie = myFunc.ByteToInt(temp_byte);

      for (int i = 0; i < 3; i++) {
        temp_byte = new byte[4];
        temp_byte[0] = arr[8 + i * 4];
        temp_byte[1] = arr[9 + i * 4];
        temp_byte[2] = arr[10 + i * 4];
        temp_byte[3] = arr[11 + i * 4];
        Res_translationID[i] = myFunc.ByteToInt(temp_byte);
      }

      temp_byte = new byte[2];
      temp_byte[0] = arr[20];
      temp_byte[1] = arr[21];
      Res_atribute_type = myFunc.ByteToShort(temp_byte);

      temp_byte = new byte[2];
      temp_byte[0] = arr[22];
      temp_byte[1] = arr[23];
      Res_atribute_length = myFunc.ByteToShort(temp_byte);

      Res_family = arr[25]; // IPv4 or IPv6

      temp_byte = new byte[2];
      temp_byte[0] = arr[26];
      temp_byte[1] = arr[27];
      Res_port = myFunc.ByteToShort(temp_byte);

      port = Res_port;

      for (int i = 0; i < 4; i++) {
        Res_IP[i] = Byte.toUnsignedInt(arr[28 + i]);
      }

      IPv4 = Res_IP;
      short indic = 0x0010;
      temp_short = indic;
      temp_byte = myFunc.ShortToByte(temp_short);
      data[0] = temp_byte[0];
      data[1] = temp_byte[1];
      ds.close();
    } catch (IOException e) {
      System.err.println(e);
    }
  }