Example #1
0
        /*
         * Returns a string containing a concise, human-readable description of this
         * {@code PermissionCollection}.
         *
         * @return a printable representation for this {@code PermissionCollection}.
         */
        public override String ToString()
        {
            java.util.ArrayList <String>       elist  = new java.util.ArrayList <String>(100);
            java.util.Enumeration <Permission> elenum = elements();
            String superStr    = base.ToString();
            int    totalLength = superStr.length() + 5;

            if (elenum != null)
            {
                while (elenum.hasMoreElements())
                {
                    String el = elenum.nextElement().toString();
                    totalLength += el.length();
                    elist.add(el);
                }
            }
            int esize = elist.size();

            totalLength += esize * 4;
            java.lang.StringBuilder result = new java.lang.StringBuilder(totalLength).append(superStr)
                                             .append(" ("); //$NON-NLS-1$
            for (int i = 0; i < esize; i++)
            {
                result.append("\n ").append(elist.get(i).toString()); //$NON-NLS-1$
            }
            return(result.append("\n)\n").toString());                //$NON-NLS-1$
        }
Example #2
0
        /**
         * Returns the clear text representation of a given URL using HTTP format.
         *
         * @param url
         *            the URL object to be converted.
         * @return the clear text representation of the specified URL.
         * @see #parseURL
         * @see URL#toExternalForm()
         */
        protected internal String toExternalForm(URL url)
        {
            java.lang.StringBuilder answer = new java.lang.StringBuilder();
            answer.append(url.getProtocol());
            answer.append(':');
            String authority = url.getAuthority();

            if (authority != null && authority.length() > 0)
            {
                answer.append("//"); //$NON-NLS-1$
                answer.append(url.getAuthority());
            }

            String file = url.getFile();
            String refJ = url.getRef();

            if (file != null)
            {
                answer.append(file);
            }
            if (refJ != null)
            {
                answer.append('#');
                answer.append(refJ);
            }
            return(answer.toString());
        }
Example #3
0
 /**
  * Converts a {@link LogRecord} object into a human readable string
  * representation.
  *
  * @param r
  *            the log record to be formatted into a string.
  * @return the formatted string.
  */
 public override String format(LogRecord r)
 {
     java.lang.StringBuilder sb = new java.lang.StringBuilder();
     sb.append(java.text.MessageFormat.format("{0, date} {0, time} ", //$NON-NLS-1$
         new Object[] { new java.util.Date(r.getMillis()) }));
     sb.append(r.getSourceClassName()).append(" "); //$NON-NLS-1$
     sb.append(r.getSourceMethodName()).append(java.lang.SystemJ.getProperty("line.separator"));
     sb.append(r.getLevel().getName()).append(": "); //$NON-NLS-1$
     sb.append(formatMessage(r)).append(java.lang.SystemJ.getProperty("line.separator"));
     if (null != r.getThrown()) {
     sb.append("Throwable occurred: "); //$NON-NLS-1$
     java.lang.Throwable t = r.getThrown();
     java.io.PrintWriter pw = null;
     try {
         java.io.StringWriter sw = new java.io.StringWriter();
         pw = new java.io.PrintWriter(sw);
         t.printStackTrace(pw);
         sb.append(sw.toString());
     } finally {
         if (pw != null) {
             try {
                 pw.close();
             } catch (Exception e) {
                 // ignore
             }
         }
     }
     }
     return sb.toString();
 }
Example #4
0
        /*
         * Converts a {@link LogRecord} object into a human readable string
         * representation.
         *
         * @param r
         *            the log record to be formatted into a string.
         * @return the formatted string.
         */

        public override String format(LogRecord r)
        {
            java.lang.StringBuilder sb = new java.lang.StringBuilder();
            sb.append(java.text.MessageFormat.format("{0, date} {0, time} ", //$NON-NLS-1$
                                                     new Object[] { new java.util.Date(r.getMillis()) }));
            sb.append(r.getSourceClassName()).append(" ");                   //$NON-NLS-1$
            sb.append(r.getSourceMethodName()).append(java.lang.SystemJ.getProperty("line.separator"));
            sb.append(r.getLevel().getName()).append(": ");                  //$NON-NLS-1$
            sb.append(formatMessage(r)).append(java.lang.SystemJ.getProperty("line.separator"));
            if (null != r.getThrown())
            {
                sb.append("Throwable occurred: "); //$NON-NLS-1$
                java.lang.Throwable t  = r.getThrown();
                java.io.PrintWriter pw = null;
                try {
                    java.io.StringWriter sw = new java.io.StringWriter();
                    pw = new java.io.PrintWriter(sw);
                    t.printStackTrace(pw);
                    sb.append(sw.toString());
                } finally {
                    if (pw != null)
                    {
                        try {
                            pw.close();
                        } catch (Exception e) {
                            // ignore
                        }
                    }
                }
            }
            return(sb.toString());
        }
Example #5
0
        /**
         * Returns the string representing this permission's actions. It must be of
         * the form "read,write,execute,delete", all lower case and in the correct
         * order if there is more than one action.
         *
         * @param action
         *            the action name
         * @return the string representing this permission's actions
         */
        private String toCanonicalActionString(String action)
        {
            actions = action.trim().toLowerCase();

            // get the numerical representation of the action list
            mask = getMask(actions);

            // convert the mask to a canonical action list.
            int len = actionList.Length;
            // the test mask - shift the 1 to the leftmost position of the
            // actionList
            int highestBitMask = 1 << (len - 1);

            // if a bit of mask is set, append the corresponding action to result
            java.lang.StringBuilder result = new java.lang.StringBuilder();
            bool addedItem = false;

            for (int i = 0; i < len; i++)
            {
                if ((highestBitMask & mask) != 0)
                {
                    if (addedItem)
                    {
                        result.append(","); //$NON-NLS-1$
                    }
                    result.append(actionList[i]);
                    addedItem = true;
                }
                highestBitMask = highestBitMask >> 1;
            }
            return(result.toString());
        }
