예제 #1
0
  private String md5(String data) {

    StringBuffer sb = new StringBuffer();

    try {
      MessageDigest messageDigest = MessageDigest.getInstance("MD5");
      messageDigest.update(data.getBytes());
      byte[] digestBytes = messageDigest.digest();

      /* convert to hexstring */
      String hex = null;

      for (int i = 0; i < digestBytes.length; i++) {
        hex = Integer.toHexString(0xFF & digestBytes[i]);

        if (hex.length() < 2) {
          sb.append("0");
        }
        sb.append(hex);
      }
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }

    return sb.toString();
  }
예제 #2
0
  // createPageString -
  // Create list of pages for search results
  private String createPageString(
      int numberOfItems, int itemsPerPage, int currentPage, String baseUrl) {
    StringBuffer pageString = new StringBuffer();

    // Calculate the total number of pages
    int totalPages = 1;
    if (numberOfItems > itemsPerPage) {
      double pages = Math.ceil(numberOfItems / (double) itemsPerPage);
      totalPages = (int) Math.ceil(pages);
    }

    //
    if (totalPages > 1) {
      for (int i = 1; i <= totalPages; i++) {
        if (i == currentPage) {
          pageString.append(i);
        } else {
          pageString.append("<a href=\"" + baseUrl + i + "\" title=\"" + i + "\">" + i + "</a>");
        }

        if (i != totalPages) pageString.append(" ");
      }
    } else {
      pageString.append("1");
    }

    return pageString.toString();
  }
예제 #3
0
  protected String gettitle(String strFreq) {
    StringBuffer sbufTitle = new StringBuffer().append("VnmrJ  ");
    String strPath = FileUtil.openPath(FileUtil.SYS_VNMR + "/vnmrrev");
    BufferedReader reader = WFileUtil.openReadFile(strPath);
    String strLine;
    String strtype = "";
    if (reader == null) return sbufTitle.toString();

    try {
      while ((strLine = reader.readLine()) != null) {
        strtype = strLine;
      }
      strtype = strtype.trim();
      if (strtype.equals("merc")) strtype = "Mercury";
      else if (strtype.equals("mercvx")) strtype = "Mercury-Vx";
      else if (strtype.equals("mercplus")) strtype = "MERCURY plus";
      else if (strtype.equals("inova")) strtype = "INOVA";
      String strHostName = m_strHostname;
      if (strHostName == null) strHostName = "";
      sbufTitle.append("    ").append(strHostName);
      sbufTitle.append("    ").append(strtype);
      sbufTitle.append(" - ").append(strFreq);
      reader.close();
    } catch (Exception e) {
      // e.printStackTrace();
      Messages.logError(e.toString());
    }

    return sbufTitle.toString();
  }
예제 #4
0
 public String toString() {
   StringBuffer sb = new StringBuffer(url.length() + 17);
   sb.append("[MyMockCachedUrl: ");
   sb.append(url);
   sb.append("]");
   return sb.toString();
 }
  public static void main(String[] args) {

    StringBuffer result = new StringBuffer("<html><body><h1>Fibonacci Sequence</h1><ol>");

    long f1 = 0;
    long f2 = 1;

    for (int i = 0; i < 50; i++) {
      result.append("<li>");
      result.append(f1);
      long temp = f2;
      f2 = f1 + f2;
      f1 = temp;
    }

    result.append("</ol></body></html>");

    JEditorPane jep = new JEditorPane("text/html", result.toString());
    jep.setEditable(false);

    //  new FibonocciRectangles().execute();
    JScrollPane scrollPane = new JScrollPane(jep);
    JFrame f = new JFrame("Fibonacci Sequence");
    f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    f.setContentPane(scrollPane);
    f.setSize(512, 342);
    EventQueue.invokeLater(new FrameShower(f));
  }
