Overview | Package | Class | Use | 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.

Constructor Summary
`Util()`

Method Summary
`static
`<T extends java.io.Serializable> T`
` | `cloneViaSerialization(T object)` Creates Serializable object copy using serialization/deserialization.
`static boolean` | `copy(java.io.File source, java.io.File destination)` Deprecated. since 3.1 this method is not used by Cayenne
`static boolean` | `copy(java.net.URL from, java.io.File to)` Deprecated. since 3.1 this method is not used by Cayenne.
`static void` | `copyPipe(java.io.InputStream in, java.io.OutputStream out, int bufSizeHint)` Deprecated. since 3.1 this method is unused by Cayenne.
`static org.xml.sax.XMLReader` | `createXmlReader()` Creates an XMLReader with default feature set.
`static boolean` | `delete(java.lang.String filePath, boolean recursive)` Deprecated. since 3.1 this method is unused by Cayenne.
`static java.lang.String` | `encodeXmlAttribute(java.lang.String string)` 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
`<T> int`
` | `nullSafeCompare(boolean nullsFirst, java.lang.Comparable<T> o1, T 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
`<T> java.util.Iterator<T>`
` | `sortedIterator(java.util.Iterator<T> it, java.util.Comparator<T> 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` | `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, char replaceWith)` Strips "\n", "\r\n", "\r" from the argument string, replacing them with a provided character.
`static java.lang.String` | `stripLineBreaks(java.lang.String string, java.lang.String replaceWith)` Deprecated. since 3.1 in favor of `stripLineBreaks(String, char)`.
`static java.lang.String` | `stripPackageName(java.lang.String className)` Returns an unqualified class name for the fully qualified name.
`static java.lang.String` | `substBackslashes(java.lang.String string)` Replaces all backslashes "\" with forward slashes "/".
`static java.io.File` | `toFile(java.net.URL url)` Converts URL to file.
`static
`<K,V> java.util.Map<K,V>`
` | `toMap(K[] keys, V[] 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

### toFile

    public static java.io.File toFile(java.net.URL url)
                               throws java.lang.IllegalArgumentException

  Converts URL to file. Throws `IllegalArgumentException` if the URL is not a "file://" URL.

  Throws:
    `java.lang.IllegalArgumentException`

### 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)

  Deprecated. since 3.1 this method is not used by Cayenne

  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)

  Deprecated. since 3.1 this method is not used by Cayenne.

  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

  Deprecated. since 3.1 this method is unused by Cayenne.

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

  Throws:
    `java.io.IOException`

### delete

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

  Deprecated. since 3.1 this method is unused by Cayenne.

  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 <T> int nullSafeCompare(boolean nullsFirst,
                                          java.lang.Comparable<T> o1,
                                          T 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 <T extends java.io.Serializable> T cloneViaSerialization(T object)
                                                                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".

### stripPackageName

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

  Returns an unqualified class name for the fully qualified name.

  Since:
    3.0

### toMap

    public static <K,V> java.util.Map<K,V> toMap(K[] keys,
                                                 V[] 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

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

  Deprecated. since 3.1 in favor of `stripLineBreaks(String, char)`.

  Since:
    1.2

### stripLineBreaks

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

  Strips "\n", "\r\n", "\r" from the argument string, replacing them with a provided character.

  Since:
    3.1

### encodeXmlAttribute

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

  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 <T> java.util.Iterator<T> sortedIterator(java.util.Iterator<T> it,
                                                           java.util.Comparator<T> 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.

### 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 | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2012 Apache Cayenne. All Rights Reserved.