Beispiel #1
1
  public static String formatBranches(
      LogInformation.Revision revision, boolean useNumbersIfNamesNotAvailable) {
    String branches = revision.getBranches();
    if (branches == null) return ""; // NOI18N

    boolean branchNamesAvailable = true;
    StringBuilder branchNames = new StringBuilder();
    StringTokenizer st = new StringTokenizer(branches, ";"); // NOI18N
    while (st.hasMoreTokens()) {
      String branchNumber = st.nextToken().trim();
      List<LogInformation.SymName> names =
          revision
              .getLogInfoHeader()
              .getSymNamesForRevision(createBranchRevisionNumber(branchNumber));
      if (names.size() > 0) {
        branchNames.append(names.get(0).getName());
      } else {
        branchNamesAvailable = false;
        if (useNumbersIfNamesNotAvailable) {
          branchNames.append(branchNumber);
        } else {
          break;
        }
      }
      branchNames.append("; "); // NOI18N
    }
    if (branchNamesAvailable || useNumbersIfNamesNotAvailable) {
      branchNames.delete(branchNames.length() - 2, branchNames.length());
    } else {
      branchNames.delete(0, branchNames.length());
    }
    return branchNames.toString();
  }
Beispiel #2
1
 public void searchTags() {
   StringBuilder strTags = new StringBuilder();
   for (int i = 0; i < tempStrBuilder.length() - 1; i++) {
     i = tempStrBuilder.indexOf("<");
     if (i == -1) {
       break;
     }
     strTags.append(tempStrBuilder.substring(i, tempStrBuilder.indexOf(">") + 1));
     tempStrBuilder.delete(i, tempStrBuilder.indexOf(">") + 1);
     tags.add(strTags.toString());
     strTags.delete(0, strTags.length());
   }
 }
Beispiel #3
1
  @Override
  protected void actionPerformed(GuiButton button) throws IOException {
    switch (button.id) {
      case 0: // Means Done
        ErrorHandling.CleanErrors();
        /* Closes the text editor, saves the .oc file and attempts to compile and load it */
        mc.thePlayer.closeScreen();
        text.deleteCharAt(cursorLocation);
        saveFile();
        try {
          Compiler.main(
              String.format(System.getProperty("user.dir") + "/ObsidiCode/Test/SimpleMiner.oc"));
        } catch (Exception e) {
          e.printStackTrace();
        }
        ArrayList<String> currentErrors = (ArrayList<String>) ErrorHandling.GetErrors().clone();
        if (currentErrors.size() == 0) {
          loadRobot();
        } else {
          ErrorBook eb = ObsidiSkriveMaskineMod.errorBook();
          ObsidiCodingMachine.dropErrorLog(eb);
        }
        break;
      case 1: // Means reset
        // Resets the text on the screen.
        text = text.delete(0, text.toString().length());
        cursorLocation = 0;
        break;
      default:
        break;
    }

    super.actionPerformed(button);
  }
Beispiel #4
1
 // encodeURL
 public static String encodeURL(String url, String encode) throws UnsupportedEncodingException {
   StringBuilder sb = new StringBuilder();
   StringBuilder noAsciiPart = new StringBuilder();
   for (int i = 0; i < url.length(); i++) {
     char c = url.charAt(i);
     if (c > 255) {
       noAsciiPart.append(c);
     } else {
       if (noAsciiPart.length() != 0) {
         sb.append(URLEncoder.encode(noAsciiPart.toString(), encode));
         noAsciiPart.delete(0, noAsciiPart.length());
       }
       sb.append(c);
     }
   }
   return sb.toString();
 }
