Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.cayenne.util
Class Util

    java.lang.Object
      org.apache.cayenne.util.Util

    public class Util

extends java.lang.Object

Contains various unorganized static utility methods used across Cayenne.

Author:
  Andrei Adamchik

Constructor Summary
`Util()`

Method Summary
`static java.lang.Object` | `cloneViaSerialization(java.io.Serializable obj)` Creates Serializable object copy using serialization/deserialization.
`static boolean` | `copy(java.io.File source, java.io.File destination)` Copies file contents from source to destination.
`static boolean` | `copy(java.net.URL from, java.io.File to)` Save URL contents to a file.
`static void` | `copyPipe(java.io.InputStream in, java.io.OutputStream out, int bufSizeHint)` Reads data from the input and writes it to the output, until the end of the input stream.
`static org.xml.sax.XMLReader` | `createXmlReader()` Creates an XMLReader with default feature set.
`static boolean` | `delete(java.lang.String filePath, boolean recursive)` Deletes a file or directory, allowing recursive directory deletion.
`static java.lang.String` | `encodeXmlAttribute(java.lang.String str)` Encodes a string so that it can be used as an attribute value in an XML document.
`static java.lang.String` | `extractFileExtension(java.lang.String fileName)` Extracts extension from the file name.
`static java.lang.Class` | `getJavaClass(java.lang.String className)` Creates a Java class, handling regular class names as well as single-dimensional arrays and primitive types.
`static java.lang.String` | `getPackagePath(java.lang.String className)` Returns package name for the Java class as a path separated with forward slash ("/").
`static int` | `hashCode(java.util.Collection c)` Builds a hashCode of Collection.
`static boolean` | `isAccessible(java.lang.reflect.Member member)` Returns true if a Member is accessible via reflection under normal Java access controls.
`static boolean` | `isEmptyString(java.lang.String string)` Returns true, if the String is null or an empty string.
`static int` | `nullSafeCompare(boolean nullsFirst, java.lang.Comparable o1, java.lang.Object o2)` Compares two objects similar to "Comparable.compareTo(Object)".
`static boolean` | `nullSafeEquals(java.lang.Object o1, java.lang.Object o2)` Compares two objects similar to "Object.equals(Object)".
`static java.lang.String` | `prettyTrim(java.lang.String str, int maxLength)` Trims long strings substituting middle part with "...".
`static java.util.Iterator` | `sortedIterator(java.util.Iterator it, java.util.Comparator comparator)` Returns a sorted iterator from an unsorted one.
`static java.util.regex.Pattern` | `sqlPatternToPattern(java.lang.String pattern, boolean ignoreCase)`
`static java.lang.String` | `sqlPatternToRegex(java.lang.String pattern, boolean ignoreCase)` Deprecated. since 1.2 use "sqlPatternToPattern".
`static java.lang.String` | `stringFromFile(java.io.File file)` Reads file contents, returning it as a String, using System default line separator.
`static java.lang.String` | `stringFromFile(java.io.File file, java.lang.String joinWith)` Reads file contents, returning it as a String, joining lines with provided separator.
`static java.lang.String` | `stripFileExtension(java.lang.String fileName)` Strips extension from the file name.
`static java.lang.String` | `stripLineBreaks(java.lang.String string, java.lang.String replaceWith)` Strips "\n", "\r\n", "\r" from the argument string.
`static java.lang.String` | `substBackslashes(java.lang.String string)` Replaces all backslashes "\" with forward slashes "/".
`static java.util.Map` | `toMap(java.lang.Object[] keys, java.lang.Object[] values)` Creates a mutable map out of two arrays with keys and values.
`static java.lang.Throwable` | `unwindException(java.lang.Throwable th)` Looks up and returns the root cause of an exception.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Util

    public Util()

Method Detail

### stringFromFile

    public static java.lang.String stringFromFile(java.io.File file)
                                           throws java.io.IOException

  Reads file contents, returning it as a String, using System default line separator.

  Throws:
    `java.io.IOException`

### stringFromFile

    public static java.lang.String stringFromFile(java.io.File file,
                                                  java.lang.String joinWith)
                                           throws java.io.IOException

  Reads file contents, returning it as a String, joining lines with provided separator.

  Throws:
    `java.io.IOException`

### copy

    public static boolean copy(java.io.File source,
                               java.io.File destination)

  Copies file contents from source to destination. Makes up for the lack of file copying utilities in Java

### copy

    public static boolean copy(java.net.URL from,
                               java.io.File to)

  Save URL contents to a file.

### copyPipe

    public static void copyPipe(java.io.InputStream in,
                                java.io.OutputStream out,
                                int bufSizeHint)
                         throws java.io.IOException

  Reads data from the input and writes it to the output, until the end of the input stream.

  Parameters:
    `in` -
    `out` -
    `bufSizeHint` -
  Throws:
    `java.io.IOException`

### delete

    public static boolean delete(java.lang.String filePath,
                                 boolean recursive)

  Deletes a file or directory, allowing recursive directory deletion. This is an improved version of File.delete() method.