예제 #6
0
 /**
  * ** Reads a line from the specified socket's input stream ** @param socket The socket to read a
  * line from ** @param maxLen The maximum length of of the line to read ** @param sb The string
  * buffer to use ** @throws IOException if an error occurs or the server has stopped
  */
 protected static String socketReadLine(Socket socket, int maxLen, StringBuffer sb)
     throws IOException {
   if (socket != null) {
     int dataLen = 0;
     StringBuffer data = (sb != null) ? sb : new StringBuffer();
     InputStream input = socket.getInputStream();
     while ((maxLen < 0) || (maxLen > dataLen)) {
       int ch = input.read();
       // Print.logInfo("ReadLine char: " + ch);
       if (ch < 0) {
         // this means that the server has stopped
         throw new IOException("End of input");
       } else if (ch == LineTerminatorChar) {
         // include line terminator in String
         data.append((char) ch);
         dataLen++;
         break;
       } else {
         // append character
         data.append((char) ch);
         dataLen++;
       }
     }
     return data.toString();
   } else {
     return null;
   }
 }
예제 #7
0
  /** Return a String representation of this object. */
  public String toString() {

    if (filterConfig == null) return ("KeepSession()");
    StringBuffer sb = new StringBuffer("KeepSession(");
    sb.append(filterConfig);
    sb.append(")");
    return (sb.toString());
  }
예제 #8
0
파일: DFSMonitor.java 프로젝트: selamat/dfs
 /**
  * 构造访问sms url需要参数
  *
  * @param title
  * @param content
  */
 public void alert(String title, String content) {
   StringBuffer param = new StringBuffer("");
   param.append("function=").append(title).append("&");
   param.append("ms=").append(content).append("&");
   param.append("mo=").append(this.phone).append("&");
   param.append("priority=Z");
   this.sendPost(param.toString(), false);
 }
예제 #9
0
 public String getNameString() {
   StringBuffer str = new StringBuffer();
   for (int i = 0; i < nameStrings.length; i++) {
     if (i > 0) str.append("/");
     str.append(nameStrings[i]);
   }
   return str.toString();
 }
예제 #10
0
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(this.key);
   if (this.hasValue()) {
     sb.append("=").append(this.val);
   }
   return sb.toString();
 }
예제 #11
0
 private static String generateSendString(int seq) {
   StringBuffer buf = new StringBuffer("PING ");
   buf.append(seq);
   buf.append(' ');
   SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
   buf.append(fmt.format(new Date()));
   buf.append('\n');
   return buf.toString();
 }
예제 #12
0
파일: URIArg.java 프로젝트: colima/OpenDMTP
 public String toString() {
   StringBuffer sb = new StringBuffer();
   sb.append(this.key);
   String v = this.val;
   if ((v != null) && !v.equals("")) {
     sb.append("=").append(v);
   }
   return sb.toString();
 }
예제 #13
0
 private void checkMD(StringBuffer sb, NameValueRecord nvr, String name, String value) {
   String id = nvr.getString(name);
   if (id == null) {
     sb.append("#e  no ").append(name).append(" in metadata\n");
   } else if (!id.equals(value)) {
     sb.append("#e  original/md ").append(name).append(": ");
     sb.append(value).append(" / ").append(id).append("\n");
   }
 }
예제 #14
0
 /**
  * Codage d'une chaine pour servir en tant que nom de fichier. Remplace tous ce qui n'est ni
  * lettre ni chiffre en code hexa préfixé par _
  */
 private static String codage(String s) {
   StringBuffer r = new StringBuffer();
   char a[] = s.toCharArray();
   for (int i = 0; i < a.length; i++) {
     char c = a[i];
     if (!Character.isLetterOrDigit(c)) r.append(PREFIX + Util.hex(c));
     else r.append(c);
   }
   return r.toString();
 }
예제 #15
0
 public String convertToCommaDelimited(String[] list) {
   StringBuffer ret = new StringBuffer("");
   for (int i = 0; list != null && i < list.length; i++) {
     ret.append(list[i]);
     if (i < list.length - 1) {
       ret.append(',');
     }
   }
   return ret.toString();
 }
예제 #16
0
파일: dns.java 프로젝트: lemmy/dnsjava
 public static String inaddrString(InetAddress addr) {
   byte[] address = addr.getAddress();
   StringBuffer sb = new StringBuffer();
   for (int i = 3; i >= 0; i--) {
     sb.append(address[i] & 0xFF);
     sb.append(".");
   }
   sb.append(".IN-ADDR.ARPA.");
   return sb.toString();
 }