Beispiel #5
1
  static void toHexString(String header, ByteBuffer buf) {
    sb.delete(0, sb.length());

    for (int index = 0; index < buf.limit(); index++) {
      String hex = Integer.toHexString(0x0100 + (buf.get(index) & 0x00FF)).substring(1);
      sb.append((hex.length() < 2 ? "0" : "") + hex + " ");
    }
    LOG.debug(
        "hex->"
            + header
            + ": position,limit,capacity "
            + buf.position()
            + ","
            + buf.limit()
            + ","
            + buf.capacity());
    LOG.debug("hex->" + sb.toString());
  }
  private void generateSizeValue(File clFile) throws FileNotFoundException, IOException {

    if (clHeaderWriter == null) {
      throw new FileNotFoundException("Not Found CL Header's file.");
    }

    // Create field name "const size_t "
    String clFileName = clFile.getName().toUpperCase();
    // replace . -> _
    clFileName = clFileName.replace(".", "_");
    StringBuilder clFileNameSB = new StringBuilder(clFileName);
    clFileNameSB.delete(clFileName.length() - 3, clFileName.length());
    // Variable Name = Prefix + CL file name + Postfix
    clHeaderWriter.write("static const size_t " + PREFIX_CL + clFileNameSB + POSTFIX_SIZE + " = ");

    BufferedReader clFileReader = new BufferedReader(new FileReader(clFile));
    String readText = null;
    int textCounter = 0;
    while ((readText = clFileReader.readLine()) != null) {
      textCounter += readText.length() + 1;
    }
    clHeaderWriter.write(textCounter + ";");
    clHeaderWriter.newLine();
    clHeaderWriter.newLine();
    clHeaderWriter.newLine();
    clHeaderWriter.flush();
  }
Beispiel #7
0
  public static Result start() {
    java.util.Map<String, String[]> map = request().body().asFormUrlEncoded();

    List<String> terms = new ArrayList<>(map.size());
    for (int i = 0; i < map.size(); i++) {
      String key = "terms[" + i + "]";
      if (map.containsKey(key)) {
        String[] values = map.get(key);
        if ((values != null) && (values.length >= 1)) {
          terms.add(values[0]);
        }
      }
    }

    StreamConfig config = getConfig();
    config.putTerms(terms);
    config.update();

    StringBuilder sb = new StringBuilder();
    for (String t : terms) {
      sb.append(t);
      sb.append(", ");
    }
    sb.delete(sb.length() - 2, sb.length());

    try {
      startStream(terms);
      flash("success", "Twitter stream started (" + sb.toString() + ")");
    } catch (TwitterException e) {
      Logger.info("Error starting twitter stream", e);
      flash("error", "Error starting Twitter stream" + e.getMessage());
    }
    return redirect(routes.Streams.listAll());
  }
Beispiel #8
0
 private void expect(StringBuilder src, String expected) throws RequestMessageParsingException {
   String actual = src.substring(0, expected.length());
   if (!actual.equals(expected)) {
     String message = String.format("Expected \"%s\" next in \"%s\".", expected, src.toString());
     throw new RequestMessageParsingException(message);
   }
   src.delete(0, expected.length());
 }
Beispiel #9
0
  private String readUntil(StringBuilder src, String stop) throws RequestMessageParsingException {
    int stopIndex = src.indexOf(stop);

    if (stopIndex == -1) {
      String message = String.format("String \"%s\" not found in \"%s\".", stop, src.toString());
      throw new RequestMessageParsingException(message);
    }

    String res = src.substring(0, stopIndex);
    src.delete(0, stopIndex);
    return res;
  }
Beispiel #10
0
  /**
   * Listens to the output of the debugger constantly, and notifies observers when output is
   * recieved.
   */
  public void run() {
    boolean done = false;

    while (!done) {
      try {
        /*make sure we are alive */
        if (!alive) {
          close();
          break;
        }

        int c; // = debugStreamReader.read();
        char theChar; // = (char) c;
        // buffer.append(theChar);
        //

        while (debugStreamReader.ready()) {
          c = debugStreamReader.read();
          theChar = (char) c;
          if ((c == -1) || (c == 0)) {
            done = true;
          } else {
            buffer.append(theChar);
          }
        }

        if (buffer.length() > 0) {
          String output = buffer.toString();
          TextOutputEvent event = new TextOutputEvent(output, handle);
          synchronized (observers) {
            for (TextOutputListener listener : observers) {
              listener.receiveOutput(event);
            }
            buffer.delete(0, buffer.length());
          }
        }
      } catch (IOException e) {
        /*We will eventually want to eat this */
        e.printStackTrace();
        return;
      }
    }

    try {
      debugStreamReader.close();
      return;
    } catch (IOException e) {
      /*Eat it */
    }
    return;
  }
  private void generateCharValue(File clFile) throws FileNotFoundException, IOException {

    if (clHeaderWriter == null) {
      throw new FileNotFoundException("Not Found CL Header's file.");
    }

    // Create field name "char *file_name"
    String clFileName = clFile.getName().toUpperCase();
    // replace . -> _
    clFileName = clFileName.replace(".", "_");
    StringBuilder clFileNameSB = new StringBuilder(clFileName);
    clFileNameSB.delete(clFileName.length() - 3, clFileName.length());
    // Variable Name = Prefix + CL file name
    clHeaderWriter.write("static const char *" + PREFIX_CL + clFileNameSB + " = ");
    clHeaderWriter.newLine();

    BufferedReader clFileReader = new BufferedReader(new FileReader(clFile));
    String readText = null;
    while ((readText = clFileReader.readLine()) != null) {
      readText = replaceSpecialCharactors(readText);

      StringBuilder writeText = new StringBuilder();
      // insert " to begin of line
      writeText.append("\t\"");
      writeText.append(readText);
      // insert \n to end of line
      writeText.append("\\n\"");

      writeText.append("\n");

      clHeaderWriter.write(writeText.toString());
    }
    clFileReader.close();

    // insert ; to begin of this file
    clHeaderWriter.write("\t\"\";");
    clHeaderWriter.newLine();
    clHeaderWriter.newLine();
    clHeaderWriter.newLine();
    clHeaderWriter.flush();
  }
