コード例 #1
1
  public String debugString() {
    StringBuilder buf = new StringBuilder("DBTCPConnector: ");
    if (_allHosts != null) buf.append("paired : ").append(_allHosts);
    else buf.append(_curAddress).append(" ").append(_curAddress._addr);

    return buf.toString();
  }
コード例 #2
1
  /**
   * Performs OCR operation.
   *
   * @param imageList a list of <code>IIOImage</code> objects
   * @param rect the bounding rectangle defines the region of the image to be recognized. A
   *     rectangle of zero dimension or <code>null</code> indicates the whole image.
   * @return the recognized text
   * @throws TesseractException
   */
  public String doOCR(List<IIOImage> imageList, Rectangle rect) throws TesseractException {
    init();
    setTessVariables();

    try {
      StringBuilder sb = new StringBuilder();

      for (IIOImage oimage : imageList) {
        pageNum++;
        try {
          setImage(oimage.getRenderedImage(), rect);
          sb.append(getOCRText());
        } catch (IOException ioe) {
          // skip the problematic image
          logger.log(Level.SEVERE, ioe.getMessage(), ioe);
        }
      }

      if (hocr) {
        sb.insert(0, htmlBeginTag).append(htmlEndTag);
      }

      return sb.toString();
    } finally {
      dispose();
    }
  }
コード例 #3
1
 public static void __getNotes(String url, String token, Long[] ids)
     throws MoodleRestNotesException, MoodleRestException, UnsupportedEncodingException {
   if (MoodleCallRestWebService.isLegacy())
     throw new MoodleRestNotesException(MoodleRestException.NO_LEGACY);
   // MoodleWarning[] warnings=null;
   String functionCall = MoodleServices.CORE_NOTES_GET_NOTES.toString();
   StringBuilder data = new StringBuilder();
   data.append(URLEncoder.encode("wstoken", MoodleServices.ENCODING.toString()))
       .append("=")
       .append(URLEncoder.encode(token, MoodleServices.ENCODING.toString()));
   data.append("&")
       .append(URLEncoder.encode("wsfunction", MoodleServices.ENCODING.toString()))
       .append("=")
       .append(URLEncoder.encode(functionCall, MoodleServices.ENCODING.toString()));
   for (int i = 0; i < ids.length; i++) {
     if (ids[i] == null) throw new MoodleRestNotesException();
     else
       data.append("&")
           .append(URLEncoder.encode("notes[" + i + "]", MoodleServices.ENCODING.toString()))
           .append("=")
           .append(ids[i]);
   }
   data.trimToSize();
   NodeList elements = (new MoodleCallRestWebService()).__call(url, data.toString());
   // return warnings;
 }
コード例 #4
0
  @Override
  String get(String id) {
    File file = new File(id);
    StringBuilder sb = new StringBuilder();

    BufferedReader br = null;
    try {
      br = new BufferedReader(new FileReader(file));
      String line = br.readLine();

      while (line != null) {
        sb.append(line);
        sb.append("\n");
        line = br.readLine();
      }
    } catch (IOException e) {
      throw new EditorException(e.getMessage());
    } finally {
      if (br != null) {
        try {
          br.close();
        } catch (IOException e) {
          Logger.getLogger(getClass().getName()).severe(e.getMessage());
        }
      }
    }
    return sb.toString();
  }
コード例 #5
0
 public String substring(int start, int end) {
   StringBuilder sb = new StringBuilder();
   for (int i = start; i < end; i++) {
     sb.append(getChar(i));
   }
   return sb.toString();
 }
コード例 #6
0
 public String toString() {
   StringBuilder sb = new StringBuilder(this.getClass().getSimpleName()).append('{');
   for (TypedValues typed : _values) {
     sb.append(typed);
   }
   return sb.append('}').toString();
 }
コード例 #7
0
 public String getSuffixString() {
   StringBuilder sb = new StringBuilder();
   for (int i = offset; i <= string.length(); i++) {
     sb.append(string.getChar(i));
   }
   return sb.toString();
 }
コード例 #8
0
 private String bytesToHex(byte[] bytes) {
   StringBuilder result = new StringBuilder();
   for (byte byt : bytes) {
     result.append(Integer.toString((byt & 0xff) + 0x100, 16).substring(1));
   }
   return result.toString();
 }
コード例 #9
0
 /**
  * View traces for debugging
  *
  * @return printable version of traces
  */
 public static String getTraces() {
   StringBuilder sb = new StringBuilder();
   for (String s : undisposed.values()) {
     sb.append(s);
     sb.append("\n");
   }
   return sb.toString();
 }