Example #6
0
        /*
         *
         * Adds information about provider services into HashMap.
         *
         * @param p
         */
        public static void initServiceInfo(java.security.Provider p)
        {
            java.security.Provider.Service serv;
            String key;
            String type;
            String alias;

            java.lang.StringBuilder sb = new java.lang.StringBuilder(128);

            for (java.util.Iterator <java.security.Provider.Service> it1 = p.getServices().iterator(); it1.hasNext();)
            {
                serv = it1.next();
                type = serv.getType();
                sb.delete(0, sb.length());
                key = sb.append(type).append(".").append( //$NON-NLS-1$
                    Util.toUpperCase(serv.getAlgorithm())).toString();
                if (!services.containsKey(key))
                {
                    services.put(key, serv);
                }
                for (java.util.Iterator <String> it2 = Engine.door.getAliases(serv); it2.hasNext();)
                {
                    alias = it2.next();
                    sb.delete(0, sb.length());
                    key = sb.append(type).append(".").append(Util.toUpperCase(alias)) //$NON-NLS-1$
                          .toString();
                    if (!services.containsKey(key))
                    {
                        services.put(key, serv);
                    }
                }
            }
        }
Example #7
0
        /*
         * Substitutes all entries like ${some.key}, found in specified string,
         * for specified values.
         * If some key is unknown, throws ExpansionFailedException.
         * @param str the string to be expanded
         * @param properties available key-value mappings
         * @return expanded string
         * @throws ExpansionFailedException
         */
        public static String expand(String str, java.util.Properties properties)
        {//throws ExpansionFailedException {
            java.lang.StringBuilder result = new java.lang.StringBuilder(str);
            int start = result.indexOf(START_MARK);

            while (start >= 0)
            {
                int end = result.indexOf(END_MARK, start);
                if (end >= 0)
                {
                    String key   = result.substring(start + START_OFFSET, end);
                    String value = properties.getProperty(key);
                    if (value != null)
                    {
                        result.replace(start, end + END_OFFSET, value);
                        start += value.length();
                    }
                    else
                    {
                        throw new ExpansionFailedException("Unknown key: " + key); //$NON-NLS-1$
                    }
                }
                start = result.indexOf(START_MARK, start);
            }
            return(result.toString());
        }
Example #8
0
        /**
         * Returns the timestamp formatted as a String in the JDBC Timestamp Escape
         * format, which is {@code "yyyy-mm-dd hh:mm:ss.nnnnnnnnn"}.
         *
         * @return A string representing the instant defined by the {@code
         *         Timestamp}, in JDBC Timestamp escape format.
         */
        public override String ToString()
        {
            java.lang.StringBuilder sb = new java.lang.StringBuilder(29);

            format((getYear() + 1900), 4, sb);
            sb.append('-');
            format((getMonth() + 1), 2, sb);
            sb.append('-');
            format(getDate(), 2, sb);
            sb.append(' ');
            format(getHours(), 2, sb);
            sb.append(':');
            format(getMinutes(), 2, sb);
            sb.append(':');
            format(getSeconds(), 2, sb);
            sb.append('.');
            if (nanos == 0)
            {
                sb.append('0');
            }
            else
            {
                format(nanos, 9, sb);
                while (sb.charAt(sb.length() - 1) == '0')
                {
                    sb.setLength(sb.length() - 1);
                }
            }

            return(sb.toString());
        }
 /**
  * Returns the message string of the IllegalFormatFlagsException.
  *
  * @return the message string of the IllegalFormatFlagsException.
  */
 public override String getMessage()
 {
     java.lang.StringBuilder buffer = new java.lang.StringBuilder();
     buffer.append("Flags = '");
     buffer.append(flags);
     buffer.append("'");
     return buffer.toString();
 }
Example #10
0
        /*
         * Returns the message string of the IllegalFormatFlagsException.
         *
         * @return the message string of the IllegalFormatFlagsException.
         */

        public override String getMessage()
        {
            java.lang.StringBuilder buffer = new java.lang.StringBuilder();
            buffer.append("Flags = '");
            buffer.append(flags);
            buffer.append("'");
            return(buffer.toString());
        }
        /*
         * Returns the message string of the IllegalFormatConversionException.
         *
         * @return the message string of the IllegalFormatConversionException.
         */

        public override String getMessage()
        {
            java.lang.StringBuilder buffer = new java.lang.StringBuilder();
            buffer.append(c);
            buffer.append(" is incompatible with ");
            buffer.append(arg.getName());
            return(buffer.toString());
        }
Example #12
0
 public override String ToString()
 {
     java.lang.StringBuilder sb = new java.lang.StringBuilder();
     sb.append(isUserNode() ? "User" : "System"); //$NON-NLS-1$ //$NON-NLS-2$
     sb.append(" Preference Node: ");             //$NON-NLS-1$
     sb.append(absolutePath());
     return(sb.toString());
 }