Beispiel #12
0
  public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String fileName = reader.readLine();
    BufferedReader file = new BufferedReader(new FileReader(fileName));
    if (args[0].equals("-c")) {
      int max = 0;
      ArrayList<String> buffer = new ArrayList<String>();
      StringBuilder line = new StringBuilder();
      while (file.ready()) {
        line.append(file.readLine());
        buffer.add(line.toString());
        line.delete(0, line.length());
      }
      file.close();

      for (int i = 0; i < buffer.size(); i++) {
        System.out.println(buffer.get(i));
        String temp = buffer.get(i).substring(0, 8).trim();
        int id = Integer.parseInt(temp);
        if (id > max) max = id;
      }
      max++;
      BufferedWriter wFile = new BufferedWriter(new FileWriter(fileName));
      String ID = String.valueOf(max);
      String pName = args[1];
      String price = args[2];
      String count = args[3];
      for (int i = 0; i < 30 - args[1].length(); i++) pName += " ";
      for (int i = 0; i < 8 - args[2].length(); i++) price += " ";
      for (int i = 0; i < 4 - args[3].length(); i++) count += " ";
      for (int i = 0; i < 8 - ID.length(); i++) ID += " ";
      String result = ID + pName + price + count;
      buffer.add(result);
      for (int i = 0; i < buffer.size(); i++) {
        wFile.write(buffer.get(i));
        wFile.newLine();
      }
      wFile.close();
    }
  }
 private static void processDots(StringBuilder result, int dots, int start) {
   if (dots == 2) {
     int pos = -1;
     if (!StringUtil.endsWith(result, "/../") && !StringUtil.equals(result, "../")) {
       pos = StringUtil.lastIndexOf(result, '/', start, result.length() - 1);
       if (pos >= 0) {
         ++pos; // separator found, trim to next char
       } else if (start > 0) {
         pos = start; // path is absolute, trim to root ('/..' -> '/')
       } else if (result.length() > 0) {
         pos = 0; // path is relative, trim to default ('a/..' -> '')
       }
     }
     if (pos >= 0) {
       result.delete(pos, result.length());
     } else {
       result.append("../"); // impossible to traverse, keep as-is
     }
   } else if (dots != 1) {
     StringUtil.repeatSymbol(result, '.', dots);
     result.append('/');
   }
 }
Beispiel #14
0
 private void deleteFoundWord(String fragment) {
   String str = tempStrBuilder.toString().replace(fragment, "");
   tempStrBuilder.delete(0, tempStrBuilder.length());
   tempStrBuilder.append(str);
 }
