Package gnu.java.lang

Examples of gnu.java.lang.CPStringBuilder


    ref = url.getRef();

    // Guess a reasonable size for the string buffer so we have to resize
    // at most once.
    int size = protocol.length() + authority.length() + file.length() + 24;
    CPStringBuilder sb = new CPStringBuilder(size);

    if (protocol.length() > 0)
      {
  sb.append(protocol);
  sb.append(":");
      }
   
    // If we have superfluous leading slashes (that means, at least 2)
    // we always add the authority component ("//" + host) to
    // avoid ambiguity. Otherwise we would generate an URL like
    // proto://home/foo
    // where we meant:
    // host: <empty> - file: //home/foo
    // but URL spec says it is:
    // host: home - file: /foo
    if (authority.length() != 0 || file.startsWith("//") )
      sb.append("//").append(authority).append(file);
    else
      sb.append(file);

    if (ref != null)
      sb.append('#').append(ref);

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


    if (fmtLocale == null)
      syms = new DateFormatSymbols();
    else
      syms = new DateFormatSymbols(fmtLocale);

    CPStringBuilder result = new CPStringBuilder();
    singleDateTimeConversion(result, cal, subConversion, syms);

    genericFormat(result.toString(), flags, width, precision);
  }
View Full Code Here

   */
  public static AlgorithmParameterGenerator getInstance(String algorithm,
                                                        Provider provider)
      throws NoSuchAlgorithmException
  {
    CPStringBuilder sb = new CPStringBuilder()
        .append("AlgorithmParameterGenerator for algorithm [")
        .append(algorithm).append("] from provider[")
        .append(provider).append("] could not be created");
    Throwable cause;
    try
      {
        Object spi = Engine.getInstance(ALGORITHM_PARAMETER_GENERATOR,
                                        algorithm,
                                        provider);
        return new AlgorithmParameterGenerator((AlgorithmParameterGeneratorSpi) spi,
                                               provider,
                                               algorithm);
      }
    catch (InvocationTargetException x)
      {
        cause = x.getCause();
        if (cause instanceof NoSuchAlgorithmException)
          throw (NoSuchAlgorithmException) cause;
        if (cause == null)
          cause = x;
      }
    catch (ClassCastException x)
      {
        cause = x;
      }
    NoSuchAlgorithmException x = new NoSuchAlgorithmException(sb.toString());
    x.initCause(cause);
    throw x;
  }
View Full Code Here

   * @see Provider
   */
  public static KeyFactory getInstance(String algorithm, Provider provider)
      throws NoSuchAlgorithmException
  {
    CPStringBuilder sb = new CPStringBuilder("KeyFactory for algorithm [")
        .append(algorithm).append("] from provider[")
        .append(provider).append("] could not be created");
    Throwable cause;
    try
      {
        Object spi = Engine.getInstance(KEY_FACTORY, algorithm, provider);
        return new KeyFactory((KeyFactorySpi) spi, provider, algorithm);
      }
    catch (InvocationTargetException x)
      {
        cause = x.getCause();
        if (cause instanceof NoSuchAlgorithmException)
          throw (NoSuchAlgorithmException) cause;
        if (cause == null)
          cause = x;
      }
    catch (ClassCastException x)
      {
        cause = x;
      }
    NoSuchAlgorithmException x = new NoSuchAlgorithmException(sb.toString());
    x.initCause(cause);
    throw x;
  }
