Package java.lang

Examples of java.lang.StringBuffer


    int iRnd;
    long lSeed = new Date().getTime();
    Random oRnd = new Random(lSeed);
    String sHex;
    StringBuffer sUUID = new StringBuffer(32);
    byte[] localIPAddr = new byte[4];

    try {

      // 8 characters Code IP address of this machine
      localIPAddr = InetAddress.getLocalHost().getAddress();

      sUUID.append(byteToStr[((int) localIPAddr[0]) & 255]);
      sUUID.append(byteToStr[((int) localIPAddr[1]) & 255]);
      sUUID.append(byteToStr[((int) localIPAddr[2]) & 255]);
      sUUID.append(byteToStr[((int) localIPAddr[3]) & 255]);
    }
    catch (UnknownHostException e) {
      // Use localhost by default
      sUUID.append("7F000000");
    }

    // Append a seed value based on current system date
    sUUID.append(Long.toHexString(lSeed));

    // 6 characters - an incremental sequence
    sUUID.append(Integer.toHexString(iSequence++));

    if (iSequence>16777000) iSequence=1048576;

    do {
      iRnd = oRnd.nextInt();
      if (iRnd>0) iRnd = -iRnd;
      sHex = Integer.toHexString(iRnd);
    } while (0==iRnd);

    // Finally append a random number
    sUUID.append(sHex);

    return sUUID.substring(0, 32);
  } // generateUUID()
View Full Code Here


   
  if (byCategory!=Character.UNASSIGNED && byCategory!=Character.UPPERCASE_LETTER && byCategory!=Character.LOWERCASE_LETTER)
    throw new IllegalArgumentException("Gadgets.generateRandomId() Character category must be one of {UNASSIGNED, UPPERCASE_LETTER, LOWERCASE_LETTER}");

  int iCsLen = sCharset.length();
    StringBuffer oId = new StringBuffer(iLength);
    Random oRnd = new Random(new Date().getTime());
    for (int i=0; i<iLength; i++){
    char c = sCharset.charAt(oRnd.nextInt(iCsLen));
    if (byCategory==Character.UPPERCASE_LETTER)
      c = Character.toUpperCase(c);
    else if (byCategory==Character.LOWERCASE_LETTER)
      c = Character.toLowerCase(c);
    oId.append(c);
  } // next
  return oId.toString();
  } // generateRandomId
View Full Code Here

   * @return String
   */
  public static String XHTMLEncode(String text) {
    char c;
    int len = text.length();
    StringBuffer results = new StringBuffer(len*2);

    for (int i = 0; i < len; ++i) {
      c = text.charAt(i);
      if (c<=127) {
    results.append(c);
      } else {
        results.append("&#"+String.valueOf((int)c)+";");
      }
    }
    return results.toString();
  }
View Full Code Here

        super(h);
        m_ilen = ilen;
        m_ibuf = ByteBuffer.allocate(ilen);
        m_olen = olen;
        m_obuf = ByteBuffer.allocate(olen);
        m_line = new StringBuffer(4096);
    } // TcpSocket
View Full Code Here

            "");
    String html = "&auml; &Auml; &ouml; &Ouml; &lt; &amp; &gt; " +
      "&apos; &nbsp; &quot;";
    appendEntityAlphaTest("Test with one entity.", html,
            "");
    StringBuffer sbControl = new StringBuffer();
    for (int ic = 0x80; ic <= 0x9f; ic++) {
      sbControl.append((char)ic);
    }
    super.append("control(0)=\n" + sbControl.charAt(0) + "," + Integer.toHexString(sbControl.charAt(0)));
    String control = sbControl.toString();
    char[] cc = new char[sbControl.length()];
    sbControl.getChars(0, cc.length, cc, 0);
    String control2 = new String(cc);
    super.append("control(0)=\n" + control.charAt(0) + "," + Integer.toHexString(control.charAt(0)));
    super.append("control2(0)=\n" + control2.charAt(0) + "," + Integer.toHexString(control2.charAt(0)));
    String cvControl = control;
    try {
      cvControl = new String(control.getBytes("ISO-8859_1"), "Cp1252");
    } catch (UnsupportedEncodingException e) {
      super.append("Conversion error for win contol string.");
    }
    super.append("cvControl(0)=\n" + cvControl.charAt(0) + "," + Integer.toHexString(cvControl.charAt(0)));
    String ncontrol = EncodingUtil.replaceSpChars(cvControl, true, false,
        false, false);
    super.append("converted cvControl,ncontrol=\n" + ncontrol.charAt(0) + "," + Integer.toHexString(ncontrol.charAt(0)));
    StringBuffer sbTst = new StringBuffer();
    StringBuffer sbRes = new StringBuffer();
    appendHashTest("Iso entities", EncodingUtil.getConvIso88591(), sbTst, sbRes);
    // Convert from ISO to iso
    String cvRes = EncodingUtil.replaceSpChars(sbRes.toString(),
        false, false, false, false);
    StringBuffer sbwTst = new StringBuffer();
    StringBuffer sbwRes = new StringBuffer();
    appendHashTest("cp1252 entities", EncodingUtil.getConvCp1252(), sbwTst, sbwRes);
    // Convert from windows to windows
    String cvwRes = EncodingUtil.replaceSpChars(sbwRes.toString(),
        true, false, true, false);
    appendEntitySpTest("Test with iso conv to iso midp phone.",
        sbRes.toString(), false, false, false, cvRes);
    // Convert from windows to windows .  Given that windows uses
    // ISO control characters, it should not match the other encoding.
    appendEntitySpTest("Test with win conv to iso midp phone.",
        sbwRes.toString(), true, false, false, cvRes);
    appendEntitySpTest("Test with win conv to win midp phone.",
        sbwRes.toString(), true, true, false, cvwRes);
    // Convert from ISO to windows.  Given that windows supports
    // the ISO characters, it should match other decoding too.
    appendEntitySpTest("Test with iso conv to windows midp phone.",
        sbRes.toString(), false, true, false, cvwRes);
    appendEntitySpTest("Test with iso sponly conv to iso midp phone.",
        control, false, false, false, control);
    // Convert from windows to windows .  Given that windows uses
    // ISO control characters, it should not match the other encoding.
    appendEntitySpTest("Test with win sponly conv to iso midp phone.",
        control, true, false, false, control);
    appendEntitySpTest("Test with win sponly conv to win midp phone.",
        control, true, true, false, control);
    // Convert from ISO to windows.  Given that windows supports
    // the ISO characters, it should match other decoding too.
    appendEntitySpTest("Test with iso sponly conv to windows midp phone.",
        control, false, true, false, control);
    String[] isoSp = EncodingUtil.getIsoSpecialEntities();
    char[] isoSpVals =
      {'-', // en dash
      '-', // em dash
      '\'', // left single quotation mark
      '\'', // right single quotation mark
      '\'', // single low-9 quotation mark
      '\"', // left double quotation mark
      '\"', // right double quotation mark
      '\"'}; // double low-9 quotation mark
    Hashtable isoConv = new Hashtable();
    EncodingUtil.initEntVals(isoConv, isoSp, isoSpVals);
    StringBuffer sbSp = new StringBuffer();
    StringBuffer sbSpRes = new StringBuffer();
    appendHashTest("Iso special entities", isoConv, sbSp, sbSpRes);
  }