Beispiel #15
0
  private static void generateCtor(
      ClassFileWriter cfw, String adapterName, String superName, Constructor<?> superCtor) {
    short locals = 3; // this + factory + delegee
    Class<?>[] parameters = superCtor.getParameterTypes();

    // Note that we swapped arguments in app-facing constructors to avoid
    // conflicting signatures with serial constructor defined below.
    if (parameters.length == 0) {
      cfw.startMethod(
          "<init>",
          "(Laurora/javascript/Scriptable;" + "Laurora/javascript/ContextFactory;)V",
          ClassFileWriter.ACC_PUBLIC);

      // Invoke base class constructor
      cfw.add(ByteCode.ALOAD_0); // this
      cfw.addInvoke(ByteCode.INVOKESPECIAL, superName, "<init>", "()V");
    } else {
      StringBuilder sig =
          new StringBuilder(
              "(Laurora/javascript/Scriptable;" + "Laurora/javascript/ContextFactory;");
      int marker = sig.length(); // lets us reuse buffer for super signature
      for (Class<?> c : parameters) {
        appendTypeString(sig, c);
      }
      sig.append(")V");
      cfw.startMethod("<init>", sig.toString(), ClassFileWriter.ACC_PUBLIC);

      // Invoke base class constructor
      cfw.add(ByteCode.ALOAD_0); // this
      short paramOffset = 3;
      for (Class<?> parameter : parameters) {
        paramOffset += generatePushParam(cfw, paramOffset, parameter);
      }
      locals = paramOffset;
      sig.delete(1, marker);
      cfw.addInvoke(ByteCode.INVOKESPECIAL, superName, "<init>", sig.toString());
    }

    // Save parameter in instance variable "delegee"
    cfw.add(ByteCode.ALOAD_0); // this
    cfw.add(ByteCode.ALOAD_1); // first arg: Scriptable delegee
    cfw.add(ByteCode.PUTFIELD, adapterName, "delegee", "Laurora/javascript/Scriptable;");

    // Save parameter in instance variable "factory"
    cfw.add(ByteCode.ALOAD_0); // this
    cfw.add(ByteCode.ALOAD_2); // second arg: ContextFactory instance
    cfw.add(ByteCode.PUTFIELD, adapterName, "factory", "Laurora/javascript/ContextFactory;");

    cfw.add(ByteCode.ALOAD_0); // this for the following PUTFIELD for self
    // create a wrapper object to be used as "this" in method calls
    cfw.add(ByteCode.ALOAD_1); // the Scriptable delegee
    cfw.add(ByteCode.ALOAD_0); // this
    cfw.addInvoke(
        ByteCode.INVOKESTATIC,
        "aurora/javascript/JavaAdapter",
        "createAdapterWrapper",
        "(Laurora/javascript/Scriptable;"
            + "Ljava/lang/Object;"
            + ")Laurora/javascript/Scriptable;");
    cfw.add(ByteCode.PUTFIELD, adapterName, "self", "Laurora/javascript/Scriptable;");

    cfw.add(ByteCode.RETURN);
    cfw.stopMethod(locals);
  }
  public static void main(String[] args) throws Exception {
    java.io.File file =
        new java.io.File(
            "capacity.txt"); // A file use to tell the program how many question do we have.

    if (file.exists()) {
      Scanner input = new Scanner(file);
      String capacityForString = " ";
      while (input.hasNext()) {
        capacityForString = input.next(); // Read items
      }

      input.close(); // Close the file.
      int capacityForInt = Integer.parseInt(capacityForString); // String to integer.
      capacityForInt = capacityForInt + 1; // Avoid the index 0, so add one.
      FileReader fr = null;
      BufferedReader br = null;
      String[] question = new String[capacityForInt];
      try {
        fr = new FileReader("question.txt"); // A file holds the question.
        br = new BufferedReader(fr);
        String data;
        StringBuilder stringBuilderForQuestion = new StringBuilder();
        int index = 1;

        while ((data = br.readLine()) != null) {
          if (data.equals("-")) {
            String stringForQuestion =
                new String(stringBuilderForQuestion); // Convert stringBuilder into String data type
            question[index] =
                stringForQuestion; // A question has connected, so we input the string array.
            index = index + 1;
            stringBuilderForQuestion.delete(
                0, stringForQuestion.length()); // clear the StringBuilder.
          } else {
            stringBuilderForQuestion.append(data + "\n"); // connect the long question.
          }
        }
      } // end try
      catch (IOException e) {
      } finally {
        try {
          br.close(); // Because the br = new BufferedReader(fr); , we close the br.
        } catch (IOException e) {
        }
      } // end finally

      int chooseQuestion = (int) (Math.random() * capacityForInt); // choose a question for random.
      while (chooseQuestion == 0) {
        chooseQuestion = (int) (Math.random() * capacityForInt);
      }
      System.out.println(question[chooseQuestion]); // display the question on CMD.

    } else {
      System.out.println(
          "You loss a file which decide the capacity,so we cannot load the question."); // Wrong
                                                                                        // message
                                                                                        // for
                                                                                        // check.
    } // end if
  } // end main method