예제 #17
0
 /** Return string representation of this VMID. */
 public String toString() {
   StringBuffer result = new StringBuffer();
   if (addr != null)
     for (int i = 0; i < addr.length; ++i) {
       int x = (int) (addr[i] & 0xFF);
       result.append((x < 0x10 ? "0" : "") + Integer.toString(x, 16));
     }
   result.append(':');
   result.append(uid.toString());
   return result.toString();
 }
예제 #18
0
파일: UDP.java 프로젝트: NZDIS/jgroups
  String getDiagResponse() {
    StringBuffer sb = new StringBuffer();
    sb.append(local_addr).append(" (").append(group_addr).append(")");
    sb.append(" [").append(mcast_addr_name).append(":").append(mcast_port).append("]\n");
    //    sb.append("Version=").append(Version.version).append(", cvs=\"").append(
    //        Version.cvs).append("\"\n");
    sb.append("bound to ").append(bind_addr).append(":").append(bind_port).append("\n");
    sb.append("members: ").append(members).append("\n");

    return sb.toString();
  }
예제 #19
0
파일: URIArg.java 프로젝트: colima/OpenDMTP
 /**
  * ** Returns a String representation of all key/values ** @param sbuff The StringBuffer to write
  * the key/values to, or null ** for a new one ** @return A String representation of all
  * key/values
  */
 public StringBuffer getArgString(StringBuffer sbuff) {
   StringBuffer sb = (sbuff != null) ? sbuff : new StringBuffer();
   for (Iterator i = this.getKeyValList().iterator(); i.hasNext(); ) {
     KeyVal kv = (KeyVal) i.next();
     sb.append(kv.toString());
     if (i.hasNext()) {
       sb.append("&");
     }
   }
   return sb;
 }
예제 #20
0
 public String getSalt() {
   if (salt == null) {
     StringBuffer salt = new StringBuffer();
     salt.append(nameRealm.toString());
     for (int i = 0; i < nameStrings.length; i++) {
       salt.append(nameStrings[i]);
     }
     return salt.toString();
   }
   return salt;
 }
예제 #21
0
  /** Very lazy byte[] to URL encoder. Just encodes everything, even "normal" chars. */
  static String urlencode(byte[] bs) {
    StringBuffer sb = new StringBuffer(bs.length * 3);
    for (int i = 0; i < bs.length; i++) {
      int c = bs[i] & 0xFF;
      sb.append('%');
      if (c < 16) sb.append('0');
      sb.append(Integer.toHexString(c));
    }

    return sb.toString();
  }
예제 #22
0
 /**
  * print the informations for one specified port
  *
  * @param i theport
  * @param output where to write/print
  * @throws IOException
  */
 private void printInfoPort(int i, BufferedWriter output) throws IOException {
   StringBuffer sb = new StringBuffer();
   InetSocketAddress os = getPort(i).getIsa();
   sb.append("Port <" + new Integer(i).toString() + ">\n State : ");
   if (os == null) sb.append("down");
   else {
     sb.append("up\n");
     sb.append(" Colision domain : " + os);
   }
   output.write(sb.toString() + "\n");
   output.flush();
 }
예제 #23
0
  protected void _save() {
    jEdit.setBooleanProperty("view.showToolbar", showToolbar.isSelected());

    StringBuffer buf = new StringBuffer();
    for (int i = 0; i < listModel.getSize(); i++) {
      if (i != 0) buf.append(' ');
      Button button = (Button) listModel.elementAt(i);
      buf.append(button.actionName);
      jEdit.setProperty(button.actionName + ".icon", button.iconName);
    }
    jEdit.setProperty("view.toolbar", buf.toString());
  }
예제 #24
0
  @Override
  public String lookForExpiredAuction(int auctionId) throws RemoteException {
    ExpiredAuctionItem temp;
    StringBuffer sb = new StringBuffer();

    if ((temp = expiredAuctions.get(auctionId)) != null) {
      System.out.println("Expired auction found, results of this auction :" + temp.getResult());
      sb.append("Results of this auction :\n" + temp.getResult() + "\n");
      sb.append("General info of this auction : \n" + temp.toString() + "\n");
    }

    return sb.toString();
  }