コード例 #10
0
ファイル: LibRt.java プロジェクト: yamila87/rt_src
 public static void logmex(String t, int lvl, String msg, Object o, Exception ex) {
   StringBuilder sb = new StringBuilder();
   StackTraceElement se[] = ex.getStackTrace();
   for (int i = 0; i < se.length; i++) {
     sb.append(se[i].getMethodName() + "@" + se[i].getFileName() + "@" + se[i].getLineNumber());
     sb.append(" > ");
   }
   logm(t, lvl, msg + " EXCEPTION " + ex + " " + sb.toString(), o);
 }
コード例 #11
0
 private static String byteArrayToHexString(byte[] bytes) {
   StringBuilder sb = new StringBuilder(2 * bytes.length);
   try (Formatter formatter = new Formatter(sb)) {
     for (byte b : bytes) {
       formatter.format("%02x", b);
     }
   }
   return sb.toString();
 }
コード例 #12
0
ファイル: NodeRunnerDcom.java プロジェクト: winsx/Payara
  private static String commandListToString(List<String> command) {
    StringBuilder fullCommand = new StringBuilder();

    for (String s : command) {
      fullCommand.append(" ");
      fullCommand.append(s);
    }

    return fullCommand.toString();
  }
コード例 #13
0
ファイル: OCSSWRuntimeConfig.java プロジェクト: mg1989/seadas
 private static String assembleLibDirPaths(String[] libDirPaths) {
   StringBuilder sb = new StringBuilder(64);
   for (String libDirPath : libDirPaths) {
     if (sb.length() > 0) {
       sb.append(File.pathSeparator);
     }
     sb.append(libDirPath);
   }
   return sb.toString();
 }
コード例 #14
0
  @Override
  public synchronized String format(LogRecord record) {
    StringBuilder sb = new StringBuilder();

    sb.append(dateFormat.format(new Date(record.getMillis())));
    sb.append(' ');
    sb.append(record.getLevel().getLocalizedName());
    sb.append(": ");
    sb.append(formatMessage(record));
    sb.append(LINE_SEPARATOR);

    if (record.getThrown() != null) {
      try {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        record.getThrown().printStackTrace(pw);
        pw.close();
        sb.append(sw.toString());
      } catch (Exception e) {
        // ignore
      }
    }

    return sb.toString();
  }
コード例 #15
0
ファイル: Judge.java プロジェクト: rgrig/homework-eval
 public void run() {
   try {
     int c;
     StringBuilder sb = new StringBuilder();
     while ((c = source.read()) != -1) sb.append((char) c);
     result = sb.toString();
     source.close();
   } catch (IOException e) {
     exception = e;
   }
 }
コード例 #16
0
  private static String toPrintable(String line, int max) {
    StringBuilder b = new StringBuilder();

    for (int i = 0; i < line.length(); ++i) {
      if (i >= max) break;
      char c = line.charAt(i);
      if (c >= ' ' && c <= '~') b.append(c);
      else b.append('.');
    }
    return b.toString();
  }
コード例 #17
0
 public String pathLabel() {
   if (parentEdge != null) {
     StringBuilder sb = new StringBuilder(parentEdge.headNode.pathLabel());
     for (int i = 0; i < parentEdge.length(); i++) {
       sb.append(parentEdge.getChar(i));
     }
     return sb.toString();
   } else {
     return "";
   }
 }
コード例 #18
0
 public String toString() {
   int size = args.size();
   StringBuilder sb =
       new StringBuilder(name)
           .append('@')
           .append(hashCode())
           .append(':')
           .append(size)
           .append('\n');
   for (int i = 0; i < size; ++i) {
     sb.append(args.get(i).get(0)).append('\n');
   }
   return sb.toString();
 }
コード例 #19
0
ファイル: LibRt.java プロジェクト: yamila87/rt_src
 public static String get_stream(Reader isr) throws IOException {
   char[] buffer = new char[BUFF_SZ];
   StringBuilder out = new StringBuilder();
   logm("DBG", 9, "STREAM GET", isr + "");
   for (; ; ) {
     int rsz = isr.read(buffer, 0, buffer.length);
     logm("DBG", 9, "STREAM GET READ", rsz);
     if (rsz < 0) break;
     out.append(buffer, 0, rsz);
   }
   String s = out.toString();
   logm("DBG", 9, "STREAM GET RESULT", s);
   return s;
 }