Example #13
0
        /**
         * Canonicalize paths: escape characters outside of US-ASCII charset (e.g. /SanJoséSellers ==>
         * /Sanjos%C3%A9Sellers) and normalize escape-characters (e.g. %aa ==> %AA)
         *
         * @param path Path to canonicalize.
         * @return escaped and normalized path
         */
        private static String maybeEscapePattern(String path)
        {
            byte[] bytes = System.Text.Encoding.UTF8.GetBytes(path);// path.getBytes(java.nio.charset.StandardCharsets.UTF_8);

            int  unescapedCount = 0;
            bool notCapitalized = false;

            // Check if any changes required
            for (int i = 0; i < bytes.Length; i++)
            {
                if (i < bytes.Length - 2 &&
                    bytes[i] == '%' &&
                    isHexChar(bytes[i + 1]) &&
                    isHexChar(bytes[i + 2]))
                {
                    if (java.lang.Character.isLowerCase((char)bytes[i + 1]) || java.lang.Character.isLowerCase((char)bytes[i + 2]))
                    {
                        notCapitalized = true;
                    }
                    i += 2;
                }
                else if ((bytes[i] & 0x80) != 0)
                {
                    unescapedCount++;
                }
            }

            // Return if no changes needed
            if (unescapedCount == 0 && !notCapitalized)
            {
                return(path);
            }

            java.lang.StringBuilder stringBuilder = new java.lang.StringBuilder();
            for (int i = 0; i < bytes.Length; i++)
            {
                if (i < bytes.Length - 2 &&
                    bytes[i] == '%' &&
                    isHexChar(bytes[i + 1]) &&
                    isHexChar(bytes[i + 2]))
                {
                    stringBuilder.append((char)bytes[i++]);
                    stringBuilder.append((char)java.lang.Character.toUpperCase((char)bytes[i++]));
                    stringBuilder.append((char)java.lang.Character.toUpperCase((char)bytes[i]));
                }
                else if ((bytes[i] & 0x80) != 0)
                {
                    stringBuilder.append('%');
                    stringBuilder.append(java.lang.Integer.toHexString((bytes[i] >> 4) & 0xf).toUpperCase());
                    stringBuilder.append(java.lang.Integer.toHexString(bytes[i] & 0xf).toUpperCase());
                }
                else
                {
                    stringBuilder.append((char)bytes[i]);
                }
            }
            return(stringBuilder.toString());
        }
        /**
         * Returns the message string of the {@code FormatFlagsConversionMismatchException}.
         *
         * @return the message string of the {@code FormatFlagsConversionMismatchException}.
         */

        public override String getMessage()
        {
            java.lang.StringBuilder buffer = new java.lang.StringBuilder();
            buffer.append("Mismatched Convertor =");
            buffer.append(c);
            buffer.append(", Flags= ");
            buffer.append(f);
            return(buffer.toString());
        }
Example #15
0
        private const String PADDING = "0000";  //$NON-NLS-1$

        /*
         * Private method to format the time
         */
        private void format(int date, int digits, java.lang.StringBuilder sb)
        {
            String str = java.lang.StringJ.valueOf(date);

            if (digits - str.length() > 0)
            {
                sb.append(PADDING.substring(0, digits - str.length()));
            }
            sb.append(str);
        }
Example #16
0
        // print error message in some format
        protected void printInvalidPropMessage(String key, String value, java.lang.Exception e)
        {
            // logging.12=Invalid property value for
            String msg = new java.lang.StringBuilder().append(
                "Invalid property value for ")                                       //$NON-NLS-1$
                         .append(prefix).append(":").append(key).append("/").append( //$NON-NLS-1$//$NON-NLS-2$
                value).toString();

            errorMan.error(msg, e, ErrorManager.GENERIC_FAILURE);
        }
 /**
  * Returns the message string of the IllegalFormatCodePointException.
  *
  * @return the message string of the IllegalFormatCodePointException.
  */
 public override String getMessage()
 {
     java.lang.StringBuilder buffer = new java.lang.StringBuilder();
     buffer.append("Code point is ");
     char[] chars = java.lang.Character.toChars(c);
     for (int i = 0; i < chars.Length; i++)
     {
         buffer.append(chars[i]);
     }
     return buffer.toString();
 }
        /*
         * Returns the message string of the IllegalFormatCodePointException.
         *
         * @return the message string of the IllegalFormatCodePointException.
         */

        public override String getMessage()
        {
            java.lang.StringBuilder buffer = new java.lang.StringBuilder();
            buffer.append("Code point is ");
            char[] chars = java.lang.Character.toChars(c);
            for (int i = 0; i < chars.Length; i++)
            {
                buffer.append(chars[i]);
            }
            return(buffer.toString());
        }
Example #19
0
        /*
         * Formats the {@code Time} as a String in JDBC escape format: {@code
         * hh:mm:ss}.
         *
         * @return A String representing the {@code Time} value in JDBC escape
         *         format: {@code HH:mm:ss}
         */
        public override String ToString()
        {
            java.lang.StringBuilder sb = new java.lang.StringBuilder(8);

            format(getHours(), 2, sb);
            sb.append(':');
            format(getMinutes(), 2, sb);
            sb.append(':');
            format(getSeconds(), 2, sb);

            return(sb.toString());
        }
Example #20
0
        /*
         * Produces a string representation of the date in SQL format
         *
         * @return a string representation of the date in SQL format - {@code
         *         "yyyy-mm-dd"}.
         */
        public override String ToString()
        {
            java.util.Calendar c = new java.util.GregorianCalendar();
            c.setTimeInMillis(this.milliseconds);
            java.lang.StringBuilder sb = new java.lang.StringBuilder(10);

            format(c.get(java.util.Calendar.YEAR), 4, sb);
            sb.append('-');
            format(c.get(java.util.Calendar.MONTH + 1), 2, sb);
            sb.append('-');
            format(c.get(java.util.Calendar.DAY_OF_MONTH), 2, sb);

            return(sb.toString());
        }
Example #21
0
        /**
         * Returns MultiRectArea object converted to string
         */

        public override String ToString()
        {
            int cnt = getRectCount();

            java.lang.StringBuilder sb = new java.lang.StringBuilder((cnt << 5) + 128);
            sb.append(this.getClass().getName()).append(" ["); //$NON-NLS-1$
            for (int i = 1; i < rect[0]; i += 4)
            {
                sb.append(i > 1 ? ", [" : "[").append(rect[i]).append(", ").append(rect[i + 1]). //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                append(", ").append(rect[i + 2] - rect[i] + 1).append(", ").                     //$NON-NLS-1$ //$NON-NLS-2$
                append(rect[i + 3] - rect[i + 1] + 1).append("]");                               //$NON-NLS-1$
            }
            return(sb.append("]").toString());                                                   //$NON-NLS-1$
        }