View Full Code Here

   *
   * @deprecated
   */
  public final String readLine() throws IOException
  {
    CPStringBuilder strb = new CPStringBuilder();

    while (true)
      {
        int c = in.read();
  if (c == -1// got an EOF
      return strb.length() > 0 ? strb.toString() : null;
  if (c == '\r')
    {
      int next_c = in.read();
            if (next_c != '\n' && next_c != -1)
              {
                if (!(in instanceof PushbackInputStream))
                  in = new PushbackInputStream(in);
                ((PushbackInputStream) in).unread(next_c);
              }
            break;
    }
        if (c == '\n')
            break;
  strb.append((char) c);
      }

    return strb.length() > 0 ? strb.toString() : "";
  }
View Full Code Here

  static String convertFromUTF (byte[] buf)
    throws EOFException, UTFDataFormatException
  {
    // Give StringBuffer an initial estimated size to avoid
    // enlarge buffer frequently
    CPStringBuilder strbuf = new CPStringBuilder (buf.length / 2 + 2);

    for (int i = 0; i < buf.length; )
      {
  if ((buf [i] & 0x80) == 0)    // bit pattern 0xxxxxxx
    strbuf.append ((char) (buf [i++] & 0xFF));
  else if ((buf [i] & 0xE0) == 0xC0// bit pattern 110xxxxx
    {
      if (i + 1 >= buf.length
    || (buf [i + 1] & 0xC0) != 0x80)
        throw new UTFDataFormatException ();

      strbuf.append((char) (((buf [i++] & 0x1F) << 6)
          | (buf [i++] & 0x3F)));
    }
  else if ((buf [i] & 0xF0) == 0xE0// bit pattern 1110xxxx
    {
      if (i + 2 >= buf.length
    || (buf [i + 1] & 0xC0) != 0x80
    || (buf [i + 2] & 0xC0) != 0x80)
        throw new UTFDataFormatException ();

      strbuf.append ((char) (((buf [i++] & 0x0F) << 12)
           | ((buf [i++] & 0x3F) << 6)
           | (buf [i++] & 0x3F)));
    }
  else // must be ((buf [i] & 0xF0) == 0xF0 || (buf [i] & 0xC0) == 0x80)
    throw new UTFDataFormatException ()// bit patterns 1111xxxx or
            //     10xxxxxx
      }

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

    else
      {
        // Look for the terminating quote.  However, if we
        // see a '', that represents a literal quote and
        // we must iterate.
        CPStringBuilder buf = new CPStringBuilder();
        int oldPos = i + 1;
        do
          {
      if (pos == -1)
        throw new IllegalArgumentException("Quotes starting at character "
                   + i +
                   " not closed.");
      buf.append(pattern.substring(oldPos, pos));
      if (pos + 1 >= pattern.length()
          || pattern.charAt(pos + 1) != '\'')
        break;
      buf.append('\'');
      oldPos = pos + 2;
      pos = pattern.indexOf('\'', pos + 2);
          }
        while (true);
        tokens.add(buf.toString());
      }
    i = pos;
        }
      else
        {
View Full Code Here

   * @return a string representation of the <code>SimpleDateFormat</code>
   *         instance.
   */
  public String toString()
  {
    CPStringBuilder output = new CPStringBuilder(getClass().getName());
    output.append("[tokens=");
    output.append(tokens);
    output.append(", formatData=");
    output.append(formatData);
    output.append(", defaultCenturyStart=");
    output.append(defaultCenturyStart);
    output.append(", defaultCentury=");
    output.append(defaultCentury);
    output.append(", pattern=");
    output.append(pattern);
    output.append(", serialVersionOnStream=");
    output.append(serialVersionOnStream);
    output.append(", standardChars=");
    output.append(standardChars);
    output.append("]");
    return output.toString();
  }
View Full Code Here

   *
   * @return the quoted string.
   */
  private static String quote(String str, String legalCharacters)
  {
    CPStringBuilder sb = new CPStringBuilder(str.length());
    for (int i = 0; i < str.length(); i++)
      {
  char c = str.charAt(i);
  if ((legalCharacters.indexOf(c) == -1)
      && (c <= 127))
    {
      sb.append('%');
      sb.append(HEX.charAt(c / 16));
      sb.append(HEX.charAt(c % 16));
    }
        else
    sb.append(c);
      }
    return sb.toString();
  }
View Full Code Here

   */
  private String translateLocalizedPattern(String pattern,
             String oldChars, String newChars)
  {
    int len = pattern.length();
    CPStringBuilder buf = new CPStringBuilder(len);
    boolean quoted = false;
    for (int i = 0;  i < len;  i++)
      {
  char ch = pattern.charAt(i);
  if (ch == '\'')
    quoted = ! quoted;
  if (! quoted)
    {
      int j = oldChars.indexOf(ch);
      if (j >= 0)
        ch = newChars.charAt(j);
    }
  buf.append(ch);
      }
    return buf.toString();
  }
View Full Code Here

TOP

Related Classes of gnu.java.lang.CPStringBuilder

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.