javapoint.StaticClasses
Class Utilities

java.lang.Object
  extended by javapoint.StaticClasses.Utilities

public class Utilities
extends java.lang.Object


Field Summary
static int DEBUG_STACK_OFFSET
           
 
Method Summary
static void close(java.lang.Object closable)
          Tries to close closable using reflection and without throwing an exception if it fails.
static javax.swing.JFileChooser createFileChooser()
           
static javax.swing.JFileChooser createImageFileChooser()
           
static java.io.File createTemporaryFile(java.lang.String prefix, java.lang.String suffix, boolean persistent, java.io.InputStream contents)
          Tries to create a temporary file and initialize it using contents.
static java.lang.String debug(int stackOffset, java.lang.Object... objects)
          Concatenates the source location of the call and the string representations of the parameters separated by spaces.
static void debugPrint(java.lang.Object... objects)
          Prints on the standard output the concatenation of the source location of the call and the string representations of the parameters separated by spaces.
static java.io.File getApplicationFile()
           
static java.net.URL getApplicationURL()
           
static java.lang.Class<?> getCallerClass()
          If a method A.a() calls a method B.b(), then the result of calling this method in b() will be A.class.
static java.lang.String getCallerMethodName()
          If a method a() calls a method b(), then the result of calling this method in b() will be "a".
static int getDebugStackOffset()
           
static java.util.logging.Logger getLoggerForThisMethod()
          Calls Logger.getLogger(String) using the fully qualified name of the calling method.
static
<T> T
throwUnchecked(java.lang.Throwable cause)
          Use this method when you want to propagate a checked exception wrapped in a runtime exception instead of using the normal checked exception mechanism.
static
<T> java.util.List<T>
toList(java.util.Enumeration<T> enumeration)
           
static void write(java.io.InputStream input, java.io.OutputStream output)
          Writes input to output; this method does not close the streams when it terminates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_STACK_OFFSET

public static final int DEBUG_STACK_OFFSET
Method Detail

createTemporaryFile

public static java.io.File createTemporaryFile(java.lang.String prefix,
                                               java.lang.String suffix,
                                               boolean persistent,
                                               java.io.InputStream contents)
                                        throws java.io.IOException
Tries to create a temporary file and initialize it using contents. contents is closed at the end of this method.

Parameters:
prefix -
Not null
suffix -
Not null
persistent - true if the file shouldn't be automatically deleted
contents -
Not null
Input-output
Returns:
a temporary file that is deleted when the program exits
Not null
New
Throws:
java.io.IOException - if
  • the file cannot be created
  • an I/O error occurs while writing contents to the file

write

public static void write(java.io.InputStream input,
                         java.io.OutputStream output)
                  throws java.io.IOException
Writes input to output; this method does not close the streams when it terminates.

Parameters:
input -
Not null
Input-output
output -
Not null
Input-output
Throws:
java.io.IOException - if an I/O error occurs

close

public static void close(java.lang.Object closable)
Tries to close closable using reflection and without throwing an exception if it fails.

Parameters:
closable -
Maybe null

toList

public static <T> java.util.List<T> toList(java.util.Enumeration<T> enumeration)
Type Parameters:
T - The type of the elements
Parameters:
enumeration -
Not null
Input-output
Returns:

Not null
New

getApplicationURL

public static java.net.URL getApplicationURL()
Returns:

Not null

getApplicationFile

public static java.io.File getApplicationFile()
Returns:

Not null
New

getCallerClass

public static java.lang.Class<?> getCallerClass()
If a method A.a() calls a method B.b(), then the result of calling this method in b() will be A.class.
Warning: this method can only be used directly.
If you want to refactor your code, you can re-implement the functionality using Thread.currentThread().getStackTrace().

Returns:
null if the caller class cannot be retrieved
A possibly null value

getCallerMethodName

public static java.lang.String getCallerMethodName()
If a method a() calls a method b(), then the result of calling this method in b() will be "a".
Warning: this method can only be used directly.
If you want to refactor your code, you can re-implement the functionality using Thread.currentThread().getStackTrace().

Returns:
null if the caller method cannot be retrieved
A possibly null value

getLoggerForThisMethod

public static java.util.logging.Logger getLoggerForThisMethod()
Calls Logger.getLogger(String) using the fully qualified name of the calling method.
Warning: this method can only be used directly.
If you want to refactor your code, you can re-implement the functionality using Thread.currentThread().getStackTrace().

Returns:

A non-null value
Throws:
java.lang.NullPointerException - if the caller class cannot be retrieved

throwUnchecked

public static <T> T throwUnchecked(java.lang.Throwable cause)
Use this method when you want to propagate a checked exception wrapped in a runtime exception instead of using the normal checked exception mechanism.

Type Parameters:
T - the type that the caller is supposed to return
Parameters:
cause -
Should not be null
Shared parameter
Returns:

Does not return
Throws:
java.lang.RuntimeException - with cause as cause if it is a checked exception, otherwise cause is re-thrown

debug

public static java.lang.String debug(int stackOffset,
                                     java.lang.Object... objects)
Concatenates the source location of the call and the string representations of the parameters separated by spaces.
This is method helps to perform console debugging using System.out or System.err.

Parameters:
stackOffset - DEBUG_STACK_OFFSET is the source of the call, DEBUG_STACK_OFFSET + 1 is the source of the call's caller, and so forth
Range: [O .. Integer.MAX_VALUE]
objects -
Should not be null
Returns:

A new value
A non-null value

debugPrint

public static void debugPrint(java.lang.Object... objects)
Prints on the standard output the concatenation of the source location of the call and the string representations of the parameters separated by spaces.

Parameters:
objects -
Should not be null

getDebugStackOffset

public static int getDebugStackOffset()
Returns:

Range: [0 .. Integer.MAX_VALUE]

createFileChooser

public static javax.swing.JFileChooser createFileChooser()
Returns:

Not null
New

createImageFileChooser

public static javax.swing.JFileChooser createImageFileChooser()