Exemplo n.º 1
1
    @Override
    public void onTextAvailable(ProcessEvent event, Key outputType) {
      String text = event.getText();
      if (outputType == ProcessOutputTypes.STDERR) {
        output.append(text);

        // We loop until the state stabilizes
        State lastState;
        do {
          lastState = state;
          switch (state) {
            case WAITING:
              {
                Matcher matcher = matcher(DIAGNOSTIC_PATTERN);
                if (find(matcher)) {
                  currentCompilerMessage = new CompilerMessage();
                  currentCompilerMessage.setMessageCategoryFromString(matcher.group(1));
                  state = State.ATTRIBUTES;
                }
                break;
              }
            case ATTRIBUTES:
              {
                Matcher matcher = matcher(ATTRIBUTE_PATTERN);
                int indexDelta = 0;
                while (matcher.find()) {
                  handleSkippedOutput(
                      output.subSequence(
                          firstUnprocessedIndex + indexDelta,
                          firstUnprocessedIndex + matcher.start()));
                  currentCompilerMessage.setAttributeFromStrings(
                      matcher.group(1), matcher.group(2));
                  indexDelta = matcher.end();
                }
                firstUnprocessedIndex += indexDelta;

                Matcher endMatcher = matcher(OPEN_TAG_END_PATTERN);
                if (find(endMatcher)) {
                  state = State.MESSAGE;
                }
                break;
              }
            case MESSAGE:
              {
                Matcher matcher = matcher(MESSAGE_PATTERN);
                if (find(matcher)) {
                  currentCompilerMessage.setMessage(matcher.group(1));
                  currentCompilerMessage.reportTo(compileContext);
                  state = State.WAITING;
                }
                break;
              }
          }
        } while (state != lastState);

      } else {
        compileContext.addMessage(INFORMATION, text, "", -1, -1);
      }
    }
Exemplo n.º 2
1
 private boolean find(Matcher matcher) {
   boolean result = matcher.find();
   if (result) {
     handleSkippedOutput(
         output.subSequence(firstUnprocessedIndex, firstUnprocessedIndex + matcher.start()));
     firstUnprocessedIndex += matcher.end();
   }
   return result;
 }
Exemplo n.º 3
1
 private Matcher matcher(Pattern pattern) {
   return pattern.matcher(output.subSequence(firstUnprocessedIndex, output.length()));
 }
 private <T> String toClassString(Collection<Class<? extends T>> providers) {
   StringBuilder sb = new StringBuilder();
   for (Class<?> provider : providers) {
     sb.append(provider.getName()).append(", ");
   }
   return sb.subSequence(0, sb.length() - 2).toString();
 }
Exemplo n.º 5
0
 private String toClassString(Collection<?> providers) {
   StringBuilder sb = new StringBuilder();
   for (Object provider : providers) {
     sb.append(provider.getClass().getName()).append(", ");
   }
   return sb.subSequence(0, sb.length() - 2).toString();
 }
  @Nullable
  private static String trimToValue(@Nullable StringBuilder output) {
    if (output == null) {
      return null;
    }
    int pos = output.lastIndexOf("  ");
    int pos2 = output.lastIndexOf("\t");
    pos = Math.max(pos, pos2);
    if (pos == -1) {
      return null;
    }

    output.delete(0, pos + 1);
    String blackList = "\r\n \"";
    int startPos = 0;
    int endPos = output.length() - 1;
    while (true) {
      if (startPos >= endPos) {
        return null;
      }
      if (blackList.indexOf(output.charAt(startPos)) != -1) {
        startPos++;
      } else {
        break;
      }
    }
    while (true) {
      if (blackList.indexOf(output.charAt(endPos)) != -1) {
        endPos--;
      } else {
        break;
      }
    }
    return output.subSequence(startPos, endPos + 1).toString();
  }
Exemplo n.º 7
0
 public String serialize() {
   StringBuilder builder = new StringBuilder();
   if (getItems() == null) {
     return "";
   }
   for (KeyValueLineModel keyValueLineModel : (List<KeyValueLineModel>) getItems()) {
     String key = keyValueLineModel.getKeys().getSelectedItem();
     if (!isKeyValid(key)) {
       continue;
     }
     builder.append(key);
     builder.append(KEY_VALUE_DELIMETER);
     if (keyValueLineModel.getValue().getIsAvailable()) {
       builder.append(keyValueLineModel.getValue().getEntity());
     } else if (keyValueLineModel.getValues().getIsAvailable()) {
       builder.append(keyValueLineModel.getValues().getSelectedItem());
     }
     builder.append(PROPERTIES_DELIMETER);
   }
   // remove the last delimiter
   if (builder.toString().endsWith(PROPERTIES_DELIMETER)) {
     return builder.subSequence(0, builder.length() - PROPERTIES_DELIMETER.length()).toString();
   }
   return builder.toString();
 }