コード例 #20
0
ファイル: MainFX.java プロジェクト: hius74/projects
  public static void showError(String message, Throwable t) {
    LOG.log(Level.SEVERE, "Сообщение: " + message, t);

    StringBuilder s = new StringBuilder(message).append('\n');
    s.append(t.getClass().getName()).append(": ").append(t.getLocalizedMessage());
    for (StackTraceElement e : t.getStackTrace()) {
      String line = e.toString();
      if (line.startsWith("my")) {
        s.append("\n    ").append(line);
      }
    }
    Alert alert = new Alert(Alert.AlertType.ERROR, s.toString(), ButtonType.OK);
    alert.showAndWait();
  }
コード例 #21
0
ファイル: NodeRunnerDcom.java プロジェクト: winsx/Payara
  /*
   * return 0 is success, otherwise failure
   */
  public final int runAdminCommandOnRemoteNode(
      Node thisNode, StringBuilder output, List<String> args, List<String> stdinLines)
      throws SSHCommandExecutionException, IllegalArgumentException, UnsupportedOperationException {

    String humanreadable = null;
    try {
      this.node = thisNode;
      dcomInfo = new DcomInfo(node);
      List<String> fullcommand = new ArrayList<String>();
      WindowsRemoteAsadmin asadmin = dcomInfo.getAsadmin();

      if (stdinLines != null && !stdinLines.isEmpty()) setupAuthTokenFile(fullcommand, stdinLines);

      fullcommand.addAll(args);
      humanreadable = dcomInfo.getNadminPath() + " " + commandListToString(fullcommand);

      // This is where the rubber meets the road...
      String out = asadmin.run(fullcommand);
      output.append(out);
      logger.info(Strings.get("remote.command.summary", humanreadable, out));
      return determineStatus(args);
    } catch (WindowsException ex) {
      throw new SSHCommandExecutionException(
          Strings.get("remote.command.error", ex.getMessage(), humanreadable), ex);
    } finally {
      teardownAuthTokenFile();
    }
  }
コード例 #22
0
ファイル: LibRt.java プロジェクト: yamila87/rt_src
 public static String get_stream(InputStream is, String encoding) throws IOException {
   if (encoding == null) {
     encoding = CfgEncodingDflt;
   }
   byte[] buffer = new byte[BUFF_SZ];
   StringBuilder out = new StringBuilder();
   logm("DBG", 9, "STREAM GET", is + "");
   for (; ; ) {
     int rsz = is.read(buffer, 0, buffer.length);
     logm("DBG", 9, "STREAM GET READ", rsz);
     if (rsz < 0) break;
     out.append(new String(buffer, 0, rsz, encoding));
   }
   String s = out.toString();
   logm("DBG", 9, "STREAM GET RESULT", s);
   return s;
 }
コード例 #23
0
ファイル: TimedObject.java プロジェクト: ayanch/DSLMON
  protected String buildMessage(Method method, Object[] args, long timeNanoSec) {
    String res = null;

    {
      StringBuilder sb = new StringBuilder();

      {
        sb.append("Object: \"");
        sb.append(resource.getClass().getSimpleName());
        sb.append("\n");

        sb.append("Method: \"");
        sb.append(method.toString());
        sb.append("\n");

        String time = null;

        if (timeNanoSec < 1000L * 1000L) // if time is less than one millisecond...
        {
          time = timeNanoSec + " ns";
        } else {
          if (timeNanoSec < 1000L * 1000L * 1000L) // if time is less than one second...
          {
            double timeMilliSec = ((double) timeNanoSec + 500L * 1000L) / (1000L * 1000L);

            String v = f.format(timeMilliSec);
            time = v + ". ms";
          } else {
            double timeSec =
                ((double) timeNanoSec + 500L * 1000L * 1000L) / (1000L * 1000L * 1000L);

            String v = f.format(timeSec);
            time = v + ". s";
          }
        }

        sb.append("Time: ");
        sb.append(time);
      }

      res = sb.toString();
    }

    return res;
  }
コード例 #24
0
    public String toString() {
      StringBuilder buf = new StringBuilder();
      buf.append("Replica Set Node: ").append(_addr).append("\n");
      buf.append("\t ok \t").append(_ok).append("\n");
      buf.append("\t ping \t").append(_pingTime).append("\n");

      buf.append("\t master \t").append(_isMaster).append("\n");
      buf.append("\t secondary \t").append(_isSecondary).append("\n");

      buf.append("\t priority \t").append(_priority).append("\n");

      return buf.toString();
    }