예제 #25
0
 private static String doFormUrlEncode(Map<String, String> map) {
   StringBuffer encodedString = new StringBuffer(map.size() * 20);
   for (String key : map.keySet()) {
     if (encodedString.length() > 0) {
       encodedString.append(PARAM_SEPARATOR);
     }
     encodedString.append(urlEncodeWrapper(key));
     if (map.get(key).length() > 0) {
       encodedString.append(PAIR_SEPARATOR).append(urlEncodeWrapper(map.get(key)));
     }
   }
   return encodedString.toString();
 }
예제 #26
0
  /**
   * Process listuser from server
   *
   * @param doc
   */
  private void _listuser(Document doc) {
    StringBuffer userlist = new StringBuffer();

    Element root = doc.getRootElement();
    Element list = root.getChild("listuser");
    List users = list.getChildren("user");
    Iterator i = users.iterator();
    while (i.hasNext()) {
      userlist.append(((Element) i.next()).getText());
      userlist.append("\n");
    }
    sendMessage(SERVER, "Users: \n" + userlist);
  }
예제 #27
0
파일: Util.java 프로젝트: rhusar/smartfrog
 public static String commonString(String s1, String s2, String delim) {
   Vector v1 = str2vec(s1, delim);
   Vector v2 = str2vec(s2, delim);
   StringBuffer buf = new StringBuffer();
   for (int i = 0; i < v1.size(); i++) {
     String s = (String) v1.elementAt(i);
     if (v2.contains(s)) {
       if (buf.length() > 0) buf.append(delim);
       buf.append(s);
     }
   }
   return buf.toString();
 }
예제 #28
0
파일: kbSRU.java 프로젝트: STITCHplus/kbSRU
 public StringBuffer construct_lucene_solr(StringBuffer result, SolrDocument d) {
   for (String field : (d.getFieldNames())) {
     if ((!field.endsWith("_str")) && (!field.equalsIgnoreCase("fullrecord"))) {
       Iterator j = d.getFieldValues(field).iterator();
       while (j.hasNext()) {
         result.append("<" + field + ">");
         result.append(helpers.xmlEncode((String) j.next().toString()));
         field = field.split(" ")[0];
         result.append("</" + field + ">");
       }
     }
   }
   return (result);
 }
예제 #29
0
  /**
   * <code>appendItem</code> appends the XML representation of the current packet data to the
   * specified <code>StringBuffer</code>.
   *
   * @param retval The <code>StringBuffer</code> to append to
   */
  public void appendItem(StringBuffer retval) {
    retval.append("<query xmlns=\"jabber:iq:pass\">");

    // Now append the server
    if (server_url != null) {
      retval.append("<server ");
      appendAttrib(retval, "port", Integer.toString(server_port));
      retval.append(">" + server_url + "</server>");
    }

    // Now append the client
    if (client_url != null) {
      retval.append("<client ");
      appendAttrib(retval, "port", Integer.toString(client_port));
      retval.append(">" + client_url + "</client>");
    }

    // Now append the proxy
    if (proxy_url != null) {
      retval.append("<proxy ");
      appendAttrib(retval, "port", Integer.toString(proxy_port));
      retval.append(">" + proxy_url + "</proxy>");
    }

    // The connection expiration limit
    appendChild(retval, "expire", Integer.toString(expiration));

    // Append close tag
    retval.append("</query>");
  }
예제 #30
0
 /** Réciproque à la fonction codage() */
 private static String decodage(String s) {
   StringBuffer r = new StringBuffer();
   char a[] = s.toCharArray();
   for (int i = 0; i < a.length; i++) {
     char c = a[i];
     if (c != PREFIX) r.append(c);
     else {
       c = (char) (code(a[i + 1]) * 16 + code(a[i + 2]));
       r.append(c);
       i += 2;
     }
   }
   return r.toString();
 }