### substBackslashes

    public static java.lang.String substBackslashes(java.lang.String string)

  Replaces all backslashes "\" with forward slashes "/". Convenience method to convert path Strings to URI format.

### unwindException

    public static java.lang.Throwable unwindException(java.lang.Throwable th)

  Looks up and returns the root cause of an exception. If none is found, returns supplied Throwable object unchanged. If root is found, recursively "unwraps" it, and returns the result to the user.

### nullSafeEquals

    public static boolean nullSafeEquals(java.lang.Object o1,
                                         java.lang.Object o2)

  Compares two objects similar to "Object.equals(Object)". Unlike Object.equals(..), this method doesn't throw an exception if any of the two objects is null.

### nullSafeCompare

    public static int nullSafeCompare(boolean nullsFirst,
                                      java.lang.Comparable o1,
                                      java.lang.Object o2)

  Compares two objects similar to "Comparable.compareTo(Object)". Unlike Comparable.compareTo(..), this method doesn't throw an exception if any of the two objects is null.

  Since:
    1.1

### isEmptyString

    public static boolean isEmptyString(java.lang.String string)

  Returns true, if the String is null or an empty string.

### cloneViaSerialization

    public static java.lang.Object cloneViaSerialization(java.io.Serializable obj)
                                                  throws java.lang.Exception

  Creates Serializable object copy using serialization/deserialization.

  Throws:
    `java.lang.Exception`

### createXmlReader

    public static org.xml.sax.XMLReader createXmlReader()
                                                 throws org.xml.sax.SAXException,
                                                        javax.xml.parsers.ParserConfigurationException

  Creates an XMLReader with default feature set. Note that all Cayenne internal XML parsers should probably use XMLReader obtained via this method for consistency sake, and can customize feature sets as needed.

  Throws:
    `org.xml.sax.SAXException`
    `javax.xml.parsers.ParserConfigurationException`

### getPackagePath

    public static java.lang.String getPackagePath(java.lang.String className)

  Returns package name for the Java class as a path separated with forward slash ("/"). Method is used to lookup resources that are located in package subdirectories. For example, a String "a/b/c" will be returned for class name "a.b.c.ClassName".

### toMap

    public static java.util.Map toMap(java.lang.Object[] keys,
                                      java.lang.Object[] values)

  Creates a mutable map out of two arrays with keys and values.

  Since:
    1.2

### extractFileExtension

    public static java.lang.String extractFileExtension(java.lang.String fileName)

  Extracts extension from the file name. Dot is not included in the returned string.

### stripFileExtension

    public static java.lang.String stripFileExtension(java.lang.String fileName)

  Strips extension from the file name.

### stripLineBreaks

    public static java.lang.String stripLineBreaks(java.lang.String string,
                                                   java.lang.String replaceWith)

  Strips "\n", "\r\n", "\r" from the argument string.

  Since:
    1.2

### encodeXmlAttribute

    public static java.lang.String encodeXmlAttribute(java.lang.String str)

  Encodes a string so that it can be used as an attribute value in an XML document. Will do conversion of the greater/less signs, quotes and ampersands.

### prettyTrim

    public static java.lang.String prettyTrim(java.lang.String str,
                                              int maxLength)

  Trims long strings substituting middle part with "...".

  Parameters:
    `str` - String to trim.
    `maxLength` - maximum allowable length. Must be at least 5, or an IllegalArgumentException is thrown.
  Returns:
    String

### sortedIterator

    public static java.util.Iterator sortedIterator(java.util.Iterator it,
                                                    java.util.Comparator comparator)

  Returns a sorted iterator from an unsorted one. Use this method as a last resort, since it is much less efficient then just sorting a collection that backs the original iterator.

### hashCode

    public static int hashCode(java.util.Collection c)

  Builds a hashCode of Collection.

### sqlPatternToRegex

    public static java.lang.String sqlPatternToRegex(java.lang.String pattern,
                                                     boolean ignoreCase)

  Deprecated. since 1.2 use "sqlPatternToPattern".

  Converts a SQL-style pattern to a valid Perl regular expression. E.g.:

  `"billing_%"` will become `/^billing_.*$/`

  `"user?"` will become `/^user.?$/`

### sqlPatternToPattern

    public static java.util.regex.Pattern sqlPatternToPattern(java.lang.String pattern,
                                                              boolean ignoreCase)

  Since:
    1.2

### isAccessible

    public static boolean isAccessible(java.lang.reflect.Member member)

  Returns true if a Member is accessible via reflection under normal Java access controls.

  Since:
    1.2

### getJavaClass

    public static java.lang.Class getJavaClass(java.lang.String className)
                                        throws java.lang.ClassNotFoundException

  Creates a Java class, handling regular class names as well as single-dimensional arrays and primitive types.

  Throws:
    `java.lang.ClassNotFoundException`
  Since:
    1.2

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2006 Apache.org All Rights Reserved.