View Full Code Here

          String date=st.nextToken().trim();
          st.nextToken();
          String state=st.nextToken().trim();
    setBackground((Color) ht_string2color.get(state));
    StringTokenizer st2 = new StringTokenizer(((DefaultMutableTreeNode)dmtn.getFirstChild()).toString()," | ");
    StringBuffer ttt=new StringBuffer(
      "<html><B>IP = </B>"+/*IP=<ip> Profil=<port>/<profil>*/dmtn.getParent().getParent()+"<B> Profil =</B>"+dmtn.getParent()+
      "<br><B>Bundle : </B>"+/*Bundle : Id=<bundleId> : <bundleSymbolicName>*/dmtn+
      "<br><B>Date : </B>"+/*<date> - <time>*/st2.nextToken()+" - "+st2.nextToken()+
      "<br><B>State on last log : "+/*<bundleState>*/st2.nextToken()+
        "<br>Event "+/*Event <eventNumber> : <logLevel> : <message>*/dmtn.getChildCount()+" : "+st2.nextToken()+" : </B><br>");
    while (st2.hasMoreTokens()) {
      ttt.append(st2.nextToken()+" ");
    }
    setToolTipText(ttt+"</html>");
  }
        break;
      }
View Full Code Here

    else
      return false;
  }
 
  public String getSelectedAsString() {
    StringBuffer buffer = new StringBuffer();
    for(Iterator<String> iter = selected.iterator();iter.hasNext();) {
      buffer.append(iter.next());
     
      if(iter.hasNext())
        buffer.append(",");
    }
   
    return buffer.toString();
  }
View Full Code Here

    protected String leftMiddleRight(String left,
                                     String middle,
                                     String right)
    {
        StringBuffer sb = new StringBuffer(left.length()
                                           +right.length()
                                           +middle.length());
        leftMiddleRight(sb, left, middle, right);
        return sb.toString();
    }
View Full Code Here

        //list and converting each item to a string and summing
        //their lengths, but would that would be any less
        //expensive than letting the StringBuffer resize itself?
        int size = left.length() + right.length() +
                   ((connector.length() + 7) * list.size());
        StringBuffer sb = new StringBuffer(size);
        leftRightListConnector(sb, left, right, list, connector);
        return sb.toString();
    }
View Full Code Here

     * @param rawText The <i>unquoted</i>, <i>unescaped</i> text to process.
     * @return Quoted and escaped text.
     */
    public String quoteAndEscapeText(String rawText)
    {
        StringBuffer buf = new StringBuffer( (int)(rawText.length() * 1.1) );

        char[] data = rawText.toCharArray();
        buf.append(SINGLE_QUOTE);
        for (int i = 0; i < data.length; i++)
        {
            switch (data[i])
            {
            case SINGLE_QUOTE:
                buf.append(SINGLE_QUOTE).append(SINGLE_QUOTE);
                break;
            // Some databases need to have backslashes escaped.
            // Subclasses can override this method to include
            // this case if appropriate.
            /*
                case BACKSLASH:
                buf.append(BACKSLASH).append(BACKSLASH);
                break;
            */
            default:
                buf.append(data[i]);
            }
        }
        buf.append(SINGLE_QUOTE);

        return buf.toString();
    }
View Full Code Here

TOP

Related Classes of java.lang.StringBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.