Exemplo n.º 8
0
    public PathBuilder repeat(int count) {
      int pos = m_sb.length();

      for (int i = 0; i < count; i++) {
        m_sb.append(m_sb.subSequence(m_marker, pos));
      }

      return this;
    }
Exemplo n.º 9
0
  @Override
  public String decode(StringBuilder mensagemEmBinario) {
    StringBuilder array =
        new StringBuilder(
            mensagemEmBinario.subSequence(
                0, mensagemEmBinario.length() - (polinomio.length() - 1)));

    return Utilidades.converteBinarioParaAscii(array);
  }
 public void endOfInput() throws LexicalGrammarParserException {
   List<Matcher> matcherAndElements = new ArrayList<Matcher>();
   for (Pattern lexerPart : lexer.getPatterns()) {
     Matcher matcher = lexerPart.matcher(stringBuilder);
     matcher.useAnchoringBounds(false);
     matcher.useTransparentBounds(true);
     matcherAndElements.add(matcher);
   }
   int currentPosition = 0;
   while (currentPosition < stringBuilder.length()) {
     int size = 0;
     final int beforePosition = currentPosition;
     IRegularExpressionElement<? extends E> matchLexerPart = null;
     Matcher matchMatcher = null;
     int i = 0;
     for (Matcher matcher : matcherAndElements) {
       matcher.region(beforePosition, stringBuilder.length());
       if (matcher.lookingAt()) {
         int csize = matcher.end() - beforePosition;
         if (csize > size) {
           size = csize;
           matchLexerPart = lexer.getElements().get(i);
           matchMatcher = matcher;
         }
       }
       i++;
     }
     if (matchLexerPart == null) {
       throw new UnrecognizedCharacterSequence(
           stringBuilder
               .subSequence(
                   currentPosition,
                   Math.min(currentPosition + EXCEPTION_SIZE, stringBuilder.length()))
               .toString());
     }
     currentPosition += size;
     tokenReceiver.receiveToken(
         matchLexerPart.createToken(
             beforePosition,
             stringBuilder.subSequence(beforePosition, beforePosition + size),
             new SimpleMatchedGroups(matchMatcher, beforePosition)));
   }
   tokenReceiver.endOfTokens();
 }
Exemplo n.º 11
0
  public StringBuilder prepareImages(StringBuilder s) {
    int start = 0;

    // StringBuilder lower_case = new StringBuilder( s.toString().toLowerCase() );
    List<FileAttachment> attached_images = new ArrayList();

    for (Attachment att : attachments) {
      // System.out.println(att.getClass().getName());
      if (att instanceof FileAttachment) {
        FileAttachment fatt = (FileAttachment) att;

        String mime_type = fatt.getMimeTag();

        logger.info(fatt.toString() + " " + mime_type);

        if (mime_type != null && MainWin.is_image_mime_type(mime_type)) {
          attached_images.add(fatt);
        }
      }
    }

    Collections.sort(
        attached_images,
        new Comparator<FileAttachment>() {

          @Override
          public int compare(FileAttachment o1, FileAttachment o2) {
            if (o1.getSubDir() != null && o2.getSubDir() != null) {
              return o1.getSubDir().compareTo(o2.getSubDir());
            }

            return o1.getFilename().compareTo(o2.getFilename());
          }
        });

    while ((start = findImgTag(s, start)) >= 0) {
      // System.out.println("HERE");

      int end = s.indexOf(">", start);

      if (end < 0) {
        break;
      }

      String res = replace_src(new StringBuilder(s.subSequence(start, end)), attached_images);

      s.replace(start, end, res);

      if (res.length() == 0) start++;
      else start += res.length();
    }

    return s;
  }
 /**
  * 组装多个出票平台投注内容格式串
  *
  * @param platform
  * @param betCode
  * @return
  */
 public static String format(Map<String, String> map) {
   StringBuilder buf = new StringBuilder();
   if (null != map && map.size() > 0) {
     Set<String> keys = map.keySet();
     Iterator<String> iter = keys.iterator();
     while (iter.hasNext()) {
       String key = iter.next();
       String val = map.get(key);
       if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(val)) {
         String result = String.format(format, key, val);
         buf.append(result);
       }
     }
     return buf.subSequence(0, buf.length() - 1).toString();
   }
   return buf.toString();
 }