コード例 #25
0
  /** Save the bundle to a file. Returns false if save was not successful. */
  public boolean saveBundleToFile(final String localeName) {
    try {
      final File externalBundleDir = new File(EXTERNAL_BUNDLE_DIR);
      if (!externalBundleDir.isDirectory()) {
        externalBundleDir.mkdirs();
      }
      final String filename = EXTERNAL_BUNDLE_DIR + "langres_" + localeName + ".properties";
      final PrintWriter out =
          new PrintWriter(
              new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "UTF-8")));

      final TreeMap<String, String> sorter = new TreeMap<String, String>(bundle);

      for (final String string : sorter.keySet()) {
        String key = string;
        String val = getString(key);
        key = key.trim();
        val = val.trim();
        // change newlines in val into \n
        final StringBuilder sbTmp = new StringBuilder();
        for (int x = 0; x < val.length(); x++) {
          final char c = val.charAt(x);
          if (c == '\n') {
            sbTmp.append("\\n");
          } else {
            sbTmp.append(c);
          }
        }
        val = sbTmp.toString();

        out.println(key + "=" + val);
      }

      out.close();
      return true;
    } catch (final Throwable t) {
      logger.log(Level.SEVERE, "Error saving bundle.", t);
      return false;
    }
  }
コード例 #26
0
ファイル: UCFIndexerDriver.java プロジェクト: arunappulal/all
  private void setTestURL() {
    StringBuilder sb = new StringBuilder();
    sb.append(m_protocol);
    sb.append("://");
    sb.append(m_rootHost);

    if (!"80".equals(m_rootPort)) {
      sb.append(":");
      sb.append(m_rootPort);
    }

    sb.append(m_appl);
    m_url = sb.toString();
  }
コード例 #27
0
ファイル: LiteLoader.java プロジェクト: Nanonid/liteloader
  /** Query loaded mods for registered channels */
  protected void setupPluginChannels() {
    // Clear any channels from before
    pluginChannels.clear();

    // Enumerate mods for plugin channels
    for (PluginChannelListener pluginChannelListener : pluginChannelListeners) {
      List<String> channels = pluginChannelListener.getChannels();

      if (channels != null) {
        for (String channel : channels) {
          if (channel.length() > 16
              || channel.toUpperCase().equals("REGISTER")
              || channel.toUpperCase().equals("UNREGISTER")) continue;

          if (!pluginChannels.containsKey(channel)) {
            pluginChannels.put(channel, new LinkedList<PluginChannelListener>());
          }

          pluginChannels.get(channel).add(pluginChannelListener);
        }
      }
    }

    // If any mods have registered channels, send the REGISTER packet
    if (pluginChannels.keySet().size() > 0) {
      StringBuilder channelList = new StringBuilder();
      boolean separator = false;

      for (String channel : pluginChannels.keySet()) {
        if (separator) channelList.append("\u0000");
        channelList.append(channel);
        separator = true;
      }

      byte[] registrationData = channelList.toString().getBytes(Charset.forName("UTF8"));

      sendPluginChannelMessage("REGISTER", registrationData);
    }
  }
コード例 #28
0
  public String getRunData(Run run, String name) {
    File file = new File(getRunDir(run), name);
    String retVal = null;

    if (!file.exists()) return null;

    try {
      BufferedReader reader = new BufferedReader(new FileReader(file));
      StringBuilder builder = new StringBuilder();
      String line = null;

      while ((line = reader.readLine()) != null) {
        builder.append(line);
      }

      reader.close();
      retVal = builder.toString();
    } catch (Exception exp) {
      throw new IllegalArgumentException(
          "Error trying to read data at " + file.getAbsolutePath(), exp);
    }
    return retVal;
  }
コード例 #29
0
ファイル: ConsoleManager.java プロジェクト: kitskub/Glowstone
    @Override
    @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
    public String format(LogRecord record) {
      StringBuilder builder = new StringBuilder();

      builder.append(date.format(record.getMillis()));
      builder.append(" [");
      builder.append(record.getLevel().getLocalizedName().toUpperCase());
      builder.append("] ");
      builder.append(colorize(formatMessage(record)));
      builder.append('\n');

      if (record.getThrown() != null) {
        StringWriter writer = new StringWriter();
        record.getThrown().printStackTrace(new PrintWriter(writer));
        builder.append(writer.toString());
      }

      return builder.toString();
    }
コード例 #30
0
ファイル: CLIOptions.java プロジェクト: joliebig/Hercules
 private String validModesToString() {
   StringBuilder sb = new StringBuilder();
   String seperator = "";
   sb.append("[");
   for (String current : VALID_MODES) {
     sb.append(seperator);
     seperator = "/";
     sb.append(current);
   }
   sb.append("]");
   return sb.toString();
 }