Example #22
0
        private String getAbsoluteName()
        {
            File   f    = getAbsoluteFile();
            String name = f.getPath();

            if (f.isDirectory() && name.charAt(name.length() - 1) != separatorChar)
            {
                // Directories must end with a slash
                name = new java.lang.StringBuilder(name.length() + 1).append(name)
                       .append('/').toString();
            }
            if (separatorChar != '/')   // Must convert slashes.
            {
                name = name.replace(separatorChar, '/');
            }
            return(name);
        }
Example #23
0
        /*
         * Re-initialize the properties and configuration. The initialization
         * process is same as the {@code LogManager} instantiation.
         * <p>
         * Notice : No {@code PropertyChangeEvent} are fired.
         * </p>
         *
         * @throws IOException
         *             if any IO related problems happened.
         * @throws SecurityException
         *             if security manager exists and it determines that caller does
         *             not have the required permissions to perform this action.
         */
        public void readConfiguration()
        {                                                                                             //throws IOException {
            // check config class
            String configClassName = java.lang.SystemJ.getProperty("java.util.logging.config.class"); //$NON-NLS-1$

            if (null == configClassName || null == getInstanceByClass(configClassName))
            {
                // if config class failed, check config file
                String configFile = java.lang.SystemJ.getProperty("java.util.logging.config.file"); //$NON-NLS-1$

                if (null == configFile)
                {
                    // if cannot find configFile, use default logging.properties
                    configFile = new java.lang.StringBuilder().append(
                        java.lang.SystemJ.getProperty("java.home")).append(java.io.File.separator) //$NON-NLS-1$
                                 .append("lib").append(java.io.File.separator).append(             //$NON-NLS-1$
                        "logging.properties").toString();                                          //$NON-NLS-1$
                }

                java.io.InputStream input = null;
                try
                {
                    input = new java.io.BufferedInputStream(new java.io.FileInputStream(configFile));
                    readConfiguration(input);
                }
                finally
                {
                    if (input != null)
                    {
                        try
                        {
                            input.close();
                        }
                        catch (Exception e)
                        {// ignore
                        }
                    }
                }
            }
        }
Example #24
0
        /**
         * Reads a line of text form the current position in this file. A line is
         * represented by zero or more characters followed by {@code '\n'}, {@code
         * '\r'}, {@code "\r\n"} or the end of file marker. The string does not
         * include the line terminating sequence.
         * <p>
         * Blocks until a line terminating sequence has been read, the end of the
         * file is reached or an exception is thrown.
         *
         * @return the contents of the line or {@code null} if no characters have
         *         been read before the end of the file has been reached.
         * @throws IOException
         *             if this file is closed or another I/O error occurs.
         */
        public String readLine()                                            //throws IOException {
        {
            java.lang.StringBuilder line = new java.lang.StringBuilder(80); // Typical line length
            bool foundTerminator         = false;
            long unreadPosition          = 0;

            while (true)
            {
                int nextByte = read();
                switch (nextByte)
                {
                case -1:
                    return(line.length() != 0 ? line.toString() : null);

                case (byte)'\r':
                    if (foundTerminator)
                    {
                        seek(unreadPosition);
                        return(line.toString());
                    }
                    foundTerminator = true;
                    /* Have to be able to peek ahead one byte */
                    unreadPosition = getFilePointer();
                    break;

                case (byte)'\n':
                    return(line.toString());

                default:
                    if (foundTerminator)
                    {
                        seek(unreadPosition);
                        return(line.toString());
                    }
                    line.append((char)nextByte);
                    break;
                }
            }
        }
Example #25
0
        private static String formatTimeZoneName(String name, int offset)
        {
            java.lang.StringBuilder buf = new java.lang.StringBuilder();
            int index = offset, length = name.length();

            buf.append(name.substring(0, offset));

            while (index < length)
            {
                if (java.lang.Character.digit(name.charAt(index), 10) != -1)
                {
                    buf.append(name.charAt(index));
                    if ((length - (index + 1)) == 2)
                    {
                        buf.append(':');
                    }
                }
                else if (name.charAt(index) == ':')
                {
                    buf.append(':');
                }
                index++;
            }

            if (buf.toString().indexOf(":") == -1)
            {
                buf.append(':');
                buf.append("00");
            }

            if (buf.toString().indexOf(":") == 5)
            {
                buf.insert(4, '0');
            }

            return(buf.toString());
        }
Example #26
0
        private static String htmlEncode(String s)
        {
            java.lang.StringBuilder sb = new java.lang.StringBuilder();
            char c;

            for (int i = 0; i < s.length(); i++)
            {
                c = s.charAt(i);
                switch (c)
                {
                case '<':
                    sb.append("&lt;");                      //$NON-NLS-1$
                    break;

                case '>':
                    sb.append("&gt;");                      //$NON-NLS-1$
                    break;

                case '&':
                    sb.append("&amp;");                      //$NON-NLS-1$
                    break;

                case '\\':
                    sb.append("&apos;");                      //$NON-NLS-1$
                    break;

                case '"':
                    sb.append("&quot;");                      //$NON-NLS-1$
                    break;

                default:
                    sb.append(c);
                    break;
                }
            }
            return(sb.toString());
        }
