private String getIntegerInput(String prompt) {
    boolean valid = false; // indicates if the name has be retrieved
    String playersInput = null;
    Scanner keyboard = new Scanner(System.in); // keyboard input stream

    while (!valid) { // while a valid name has not been retrieved

      // prompt for the player's choice
      this.console.println(prompt);

      // get the selection from the keyboard and trim off the blanks CAPs ok
      playersInput = keyboard.nextLine();
      playersInput = playersInput.trim();
      char ch = playersInput.charAt(0);

      // if the selection is invlaid (less than one characters in length)
      if (!Character.isDigit(ch)) {
        this.console.println("Please enter a positive integer.");
        continue; // and repeat again
      }
      break; // out of the (exit) the repetition
    }

    return playersInput; // return the name
  }
  public static boolean isValidPassword(String password) {

    if (password.length() < 8) // ukoliko password nema 8 karaktera vracamo
      // gresku tj invalid password

      return false;

    int counter = 0;

    for (int i = 0; i < password.length(); i++) // prolazimo kroz sve
    // karaktere unosa

    {

      if (!Character.isLetterOrDigit(password.charAt(i))) // ukoliko se u
      // unosu ne
      // nalaze slova
      // opet vracamo
      // invalid
      // password

      {

        return false;
      }

      if (Character.isDigit(password.charAt(i))) // provjeravamo brojeve i
      // ukoliko ih ima
      // brojimo ih

      {

        counter++;
      }
    }

    if (counter >= 2) { // ukoliko ih ima vise od 2 uslov za validan
      // password je ispunjen vracamo tru za printanje
      System.out.println(" Valid password");

      return true;
    } else {
      System.out.println(" Invalid password");
      return false;
    }
  }
Exemple #3
0
  public void run() {
    CConn cc = null;
    Socket sock = null;
    if (listenMode.getValue()) {
      int port = 5500;
      ServerSocket listener = null;
      if (vncServerName.getValue() != null && Character.isDigit(vncServerName.getValue().charAt(0)))
        port = Integer.parseInt(vncServerName.getValue());

      try {
        listener = new ServerSocket(port);
      } catch (IOException e) {
        System.out.println("Could not listen on port: " + port);
        System.exit(-1);
      }

      vlog.info("Listening on port " + port);

      try {
        sock = listener.accept();
        listener.close();
      } catch (IOException e) {
        System.out.println("Accept failed: " + port);
        System.exit(-1);
      }
    }
    try {
      cc = new CConn(this, sock, vncServerName.getValue(), false);
      while (true) cc.processMsg();
    } catch (EndOfStream e) {
      vlog.info(e.toString());
    } catch (java.lang.Exception e) {
      if (cc != null) cc.deleteWindow();
      if (cc == null || !cc.shuttingDown) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(
            null, e.toString(), "VNC Viewer : Error", JOptionPane.ERROR_MESSAGE);
      }
    }
    if (cc != null) cc.deleteWindow();
    nViewers--;
    if (!applet && nViewers == 0) {
      System.exit(0);
    }
  }
 public static boolean isPrintable(char c) {
   if (Character.isJavaIdentifierStart(c)) {
     // Letters and $ _
     return true;
   }
   if (Character.isDigit(c)) {
     return true;
   }
   switch (Character.getType(c)) {
     case Character.MODIFIER_SYMBOL:
       return true; // ` ^
     case Character.DASH_PUNCTUATION:
       return true; // -
     case Character.MATH_SYMBOL:
       return true; // = ~ + | < >
     case Character.OTHER_PUNCTUATION:
       return true; // !@#%&*;':",./?
     case Character.START_PUNCTUATION:
       return true; // ( [ {
     case Character.END_PUNCTUATION:
       return true; // ) ] }
   }
   return false;
 }
