Package org.eigenbase.resgen

## Class Util

- java.lang.Object
- - org.eigenbase.resgen.Util

    abstract class Util
    extends java.lang.Object

Miscellaneous utility methods for the `org.eigenbase.resgen` package, all them `static` and package-private.

Since:
  3 December, 2001
Version:
  $Id: //open/util/resgen/src/org/eigenbase/resgen/Util.java#6 $
Author:
  jhyde

### Nested Class Summary

Nested Classes
`(package private) static class` `Util.DummyPrintStream` So we know to avoid recursively calling `printStackTrace(Throwable,PrintStream)`.
`(package private) static class` `Util.DummyPrintWriter` So we know to avoid recursively calling `printStackTrace(Throwable,java.io.PrintWriter)`.

### Field Summary

Fields
`(package private) static char` `fileSep`

### Constructor Summary

Constructors
`Util()`

### Method Summary

All Methods Static Methods Concrete Methods
`(package private) static java.net.URL` `convertPathToURL​(java.io.File file)` Creates a file-protocol URL for the given filename.
`(package private) static java.lang.String` `fileNameSansLocale​(java.lang.String fileName, java.lang.String suffix)` Given "happy/BirthdayResource_fr_FR.properties" and ".properties", returns "happy/BirthdayResource".
`(package private) static java.lang.String` `fileNameToClassName​(java.lang.String fileName, java.lang.String suffix)`
`(package private) static java.lang.String` `fileNameToCppClassName​(java.lang.String fileName, java.lang.String suffix)`
`(package private) static java.util.Locale` `fileNameToLocale​(java.lang.String fileName, java.lang.String suffix)` Given `happy/BirthdayResource_en_US.xml`, returns the locale "en_US".
`(package private) static void` `fillText​(java.io.PrintWriter pw, java.lang.String text, java.lang.String linePrefix, java.lang.String lineSuffix, int maxTextPerLine)` Left-justify a block of text.
`(package private) static java.lang.String` `formatError​(java.lang.String template, java.lang.Object[] args)`
`(package private) static void` `generateCommentBlock​(java.io.PrintWriter pw, java.lang.String name, java.lang.String text, java.lang.String comment)`
`(package private) static java.lang.String` `getClassNameSansPackage​(java.lang.String className, java.util.Locale locale)` Returns the class name without its package name but with a locale extension, if applicable.
`(package private) static ResourceDef.ResourceBundle` `load​(java.io.InputStream inStream)` loads InputStream and returns set of resources
`(package private) static ResourceDef.ResourceBundle` `load​(java.net.URL url)` loads URL into Document and returns set of resources
`(package private) static java.util.Locale` `parseLocale​(java.lang.String localeName)` Parses 'localeName' into a locale.
`(package private) static void` `printStackTrace​(java.lang.Throwable throwable, java.io.PrintStream s)`
`(package private) static void` `printStackTrace​(java.lang.Throwable throwable, java.io.PrintWriter s)`
`(package private) static java.lang.String` `quoteForJava​(java.lang.String val)`
`(package private) static java.lang.String` `quoteForJava​(java.lang.String val, boolean nullMeansNull)` Return `val` in double-quotes, suitable as a string in a Java or JScript program.
`(package private) static java.lang.String` `quoteForProperties​(java.lang.String val)` Returns a string quoted so that it can appear in a resource file.
`protected static java.lang.String` `removePackage​(java.lang.String s)`
`(package private) static java.lang.String` `removeSuffix​(java.lang.String s, java.lang.String suffix)`
`(package private) static java.lang.String` `replace​(java.lang.String s, java.lang.String find, java.lang.String replace)` Returns `s` with every instance of `find` converted to `replace`.
`(package private) static java.net.URL` `stringToUrl​(java.lang.String strFile)`
`(package private) static java.lang.Throwable[]` `toArray​(java.lang.Throwable err)` Converts a chain of `Throwable`s into an array.
`(package private) static java.lang.String` `toString​(java.lang.Throwable err)` Formats an error, which may have chained errors, as a string.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### fileSep

    static final char fileSep

### Constructor Detail

#### Util

    Util()

### Method Detail