Example #27
0
        /// <summary>
        /// Convert formatted Java Message to formatted C# Message
        /// </summary>
        /// <para>
        /// <strong>Java:</strong> <code>%[argument_index$][flags][width][.precision]conversion</code><br />
        /// <strong>C#:</strong> <code>{index[,alignment][:formatString]}</code>
        /// </para>
        /// <para>
        /// <strong>Java:</strong> <code>"The %s costs $%.2f for %d months.%n", "studio", 499.0, 3</code><br />
        /// <strong>C#:</strong> <code>"The {0} costs {1:C} for {2} months.\n", "studio", 499.0, 3</code>
        /// </para>
        /// <para>
        /// <strong>Java:</strong> <code>"Today is %tD%n", new java.util.Date()</code><br />
        /// <strong>C#:</strong> <code>"Today is " + DateTime.Now.ToShortDateString()</code>
        /// </para>
        /// <param name="msg">Message.</param>
        public static String convert(String msg)
        {
            // read chars. if %, read next charand convert to  C#
            char[] chars = msg.ToCharArray();
            java.lang.StringBuilder result = new java.lang.StringBuilder();
            int number = 0;

            for (int i = 0; i < chars.Length; i++)
            {
                switch (chars[i])
                {
                case '%':
                    i++;
                    switch (chars[i])
                    {
                    case '%':
                        result.append('%');
                        break;

                    case 'n':
                        result.append('\n');
                        break;

                    case '{':
                        result.append("{{");
                        break;

                    case '}':
                        result.append("}}");
                        break;

                    default:
                        // gültige Zeichen: -0123456789bBhHsScCdoxXeEfgGaAtT
                        // berücksichtigt:  -0123456789    s     xX
                        result.append('{');         // Beginn format
                        result.append(number);      // index of format parameter

                        bool formattedPart   = true;
                        bool beginnAlignment = true;
                        while (formattedPart)
                        {
                            switch (chars[i])
                            {
                            case '-':
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                                if (beginnAlignment)
                                {
                                    result.append(',');
                                    beginnAlignment = false;
                                }
                                result.append(chars[i]);
                                break;

                            case 'x':
                            case 'X':
                                result.append(':');
                                result.append(chars[i]);
                                formattedPart = false;
                                break;

                            case 's':
                                formattedPart = false;
                                break;

                            //case 'S': see http://stackoverflow.com/questions/1839649/c-sharp-string-format-flag-or-modifier-to-lowercase-param
                            default:
                                formattedPart = false;
                                i--;
                                break;
                            }
                            i++;
                        }
                        result.append('}');
                        number++;
                        break;
                    }
                    break;

                default:
                    result.append(chars[i]);
                    break;
                }
            }
            return(result.toString());;
        }
 /**
  * Returns the message string of the {@code FormatFlagsConversionMismatchException}.
  *
  * @return the message string of the {@code FormatFlagsConversionMismatchException}.
  */
 public override String getMessage()
 {
     java.lang.StringBuilder buffer = new java.lang.StringBuilder();
     buffer.append("Mismatched Convertor =");
     buffer.append(c);
     buffer.append(", Flags= ");
     buffer.append(f);
     return buffer.toString();
 }
Example #29
0
        /**
         * Formats the {@code Time} as a String in JDBC escape format: {@code
         * hh:mm:ss}.
         *
         * @return A String representing the {@code Time} value in JDBC escape
         *         format: {@code HH:mm:ss}
         */
        public override String ToString()
        {
            java.lang.StringBuilder sb = new java.lang.StringBuilder(8);

            format(getHours(), 2, sb);
            sb.append(':');
            format(getMinutes(), 2, sb);
            sb.append(':');
            format(getSeconds(), 2, sb);

            return sb.toString();
        }
Example #30
0
        /**
         * Transform the pattern to the valid file name, replacing any patterns, and
         * applying generation and uniqueID if present
         *
         * @param gen
         *            generation of this file
         * @return transformed filename ready for use
         */
        private String parseFileName(int gen)
        {
            int cur = 0;
            int next = 0;
            bool hasUniqueID = false;
            bool hasGeneration = false;

            // TODO privilege code?
            String homePath = java.lang.SystemJ.getProperty("user.home"); //$NON-NLS-1$
            if (homePath == null) {
            throw new java.lang.NullPointerException();
            }
            bool homePathHasSepEnd = homePath.endsWith(java.io.File.separator);

            String tempPath = java.lang.SystemJ.getProperty("java.io.tmpdir"); //$NON-NLS-1$
            tempPath = tempPath == null ? homePath : tempPath;
            bool tempPathHasSepEnd = tempPath.endsWith(java.io.File.separator);

            java.lang.StringBuilder sb = new java.lang.StringBuilder();
            pattern = pattern.replace('/', java.io.File.separatorChar);

            char[] value = pattern.toCharArray();
            while ((next = pattern.indexOf('%', cur)) >= 0) {
            if (++next < pattern.length()) {
                switch (value[next]) {
                    case 'g':
                        sb.append(value, cur, next - cur - 1).append(gen);
                        hasGeneration = true;
                        break;
                    case 'u':
                        sb.append(value, cur, next - cur - 1).append(uniqueID);
                        hasUniqueID = true;
                        break;
                    case 't':
                        /*
                         * we should probably try to do something cute here like
                         * lookahead for adjacent '/'
                         */
                        sb.append(value, cur, next - cur - 1).append(tempPath);
                        if (!tempPathHasSepEnd) {
                            sb.append(java.io.File.separator);
                        }
                        break;
                    case 'h':
                        sb.append(value, cur, next - cur - 1).append(homePath);
                        if (!homePathHasSepEnd) {
                            sb.append(java.io.File.separator);
                        }
                        break;
                    case '%':
                        sb.append(value, cur, next - cur - 1).append('%');
                        break;
                    default:
                        sb.append(value, cur, next - cur);
                        break;
                }
                cur = ++next;
            } else {
                // fail silently
            }
            }

            sb.append(value, cur, value.Length - cur);

            if (!hasGeneration && count > 1) {
            sb.append(".").append(gen); //$NON-NLS-1$
            }

            if (!hasUniqueID && uniqueID > 0) {
            sb.append(".").append(uniqueID); //$NON-NLS-1$
            }

            return sb.toString();
        }