Exemple #5
0
  public void write(char ch) throws IOException {
    boolean ok;

    switch (state) {
      case S_text:
        if (ch == '\n' || ch == '\r') {
          break; // unadorned newlines are ignored
        } else if (ch == '{') {
          if (currentCharacters.length() > 0) {
            handleText(currentCharacters.toString());
            currentCharacters = new StringBuffer();
          }
          level++;
          begingroup();
        } else if (ch == '}') {
          if (currentCharacters.length() > 0) {
            handleText(currentCharacters.toString());
            currentCharacters = new StringBuffer();
          }
          if (level == 0) throw new IOException("Too many close-groups in RTF text");
          endgroup();
          level--;
        } else if (ch == '\\') {
          if (currentCharacters.length() > 0) {
            handleText(currentCharacters.toString());
            currentCharacters = new StringBuffer();
          }
          state = S_backslashed;
        } else {
          currentCharacters.append(ch);
        }
        break;
      case S_backslashed:
        if (ch == '\'') {
          state = S_aftertick;
          break;
        }
        if (!Character.isLetter(ch)) {
          char newstring[] = new char[1];
          newstring[0] = ch;
          if (!handleKeyword(new String(newstring))) {
            warning("Unknown keyword: " + newstring + " (" + (byte) ch + ")");
          }
          state = S_text;
          pendingKeyword = null;
          /* currentCharacters is already an empty stringBuffer */
          break;
        }

        state = S_token;
        /* FALL THROUGH */
      case S_token:
        if (Character.isLetter(ch)) {
          currentCharacters.append(ch);
        } else {
          pendingKeyword = currentCharacters.toString();
          currentCharacters = new StringBuffer();

          // Parameter following?
          if (Character.isDigit(ch) || (ch == '-')) {
            state = S_parameter;
            currentCharacters.append(ch);
          } else {
            ok = handleKeyword(pendingKeyword);
            if (!ok) warning("Unknown keyword: " + pendingKeyword);
            pendingKeyword = null;
            state = S_text;

            // Non-space delimiters get included in the text
            if (!Character.isWhitespace(ch)) write(ch);
          }
        }
        break;
      case S_parameter:
        if (Character.isDigit(ch)) {
          currentCharacters.append(ch);
        } else {
          /* TODO: Test correct behavior of \bin keyword */
          if (pendingKeyword.equals("bin")) {
              /* magic layer-breaking kwd */
            long parameter = Long.parseLong(currentCharacters.toString());
            pendingKeyword = null;
            state = S_inblob;
            binaryBytesLeft = parameter;
            if (binaryBytesLeft > Integer.MAX_VALUE)
              binaryBuf = new ByteArrayOutputStream(Integer.MAX_VALUE);
            else binaryBuf = new ByteArrayOutputStream((int) binaryBytesLeft);
            savedSpecials = specialsTable;
            specialsTable = allSpecialsTable;
            break;
          }

          int parameter = Integer.parseInt(currentCharacters.toString());
          ok = handleKeyword(pendingKeyword, parameter);
          if (!ok)
            warning("Unknown keyword: " + pendingKeyword + " (param " + currentCharacters + ")");
          pendingKeyword = null;
          currentCharacters = new StringBuffer();
          state = S_text;

          // Delimiters here are interpreted as text too
          if (!Character.isWhitespace(ch)) write(ch);
        }
        break;
      case S_aftertick:
        if (Character.digit(ch, 16) == -1) state = S_text;
        else {
          pendingCharacter = Character.digit(ch, 16);
          state = S_aftertickc;
        }
        break;
      case S_aftertickc:
        state = S_text;
        if (Character.digit(ch, 16) != -1) {
          pendingCharacter = pendingCharacter * 16 + Character.digit(ch, 16);
          ch = translationTable[pendingCharacter];
          if (ch != 0) handleText(ch);
        }
        break;
      case S_inblob:
        binaryBuf.write(ch);
        binaryBytesLeft--;
        if (binaryBytesLeft == 0) {
          state = S_text;
          specialsTable = savedSpecials;
          savedSpecials = null;
          handleBinaryBlob(binaryBuf.toByteArray());
          binaryBuf = null;
        }
    }
  }