Exemplo n.º 13
0
  public static void main(String[] args) {

    StringBuilder sb =
        new StringBuilder(
            "C:"
                + File.separator
                + "DEV"
                + File.separator
                + "apache-tomcat-7.0.27"
                + File.separator
                + "wtpwebapps"
                + File.separator
                + "ShareServer"
                + File.separator
                + "upload20120705135932017.prop");
    String path =
        sb.subSequence(sb.indexOf(File.separator + "ShareServer"), sb.length()).toString();
    System.out.println(path);

    /*
    for (int i = 0; i <100; i++) {
    	Thread t = new Thread(new Runnable() {
    		@Override
    		public void run() {
    			int port = PortUtil.getPort();
    			//FileUploadServerUtil.getInstance().doService(port, "R:"+port+".txt");
    			FileUploadClient client = new FileUploadClient("127.0.0.1",port);
    			client.doUpload("R:1.txt");
    		}
    	});
    	t.start();
    	*/
    UserDao userDao = new UserDao();
    String xmpp = userDao.getXMPPName(2);
    System.out.println(xmpp);
  }
Exemplo n.º 14
0
  public void handleServerMessage(String currentMessage) {
    String[] messageParts = currentMessage.split("[|]");
    int senderReplicaId = Integer.parseInt(messageParts[1]);
    int paxosId = Integer.parseInt(messageParts[2]);
    int numEntries = this.replica.paxosEntries.size();
    Paxos currentPaxos;

    switch (Integer.parseInt(messageParts[0])) {
      case 1:
        BallotPair proposedBallotNumPair =
            new BallotPair(Integer.parseInt(messageParts[4]), Integer.parseInt(messageParts[3]));
        // receivePrepareMsg
        this.replica.logger.write(
            "Received Prepare Msg for Paxos Instance: " + String.valueOf(paxosId));
        if (paxosId > numEntries - 1) {
          // Create a new one
          this.replica.paxosEntries.add(
              new Paxos(paxosId, this.replica.replicaId, "", this.replica.logger));
          currentPaxos = this.replica.paxosEntries.get(numEntries);
          currentPaxos.onreceivePrepare(proposedBallotNumPair, senderReplicaId);
        } else if (paxosId == numEntries - 1) {
          // check if it is active or not
          currentPaxos = this.replica.paxosEntries.get(numEntries - 1);
          // active and join it - else already decided and send decide
          if (!currentPaxos.isDecided) {
            currentPaxos.onreceivePrepare(proposedBallotNumPair, senderReplicaId);
          } else {
            MessageCommunication.sendDecideUnicast(
                this.replica.replicaId, senderReplicaId, paxosId, currentPaxos.logEnrties);
          }
        } else {
          // already decided
          currentPaxos = this.replica.paxosEntries.get(numEntries - 1);
          MessageCommunication.sendDecideUnicast(
              this.replica.replicaId, senderReplicaId, paxosId, currentPaxos.logEnrties);
        }
        break;
      case 2:
        // receiveAcktoPrepareMsg
        this.replica.logger.write(
            "Received AckToPrepare Msg for Paxos Instance: " + String.valueOf(paxosId));
        // Ongoing paxos Instance
        if (paxosId == numEntries - 1 && !this.replica.paxosEntries.get(paxosId).isDecided) {
          currentPaxos = this.replica.paxosEntries.get(paxosId);
          BallotPair ownBallotNumPair =
              new BallotPair(Integer.parseInt(messageParts[4]), Integer.parseInt(messageParts[3]));
          BallotPair acceptedBallotNumPair =
              new BallotPair(Integer.parseInt(messageParts[6]), Integer.parseInt(messageParts[5]));
          currentPaxos.onreceiveAckToPrepare(
              ownBallotNumPair,
              acceptedBallotNumPair,
              messageParts.length > 7 ? messageParts[7] : "");
        } else {
          if (paxosId < numEntries - 1) {
            MessageCommunication.sendDecideUnicast(
                this.replica.replicaId,
                senderReplicaId,
                paxosId,
                this.replica.paxosEntries.get(paxosId).logEnrties);
            this.replica.logger.write(
                "Responded to  AckToPrepare Msg with Decide Msg for Paxos Instance: "
                    + String.valueOf(paxosId));
          } else {
            this.replica.logger.write(
                "Ignoring AckToPrepare Msg for Paxos Instance: " + String.valueOf(paxosId));
          }
        }
        break;
      case 3:
        // receiveNAcktoPrepareMsg
        this.replica.logger.write(
            "Received NAckToPrepare Msg for Paxos Instance: " + String.valueOf(paxosId));
        // Ongoing paxos Instance
        if (paxosId == numEntries - 1 && !this.replica.paxosEntries.get(paxosId).isDecided) {
          currentPaxos = this.replica.paxosEntries.get(paxosId);
          BallotPair ownBallotNumPair =
              new BallotPair(Integer.parseInt(messageParts[4]), Integer.parseInt(messageParts[3]));
          currentPaxos.onreceiveNAckToPrepare(ownBallotNumPair);
        } else {
          if (paxosId < numEntries - 1) {
            MessageCommunication.sendDecideUnicast(
                this.replica.replicaId,
                senderReplicaId,
                paxosId,
                this.replica.paxosEntries.get(paxosId).logEnrties);
            this.replica.logger.write(
                "Responded to  NAckToPrepare Msg with Decide Msg for Paxos Instance: "
                    + String.valueOf(paxosId));
          } else {
            this.replica.logger.write(
                "Ignoring NAckToPrepare Msg for Paxos Instance: " + String.valueOf(paxosId));
          }
        }
        break;
      case 4:
        // onreceiveAccept
        BallotPair acceptBallotNumPair =
            new BallotPair(Integer.parseInt(messageParts[4]), Integer.parseInt(messageParts[3]));
        this.replica.logger.write(
            "Received Accept Msg for Paxos Instance: " + String.valueOf(paxosId));
        if (paxosId > numEntries - 1) {
          // Create a new one
          this.replica.paxosEntries.add(
              new Paxos(paxosId, this.replica.replicaId, "", this.replica.logger));
          currentPaxos = this.replica.paxosEntries.get(numEntries);
          currentPaxos.onreceiveAccept(acceptBallotNumPair, messageParts[5]);
        } else if (paxosId == numEntries - 1) {
          // check if it is active or not
          currentPaxos = this.replica.paxosEntries.get(numEntries - 1);
          // active and join it - else already decided and send decide
          if (!currentPaxos.isDecided) {
            currentPaxos.onreceiveAccept(acceptBallotNumPair, messageParts[5]);
          } else {
            MessageCommunication.sendDecideUnicast(
                this.replica.replicaId, senderReplicaId, paxosId, currentPaxos.logEnrties);
          }
        } else {
          // already decided
          currentPaxos = this.replica.paxosEntries.get(numEntries - 1);
          MessageCommunication.sendDecideUnicast(
              this.replica.replicaId, senderReplicaId, paxosId, currentPaxos.logEnrties);
        }
        break;
      case 5:
        // onreceiveDecide
        String value = messageParts[3];
        ArrayList<String> Parts = new ArrayList<String>();
        String[] tempArray = value.split(":");
        for (String x : tempArray) {
          Parts.add(x);
        }
        if (paxosId < numEntries - 1) {
          // Redundant check
          currentPaxos = this.replica.paxosEntries.get(paxosId);
          currentPaxos.onreceiveDecide(Parts);
        } else if (paxosId == numEntries - 1) {
          // check if it is active or not
          currentPaxos = this.replica.paxosEntries.get(numEntries - 1);
          // active and join it - else already decided and send decide
          /** if(!currentPaxos.isDecided) { currentPaxos.onreceiveDecide(value); } */
          currentPaxos.onreceiveDecide(Parts);
        } else {
          // future stuff in which I did not participate because I was down
          this.replica.logger.write(
              "RECVD DECIDE MSG FOR PAXOS INSTANCE "
                  + String.valueOf(paxosId)
                  + " BUT IGNORED BECAUSE THIS REPLICA WAS DOWN IN INITIAL PHASES.");
        }
        break;
      case 6:
        String value1 = messageParts[3];
        ArrayList<String> Parts1 = new ArrayList<String>();
        String[] tempArray1 = value1.split(":");
        for (String x : tempArray1) {
          Parts1.add(x);
        }
        if (paxosId < numEntries - 1) {
          // Redundant check
          currentPaxos = this.replica.paxosEntries.get(paxosId);
          currentPaxos.onreceiveDecide(Parts1);
        } else if (paxosId == numEntries - 1) {
          // check if it is active or not
          currentPaxos = this.replica.paxosEntries.get(numEntries - 1);
          // active and join it - else already decided and send decide
          currentPaxos.onreceiveDecide(Parts1);
        } else {
          // future stuff in which I did not participate because I was down
          this.replica.logger.write(
              "RECVD DECIDE MSG FOR PAXOS INSTANCE "
                  + String.valueOf(paxosId)
                  + " BUT IGNORED BECAUSE THIS REPLICA WAS DOWN IN INITIAL PHASES.");
        }
        break;
      case 7:

        // received recoverme message from a failed node
        int highestindex = paxosId;
        int recoverNodeId = senderReplicaId;
        int num = 0;
        if (numEntries >= 1) {
          if (this.replica.paxosEntries.get(numEntries - 1).isDecided) {
            num = numEntries - 1;
          } else {
            num = numEntries - 2;
          }
          if (highestindex <= num) {
            // sendUpdate or everythinguptodate
            ArrayList<String> newValues = new ArrayList<String>();

            for (int i = highestindex + 1; i <= num; i++) {
              StringBuilder message = new StringBuilder();
              ArrayList<String> entry = this.replica.paxosEntries.get(i).logEnrties;
              for (String x : entry) {
                message.append(x + ":");
              }
              newValues.add(message.subSequence(0, message.length() - 1).toString());
              // newValues.add(this.replica.paxosEntries.get(i).valueWritten);
            }
            MessageCommunication.replyOnRecover(this.replica.replicaId, recoverNodeId, newValues);
          } else {
            this.replica.logger.write("RECOVERING NODE KNOWS MUCH MORE THAN ME :(");
          }
        }
        break;
      case 8:
        // receiving replyToRecover message

        // handle recovery message from other replicas and set isRecovered = true
        if (!this.replica.isRecovered) {
          int messageSize = paxosId;
          int numberOfEntries = replica.paxosEntries.size() - 1;
          int highestDecidedIndex = 0;
          if (numberOfEntries >= 0) {
            if (replica.paxosEntries.get(numberOfEntries).isDecided) {
              highestDecidedIndex = numberOfEntries;
            } else {
              this.replica.logger.write("This would never happen.");
              replica.paxosEntries.remove(numberOfEntries);
              highestDecidedIndex = numberOfEntries - 1;
            }
          } else highestDecidedIndex = -1;

          synchronized (this.replica.paxosEntries) {
            System.out.println("Message Size = " + messageSize);
            for (int i = 0; i < messageSize; i++) {
              System.out.println("Message Size = " + messageSize + "Message" + messageParts[3 + i]);
              String str = messageParts[3 + i];
              ArrayList<String> Parts2 = new ArrayList<String>();
              String[] tempArray2 = str.split(":");
              for (String x : tempArray2) {
                Parts2.add(x);
              }

              this.replica.paxosEntries.add(
                  new Paxos(highestDecidedIndex + i + 1, this.replica.replicaId, Parts2));
            }
          }
          replica.isRecovered = true;
        }
        // else don't do anything I am have recovered
        break;
      default:
        break;
    }
  }
 public CharSequence subSequence(int start, int end) {
   return builder.subSequence(start, end);
 }
Exemplo n.º 16
0
 /**
  * Process incoming text with replacing [*] tags by [*]...[/*]
  *
  * @param bbEncodedText bb encoded text to process
  * @return processed text
  */
 @Override
 public CharSequence process(CharSequence bbEncodedText) {
   StringBuilder result = process(new StringBuilder(bbEncodedText));
   return result.subSequence(0, result.length());
 }
Exemplo n.º 17
0
 /**
  * Liest den aktuellen Pufferinhalt aus.
  *
  * @return Der Pufferinhalt als CharSequence.
  */
 CharSequence read() {
   return buffer.subSequence(0, pointer + 1);
 }