Example #31
0
        private static String formatTimeZoneName(String name, int offset)
        {
            java.lang.StringBuilder buf = new java.lang.StringBuilder();
            int index = offset, length = name.length();
            buf.append(name.substring(0, offset));

            while (index < length)
            {
                if (java.lang.Character.digit(name.charAt(index), 10) != -1)
                {
                    buf.append(name.charAt(index));
                    if ((length - (index + 1)) == 2)
                    {
                        buf.append(':');
                    }
                }
                else if (name.charAt(index) == ':')
                {
                    buf.append(':');
                }
                index++;
            }

            if (buf.toString().indexOf(":") == -1)
            {
                buf.append(':');
                buf.append("00");
            }

            if (buf.toString().indexOf(":") == 5)
            {
                buf.insert(4, '0');
            }

            return buf.toString();
        }
Example #32
0
 /**
  * Reads a line of text form the current position in this file. A line is
  * represented by zero or more characters followed by {@code '\n'}, {@code
  * '\r'}, {@code "\r\n"} or the end of file marker. The string does not
  * include the line terminating sequence.
  * <p/>
  * Blocks until a line terminating sequence has been read, the end of the
  * file is reached or an exception is thrown.
  *
  * @return the contents of the line or {@code null} if no characters have
  *         been read before the end of the file has been reached.
  * @throws IOException
  *             if this file is closed or another I/O error occurs.
  */
 public String readLine()
 {
     //throws IOException {
     java.lang.StringBuilder line = new java.lang.StringBuilder(80); // Typical line length
     bool foundTerminator = false;
     long unreadPosition = 0;
     while (true) {
     int nextByte = read();
     switch (nextByte) {
         case -1:
             return line.length() != 0 ? line.toString() : null;
         case (byte) '\r':
             if (foundTerminator) {
                 seek(unreadPosition);
                 return line.toString();
             }
             foundTerminator = true;
             /* Have to be able to peek ahead one byte */
             unreadPosition = getFilePointer();
             break;
         case (byte) '\n':
             return line.toString();
         default:
             if (foundTerminator) {
                 seek(unreadPosition);
                 return line.toString();
             }
             line.append((char) nextByte);
             break;
     }
     }
 }
Example #33
0
        /**
         * Returns the timestamp formatted as a String in the JDBC Timestamp Escape
         * format, which is {@code "yyyy-mm-dd hh:mm:ss.nnnnnnnnn"}.
         *
         * @return A string representing the instant defined by the {@code
         *         Timestamp}, in JDBC Timestamp escape format.
         */
        public override String ToString()
        {
            java.lang.StringBuilder sb = new java.lang.StringBuilder(29);

            format((getYear() + 1900), 4, sb);
            sb.append('-');
            format((getMonth() + 1), 2, sb);
            sb.append('-');
            format(getDate(), 2, sb);
            sb.append(' ');
            format(getHours(), 2, sb);
            sb.append(':');
            format(getMinutes(), 2, sb);
            sb.append(':');
            format(getSeconds(), 2, sb);
            sb.append('.');
            if (nanos == 0)
            {
                sb.append('0');
            }
            else
            {
                format(nanos, 9, sb);
                while (sb.charAt(sb.length() - 1) == '0')
                {
                    sb.setLength(sb.length() - 1);
                }
            }

            return sb.toString();
        }
Example #34
0
        /**
         *
         * Adds information about provider services into HashMap.
         *
         * @param p
         */
        public static void initServiceInfo(java.security.Provider p)
        {
            java.security.Provider.Service serv;
            String key;
            String type;
            String alias;
            java.lang.StringBuilder sb = new java.lang.StringBuilder(128);

            for (java.util.Iterator<java.security.Provider.Service> it1 = p.getServices().iterator(); it1.hasNext(); )
            {
                serv = it1.next();
                type = serv.getType();
                sb.delete(0, sb.length());
                key = sb.append(type).append(".").append( //$NON-NLS-1$
                        Util.toUpperCase(serv.getAlgorithm())).toString();
                if (!services.containsKey(key))
                {
                    services.put(key, serv);
                }
                for (java.util.Iterator<String> it2 = Engine.door.getAliases(serv); it2.hasNext(); )
                {
                    alias = it2.next();
                    sb.delete(0, sb.length());
                    key = sb.append(type).append(".").append(Util.toUpperCase(alias)) //$NON-NLS-1$
                            .toString();
                    if (!services.containsKey(key))
                    {
                        services.put(key, serv);
                    }
                }
            }
        }
Example #35
0
        /**
         * Returns the string representing this permission's actions. It must be of
         * the form "read,write,execute,delete", all lower case and in the correct
         * order if there is more than one action.
         *
         * @param action
         *            the action name
         * @return the string representing this permission's actions
         */
        private String toCanonicalActionString(String action)
        {
            actions = action.trim().toLowerCase();

            // get the numerical representation of the action list
            mask = getMask(actions);

            // convert the mask to a canonical action list.
            int len = actionList.Length;
            // the test mask - shift the 1 to the leftmost position of the
            // actionList
            int highestBitMask = 1 << (len - 1);

            // if a bit of mask is set, append the corresponding action to result
            java.lang.StringBuilder result = new java.lang.StringBuilder();
            bool addedItem = false;
            for (int i = 0; i < len; i++) {
            if ((highestBitMask & mask) != 0) {
                if (addedItem) {
                    result.append(","); //$NON-NLS-1$
                }
                result.append(actionList[i]);
                addedItem = true;
            }
            highestBitMask = highestBitMask >> 1;
            }
            return result.toString();
        }
Example #36
0
 private static String htmlEncode(String s)
 {
     java.lang.StringBuilder sb = new java.lang.StringBuilder ();
     char c;
     for (int i = 0; i < s.length(); i++) {
         c = s.charAt (i);
         switch (c) {
         case '<':
             sb.append ("&lt;"); //$NON-NLS-1$
             break;
         case '>':
             sb.append ("&gt;"); //$NON-NLS-1$
             break;
         case '&':
             sb.append ("&amp;"); //$NON-NLS-1$
             break;
         case '\\':
             sb.append ("&apos;"); //$NON-NLS-1$
             break;
         case '"':
             sb.append ("&quot;"); //$NON-NLS-1$
             break;
         default:
             sb.append (c);
             break;
         }
     }
     return sb.toString ();
 }