#### load

    static ResourceDef.ResourceBundle load​(java.net.URL url)
                                    throws java.io.IOException

loads URL into Document and returns set of resources

Throws:
  `java.io.IOException`

#### load

    static ResourceDef.ResourceBundle load​(java.io.InputStream inStream)
                                    throws java.io.IOException

loads InputStream and returns set of resources

Throws:
  `java.io.IOException`

#### fillText

    static void fillText​(java.io.PrintWriter pw,
                         java.lang.String text,
                         java.lang.String linePrefix,
                         java.lang.String lineSuffix,
                         int maxTextPerLine)

Left-justify a block of text. Line breaks are preserved, but long lines are broken.

Parameters:
  `pw` - where to output the formatted text
  `text` - the text to be written
  `linePrefix` - a string to prepend to each output line
  `lineSuffix` - a string to append to each output line
  `maxTextPerLine` - the maximum number of characters to place on each line, not counting the prefix and suffix. If this is -1, never break lines.

#### stringToUrl

    static java.net.URL stringToUrl​(java.lang.String strFile)
                             throws java.io.IOException

Throws:
  `java.io.IOException`

#### convertPathToURL

    static java.net.URL convertPathToURL​(java.io.File file)

Creates a file-protocol URL for the given filename.

#### formatError

    static java.lang.String formatError​(java.lang.String template,
                                        java.lang.Object[] args)

#### replace

    static java.lang.String replace​(java.lang.String s,
                                    java.lang.String find,
                                    java.lang.String replace)

Returns `s` with every instance of `find` converted to `replace`.

#### quoteForJava

    static java.lang.String quoteForJava​(java.lang.String val,
                                         boolean nullMeansNull)

Return `val` in double-quotes, suitable as a string in a Java or JScript program.

Parameters:
  `val` - the value
  `nullMeansNull` - whether to print a null value as `null` (the default), as opposed to `""`

#### quoteForJava

    static java.lang.String quoteForJava​(java.lang.String val)

#### quoteForProperties

    static java.lang.String quoteForProperties​(java.lang.String val)

Returns a string quoted so that it can appear in a resource file.

#### fileNameToClassName

    static java.lang.String fileNameToClassName​(java.lang.String fileName,
                                                java.lang.String suffix)

#### fileNameToCppClassName

    static java.lang.String fileNameToCppClassName​(java.lang.String fileName,
                                                   java.lang.String suffix)

#### removeSuffix

    static java.lang.String removeSuffix​(java.lang.String s,
                                         java.lang.String suffix)

#### fileNameToLocale

    static java.util.Locale fileNameToLocale​(java.lang.String fileName,
                                             java.lang.String suffix)

Given `happy/BirthdayResource_en_US.xml`, returns the locale "en_US".

#### parseLocale

    static java.util.Locale parseLocale​(java.lang.String localeName)

Parses 'localeName' into a locale.

#### fileNameSansLocale

    static java.lang.String fileNameSansLocale​(java.lang.String fileName,
                                               java.lang.String suffix)

Given "happy/BirthdayResource_fr_FR.properties" and ".properties", returns "happy/BirthdayResource".

#### toArray

    static java.lang.Throwable[] toArray​(java.lang.Throwable err)

Converts a chain of `Throwable`s into an array.

#### toString

    static java.lang.String toString​(java.lang.Throwable err)

Formats an error, which may have chained errors, as a string.

#### printStackTrace

    static void printStackTrace​(java.lang.Throwable throwable,
                                java.io.PrintWriter s)

#### printStackTrace

    static void printStackTrace​(java.lang.Throwable throwable,
                                java.io.PrintStream s)

#### generateCommentBlock

    static void generateCommentBlock​(java.io.PrintWriter pw,
                                     java.lang.String name,
                                     java.lang.String text,
                                     java.lang.String comment)

#### getClassNameSansPackage

    static java.lang.String getClassNameSansPackage​(java.lang.String className,
                                                    java.util.Locale locale)

Returns the class name without its package name but with a locale extension, if applicable. For example, if class name is `happy.BirthdayResource`, and locale is `en_US`, returns `BirthdayResource_en_US`.

#### removePackage

    protected static java.lang.String removePackage​(java.lang.String s)