Example #37
0
 /**
  * Returns MultiRectArea object converted to string
  */
 public override String ToString()
 {
     int cnt = getRectCount();
     java.lang.StringBuilder sb = new java.lang.StringBuilder((cnt << 5) + 128);
     sb.append(this.getClass().getName()).append(" ["); //$NON-NLS-1$
     for (int i = 1; i < rect[0]; i += 4)
     {
         sb.append(i > 1 ? ", [" : "[").append(rect[i]).append(", ").append(rect[i + 1]). //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
         append(", ").append(rect[i + 2] - rect[i] + 1).append(", "). //$NON-NLS-1$ //$NON-NLS-2$
         append(rect[i + 3] - rect[i + 1] + 1).append("]"); //$NON-NLS-1$
     }
     return sb.append("]").toString(); //$NON-NLS-1$
 }
        /// <summary>
        /// Convert formatted Java Message to formatted C# Message
        /// </summary>
        /// <para>
        /// <strong>Java:</strong> <code>%[argument_index$][flags][width][.precision]conversion</code><br />
        /// <strong>C#:</strong> <code>{index[,alignment][:formatString]}</code>
        /// </para>
        /// <para>
        /// <strong>Java:</strong> <code>"The %s costs $%.2f for %d months.%n", "studio", 499.0, 3</code><br />
        /// <strong>C#:</strong> <code>"The {0} costs {1:C} for {2} months.\n", "studio", 499.0, 3</code> 
        /// </para>
        /// <para>
        /// <strong>Java:</strong> <code>"Today is %tD%n", new java.util.Date()</code><br />
        /// <strong>C#:</strong> <code>"Today is " + DateTime.Now.ToShortDateString()</code>
        /// </para>
        /// <param name="msg">Message.</param>
        public static String convert(String msg)
        {
            // read chars. if %, read next charand convert to  C#
            char[] chars = msg.ToCharArray ();
            java.lang.StringBuilder result = new java.lang.StringBuilder ();
            int number = 0;
            for (int i = 0; i < chars.Length; i++) {
                switch (chars [i]) {
                case '%':
                    i++;
                    switch (chars[i]) {
                    case '%':
                        result.append ('%');
                        break;
                    case 'n':
                        result.append ('\n');
                        break;
                    case '{':
                        result.append ("{{");
                        break;
                    case '}':
                        result.append ("}}");
                    default:
                        // gültige Zeichen: -0123456789bBhHsScCdoxXeEfgGaAtT
                        // berücksichtigt:  -0123456789    s     xX
                        result.append ('{'); // Beginn format
                        result.append (number); // index of format parameter

                        bool formattedPart = true;
                        bool beginnAlignment = true;
                        while (formattedPart) {
                            switch (chars [i]) {
                            case '-':
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                                if (beginnAlignment) {
                                    result.append (',');
                                    beginnAlignment = false;
                                }
                                result.append (chars [i]);
                                break;
                            case 'x':
                            case 'X':
                                result.append (':');
                                result.append (chars [i]);
                                formattedPart = false;
                                break;
                            case 's':
                                formattedPart = false;
                                break;
                            //case 'S': see http://stackoverflow.com/questions/1839649/c-sharp-string-format-flag-or-modifier-to-lowercase-param
                            default :
                                formattedPart = false;
                                i--;
                                break;
                            }
                            i++;
                        }
                        result.append ('}');
                        number ++;
                        break;
                    }
                    break;
                default:
                    result.append (chars [i]);
                    break;
                }
            }
            return result.toString ();;
        }
 /**
  * Returns the message string of the IllegalFormatConversionException.
  *
  * @return the message string of the IllegalFormatConversionException.
  */
 public override String getMessage()
 {
     java.lang.StringBuilder buffer = new java.lang.StringBuilder();
     buffer.append(c);
     buffer.append(" is incompatible with ");
     buffer.append(arg.getName());
     return buffer.toString();
 }
Example #40
0
 /**
  * Returns a string containing a concise, human-readable description of this
  * {@code PermissionCollection}.
  *
  * @return a printable representation for this {@code PermissionCollection}.
  */
 public override String ToString()
 {
     java.util.ArrayList<String> elist = new java.util.ArrayList<String>(100);
     java.util.Enumeration<Permission> elenum = elements();
     String superStr = base.ToString();
     int totalLength = superStr.length() + 5;
     if (elenum != null)
     {
         while (elenum.hasMoreElements())
         {
             String el = elenum.nextElement().toString();
             totalLength += el.length();
             elist.add(el);
         }
     }
     int esize = elist.size();
     totalLength += esize * 4;
     java.lang.StringBuilder result = new java.lang.StringBuilder(totalLength).append(superStr)
         .append(" ("); //$NON-NLS-1$
     for (int i = 0; i < esize; i++)
     {
         result.append("\n ").append(elist.get(i).toString()); //$NON-NLS-1$
     }
     return result.append("\n)\n").toString(); //$NON-NLS-1$
 }
Example #41
0
        /**
         * Returns the clear text representation of a given URL using HTTP format.
         *
         * @param url
         *            the URL object to be converted.
         * @return the clear text representation of the specified URL.
         * @see #parseURL
         * @see URL#toExternalForm()
         */
        protected internal String toExternalForm(URL url)
        {
            java.lang.StringBuilder answer = new java.lang.StringBuilder();
            answer.append(url.getProtocol());
            answer.append(':');
            String authority = url.getAuthority();
            if (authority != null && authority.length() > 0)
            {
                answer.append("//"); //$NON-NLS-1$
                answer.append(url.getAuthority());
            }

            String file = url.getFile();
            String refJ = url.getRef();
            if (file != null)
            {
                answer.append(file);
            }
            if (refJ != null)
            {
                answer.append('#');
                answer.append(refJ);
            }
            return answer.toString();
        }
Example #42
0
        /**
         * Produces a string representation of the date in SQL format
         *
         * @return a string representation of the date in SQL format - {@code
         *         "yyyy-mm-dd"}.
         */
        public override String ToString()
        {
            java.util.Calendar c = new java.util.GregorianCalendar();
            c.setTimeInMillis(this.milliseconds);
            java.lang.StringBuilder sb = new java.lang.StringBuilder(10);

            format(c.get(java.util.Calendar.YEAR), 4, sb);
            sb.append('-');
            format(c.get(java.util.Calendar.MONTH + 1), 2, sb);
            sb.append('-');
            format(c.get(java.util.Calendar.DAY_OF_MONTH), 2, sb);

            return sb.toString();
        }
Example #43
0
 public override String ToString()
 {
     java.lang.StringBuilder sb = new java.lang.StringBuilder();
     sb.append(isUserNode() ? "User" : "System"); //$NON-NLS-1$ //$NON-NLS-2$
     sb.append(" Preference Node: "); //$NON-NLS-1$
     sb.append(absolutePath());
     return sb.toString();
 }
Example #44
0
        /**
         * Re-initialize the properties and configuration. The initialization
         * process is same as the {@code LogManager} instantiation.
         * <p>
         * Notice : No {@code PropertyChangeEvent} are fired.
         * </p>
         *
         * @throws IOException
         *             if any IO related problems happened.
         * @throws SecurityException
         *             if security manager exists and it determines that caller does
         *             not have the required permissions to perform this action.
         */
        public void readConfiguration()
        {
            //throws IOException {
            // check config class
            String configClassName = java.lang.SystemJ.getProperty("java.util.logging.config.class"); //$NON-NLS-1$
            if (null == configClassName || null == getInstanceByClass(configClassName))
            {
                // if config class failed, check config file
                String configFile = java.lang.SystemJ.getProperty("java.util.logging.config.file"); //$NON-NLS-1$

                if (null == configFile)
                {
                    // if cannot find configFile, use default logging.properties
                    configFile = new java.lang.StringBuilder().append(
                            java.lang.SystemJ.getProperty("java.home")).append(java.io.File.separator) //$NON-NLS-1$
                            .append("lib").append(java.io.File.separator).append( //$NON-NLS-1$
                                    "logging.properties").toString(); //$NON-NLS-1$
                }

                java.io.InputStream input = null;
                try
                {
                    input = new java.io.BufferedInputStream(new java.io.FileInputStream(configFile));
                    readConfiguration(input);
                }
                finally
                {
                    if (input != null)
                    {
                        try
                        {
                            input.close();
                        }
                        catch (Exception e)
                        {// ignore
                        }
                    }
                }
            }
        }
Example #45
0
        /**
         * Transform the pattern to the valid file name, replacing any patterns, and
         * applying generation and uniqueID if present
         *
         * @param gen
         *            generation of this file
         * @return transformed filename ready for use
         */
        private String parseFileName(int gen)
        {
            int  cur           = 0;
            int  next          = 0;
            bool hasUniqueID   = false;
            bool hasGeneration = false;

            // TODO privilege code?
            String homePath = java.lang.SystemJ.getProperty("user.home"); //$NON-NLS-1$

            if (homePath == null)
            {
                throw new java.lang.NullPointerException();
            }
            bool homePathHasSepEnd = homePath.endsWith(java.io.File.separator);

            String tempPath = java.lang.SystemJ.getProperty("java.io.tmpdir"); //$NON-NLS-1$

            tempPath = tempPath == null ? homePath : tempPath;
            bool tempPathHasSepEnd = tempPath.endsWith(java.io.File.separator);

            java.lang.StringBuilder sb = new java.lang.StringBuilder();
            pattern = pattern.replace('/', java.io.File.separatorChar);

            char[] value = pattern.toCharArray();
            while ((next = pattern.indexOf('%', cur)) >= 0)
            {
                if (++next < pattern.length())
                {
                    switch (value[next])
                    {
                    case 'g':
                        sb.append(value, cur, next - cur - 1).append(gen);
                        hasGeneration = true;
                        break;

                    case 'u':
                        sb.append(value, cur, next - cur - 1).append(uniqueID);
                        hasUniqueID = true;
                        break;

                    case 't':
                        /*
                         * we should probably try to do something cute here like
                         * lookahead for adjacent '/'
                         */
                        sb.append(value, cur, next - cur - 1).append(tempPath);
                        if (!tempPathHasSepEnd)
                        {
                            sb.append(java.io.File.separator);
                        }
                        break;

                    case 'h':
                        sb.append(value, cur, next - cur - 1).append(homePath);
                        if (!homePathHasSepEnd)
                        {
                            sb.append(java.io.File.separator);
                        }
                        break;

                    case '%':
                        sb.append(value, cur, next - cur - 1).append('%');
                        break;

                    default:
                        sb.append(value, cur, next - cur);
                        break;
                    }
                    cur = ++next;
                }
                else
                {
                    // fail silently
                }
            }

            sb.append(value, cur, value.Length - cur);

            if (!hasGeneration && count > 1)
            {
                sb.append(".").append(gen); //$NON-NLS-1$
            }

            if (!hasUniqueID && uniqueID > 0)
            {
                sb.append(".").append(uniqueID); //$NON-NLS-1$
            }

            return(sb.toString());
        }
Example #46
0
 // print error message in some format
 protected void printInvalidPropMessage(String key, String value, java.lang.Exception e)
 {
     // logging.12=Invalid property value for
     String msg = new java.lang.StringBuilder().append(
         "Invalid property value for ") //$NON-NLS-1$
         .append(prefix).append(":").append(key).append("/").append( //$NON-NLS-1$//$NON-NLS-2$
                                                                    value).toString();
     errorMan.error(msg, e, ErrorManager.GENERIC_FAILURE);
 }