com.limegroup.gnutella.util
Class CommonUtils

java.lang.Object
  extended bycom.limegroup.gnutella.util.CommonUtils

public final class CommonUtils
extends java.lang.Object

This class handles common utility functions that many classes may want to access.


Field Summary
static java.lang.String QHD_VENDOR_NAME
          The vendor code for QHD and GWebCache.
 
Method Summary
static boolean canLaunchFileWithQuickTime(java.io.File file)
          Convenience method that checks both that the QuickTime for Java libraries are available and that we can launch the specified file using QuickTime.
static int compare(java.lang.Object o1, java.lang.Object o2)
          Convenience method to generically compare any two comparable things.
static java.lang.String convertFileName(java.lang.String name)
          Replaces OS specific illegal characters from any filename with '_', including ( / \n \r \t ) on all operating systems, ( ? * \ < > | " ) on Windows, ( ` ) on unix.
static boolean copy(java.io.File src, java.io.File dst)
          Copies the file 'src' to 'dst', returning true iff the copy succeeded.
static int copy(java.io.File src, int amount, java.io.File dst)
          Attempts to copy the first 'amount' bytes of file 'src' to 'dst', returning the number of bytes actually copied.
static void copyResourceFile(java.lang.String fileName)
          Copies the specified resource file into the current directory from the jar file.
static void copyResourceFile(java.lang.String fileName, java.io.File newFile)
          Copies the specified resource file into the current directory from the jar file.
static void copyResourceFile(java.lang.String fileName, java.io.File newFile, boolean forceOverwrite)
          Copies the specified resource file into the current directory from the jar file.
static java.lang.String decode(java.lang.String s)
          Copied from URLDecoder.java
static java.io.File getCurrentDirectory()
          Returns the user's current working directory as a File instance, or null if the property is not set.
static int getGUESSMajorVersionNumber()
          Gets the major version of GUESS supported.
static int getGUESSMinorVersionNumber()
          Gets the minor version of GUESS supported.
static java.lang.String getHttpServer()
          Returns the string for the server that should be reported in the HTTP "Server: " tag.
static java.lang.String getJavaVersion()
          Returns the version of java we're using.
static java.lang.String getLimeWireVersion()
          Returns the current version number of LimeWire as a string, e.g., "1.4".
static int getMajorVersionNumber()
          Gets the major version of LimeWire.
static int getMinorVersionNumber()
          Gets the minor version of LimeWire.
static java.lang.String getOS()
          Returns the operating system.
static java.lang.String getOSVersion()
          Returns the operating system version.
static java.io.File getResourceFile(java.lang.String location)
          Gets a resource file using the CommonUtils class loader, or the system class loader if CommonUtils isn't loaded.
static int getUPMajorVersionNumber()
          Gets the major version of Ultrapeer Protocol supported.
static int getUPMinorVersionNumber()
          Gets the minor version of Ultrapeer Protocol supported.
static java.io.File getUserHomeDir()
          Returns the user home directory.
static java.lang.String getUserName()
          Return the user's name.
static java.io.File getUserSettingsDir()
          Returns the directory where all user settings should be stored.
static java.lang.String getVendor()
          Returns a version number appropriate for upload headers.
static boolean isAnyMac()
          Returns whether or not the os is any Mac os.
static boolean isJaguarOrAbove()
          Returns whether or not the os is Mac OSX 10.2 or above.
static boolean isJava118()
          Returns whether or not the current JVM is a 1.1.8 implementation.
static boolean isJava13OrLater()
          Returns whether or not the current JVM is 1.3.x or later
static boolean isJava14OrLater()
          Returns whether or not the current JVM is 1.4.x or later
static boolean isLinux()
          Returns whether or not the os is Linux.
static boolean isMacClassic()
          Returns whether or not the os is Mac 9.1 or earlier.
static boolean isMacOSX()
          Returns whether or not the os is Mac OSX.
static boolean isPro()
          Accessor for whether or not this is LimeWire pro.
static boolean isQuickTimeAvailable()
          Returns whether or not the QuickTime libraries are available on the user's system.
static boolean isQuickTimeSupportedFormat(java.io.File file)
          Returns whether or not the specified file extension is supported in our implementation of QuickTime.
static boolean isSolaris()
          Returns whether or not the os is Solaris.
static boolean isTestingVersion()
          Accessor for whether or not this is a testing version (3.5.6-1jpp) of LimeWire.
static boolean isUltrapeerOS()
          Returns whether or not this operating system is considered capable of meeting the requirements of a ultrapeer.
static boolean isUnix()
          Returns whether or not the os is some version of Unix, defined here as only Solaris or Linux.
static boolean isWindows()
          Returns whether or not the os is some version of Windows.
static boolean isWindows2000orXP()
          Returns whether or not the os is 2000 or XP.
static boolean isWindowsNTor2000orXP()
          Returns whether or not the os is Windows NT, 2000, or XP.
static boolean supportsTray()
          Returns true if this is Windows NT or Windows 2000 and hence can support a system tray feature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

QHD_VENDOR_NAME

public static final java.lang.String QHD_VENDOR_NAME
The vendor code for QHD and GWebCache. WARNING: to avoid character encoding problems, this is hard-coded in QueryReply as well. So if you change this, you must change QueryReply.

See Also:
Constant Field Values
Method Detail

getGUESSMajorVersionNumber

public static int getGUESSMajorVersionNumber()
Gets the major version of GUESS supported.


getGUESSMinorVersionNumber

public static int getGUESSMinorVersionNumber()
Gets the minor version of GUESS supported.


getUPMajorVersionNumber

public static int getUPMajorVersionNumber()
Gets the major version of Ultrapeer Protocol supported.


getUPMinorVersionNumber

public static int getUPMinorVersionNumber()
Gets the minor version of Ultrapeer Protocol supported.


getLimeWireVersion

public static java.lang.String getLimeWireVersion()
Returns the current version number of LimeWire as a string, e.g., "1.4".


getMajorVersionNumber

public static int getMajorVersionNumber()
Gets the major version of LimeWire.


getMinorVersionNumber

public static int getMinorVersionNumber()
Gets the minor version of LimeWire.


isPro

public static boolean isPro()
Accessor for whether or not this is LimeWire pro.

Returns:
true if it is pro, otherwise false

isTestingVersion

public static boolean isTestingVersion()
Accessor for whether or not this is a testing version (3.5.6-1jpp) of LimeWire.

Returns:
true if the version is 3.5.6-1jpp, otherwise false

getVendor

public static java.lang.String getVendor()
Returns a version number appropriate for upload headers. Same as '"LimeWire "+getLimeWireVersion'.


getHttpServer

public static java.lang.String getHttpServer()
Returns the string for the server that should be reported in the HTTP "Server: " tag.

Returns:
the HTTP "Server: " header value

getJavaVersion

public static java.lang.String getJavaVersion()
Returns the version of java we're using.


getOS

public static java.lang.String getOS()
Returns the operating system.


getOSVersion

public static java.lang.String getOSVersion()
Returns the operating system version.


getCurrentDirectory

public static java.io.File getCurrentDirectory()
Returns the user's current working directory as a File instance, or null if the property is not set.

Returns:
the user's current working directory as a File instance, or null if the property is not set

supportsTray

public static boolean supportsTray()
Returns true if this is Windows NT or Windows 2000 and hence can support a system tray feature.


isUltrapeerOS

public static boolean isUltrapeerOS()
Returns whether or not this operating system is considered capable of meeting the requirements of a ultrapeer.

Returns:
true if this os meets ultrapeer requirements, false otherwise

isWindows

public static boolean isWindows()
Returns whether or not the os is some version of Windows.

Returns:
true if the application is running on some Windows version, false otherwise

isWindowsNTor2000orXP

public static boolean isWindowsNTor2000orXP()
Returns whether or not the os is Windows NT, 2000, or XP.

Returns:
true if the application is running on Windows NT, 2000, or XP false otherwise

isWindows2000orXP

public static boolean isWindows2000orXP()
Returns whether or not the os is 2000 or XP.

Returns:
true if the application is running on 2000 or XP, false otherwise

isMacClassic

public static boolean isMacClassic()
Returns whether or not the os is Mac 9.1 or earlier.

Returns:
true if the application is running on a Mac version prior to OSX, false otherwise

isMacOSX

public static boolean isMacOSX()
Returns whether or not the os is Mac OSX.

Returns:
true if the application is running on Mac OSX, false otherwise

isJaguarOrAbove

public static boolean isJaguarOrAbove()
Returns whether or not the os is Mac OSX 10.2 or above.

Returns:
true if the application is running on Mac OSX, 10.2 or above, false otherwise

isAnyMac

public static boolean isAnyMac()
Returns whether or not the os is any Mac os.

Returns:
true if the application is running on Mac OSX or any previous mac version, false otherwise

isSolaris

public static boolean isSolaris()
Returns whether or not the os is Solaris.

Returns:
true if the application is running on Solaris, false otherwise

isLinux

public static boolean isLinux()
Returns whether or not the os is Linux.

Returns:
true if the application is running on Linux, false otherwise

isUnix

public static boolean isUnix()
Returns whether or not the os is some version of Unix, defined here as only Solaris or Linux.


isJava118

public static boolean isJava118()
Returns whether or not the current JVM is a 1.1.8 implementation.

Returns:
true if we are running on 1.1.8, false otherwise

isJava13OrLater

public static boolean isJava13OrLater()
Returns whether or not the current JVM is 1.3.x or later

Returns:
true if we are running on 1.3.x or later, false otherwise

isJava14OrLater

public static boolean isJava14OrLater()
Returns whether or not the current JVM is 1.4.x or later

Returns:
true if we are running on 1.4.x or later, false otherwise

copy

public static int copy(java.io.File src,
                       int amount,
                       java.io.File dst)
Attempts to copy the first 'amount' bytes of file 'src' to 'dst', returning the number of bytes actually copied. If 'dst' already exists, the copy may or may not succeed.

Parameters:
src - the source file to copy
amount - the amount of src to copy, in bytes
dst - the place to copy the file
Returns:
the number of bytes actually copied. Returns 'amount' if the entire requested range was copied.

copy

public static boolean copy(java.io.File src,
                           java.io.File dst)
Copies the file 'src' to 'dst', returning true iff the copy succeeded. If 'dst' already exists, the copy may or may not succeed. May also fail for VERY large source files.


getUserHomeDir

public static java.io.File getUserHomeDir()
Returns the user home directory.

Returns:
the File instance denoting the abstract pathname of the user's home directory, or null if the home directory does not exist

getUserName

public static java.lang.String getUserName()
Return the user's name.

Returns:
the String denoting the user's name.

getUserSettingsDir

public static java.io.File getUserSettingsDir()
Returns the directory where all user settings should be stored. This is where all application data should be stored. If the directory does does not already exist, this attempts to create the directory, although this is not guaranteed to succeed.

Returns:
the File instance denoting the user's home directory for the application, or null if that directory does not exist

isQuickTimeAvailable

public static boolean isQuickTimeAvailable()
Returns whether or not the QuickTime libraries are available on the user's system.

Returns:
true if the QuickTime libraries are available, false otherwise

isQuickTimeSupportedFormat

public static boolean isQuickTimeSupportedFormat(java.io.File file)
Returns whether or not the specified file extension is supported in our implementation of QuickTime. So, this will only return true if both QuickTime supports the extension in general, and if our QuickTime implementation supports the extension.

Returns:
true if QuickTime supports the file type and our implementation of QuickTime supports that part of QuickTime's functionality, false otherwise

canLaunchFileWithQuickTime

public static boolean canLaunchFileWithQuickTime(java.io.File file)
Convenience method that checks both that the QuickTime for Java libraries are available and that we can launch the specified file using QuickTime.

Returns:
true if the QuickTime for Java libraries are available and the file is of a type that our QuickTime players support, false otherwise

compare

public static int compare(java.lang.Object o1,
                          java.lang.Object o2)
Convenience method to generically compare any two comparable things. Handles comparison uniquely for 'native' types. This is for a few reasons: 1) We want to compare strings by lowercase comparison 2) Java 1.1.8 did not have native types implement Comparable Note that we check for both java.lang.Comparable and java.lang.Comparable, and we do this _before_ checking for native types. So, this is slightly optimized for more recent JVMs Note that non-integer comparisons must specifically check if the difference is less or greater than 0 so that rounding won't be wrong. Of the native types, we check 'Integer' first since that's the most common, Boolean, then Double or Float, and finally, the rest will be caught in 'Number', which just uses an int comparison.


getResourceFile

public static java.io.File getResourceFile(java.lang.String location)
Gets a resource file using the CommonUtils class loader, or the system class loader if CommonUtils isn't loaded.


decode

public static java.lang.String decode(java.lang.String s)
Copied from URLDecoder.java


copyResourceFile

public static void copyResourceFile(java.lang.String fileName)
Copies the specified resource file into the current directory from the jar file. If the file already exists, no copy is performed.

Parameters:
fileName - the name of the file to copy, relative to the jar file -- such as "com/limegroup/gnutella/gui/images/image.gif"

copyResourceFile

public static void copyResourceFile(java.lang.String fileName,
                                    java.io.File newFile)
Copies the specified resource file into the current directory from the jar file. If the file already exists, no copy is performed.

Parameters:
fileName - the name of the file to copy, relative to the jar file -- such as "com/limegroup/gnutella/gui/images/image.gif"
newFile - the new File instance where the resource file will be copied to

copyResourceFile

public static void copyResourceFile(java.lang.String fileName,
                                    java.io.File newFile,
                                    boolean forceOverwrite)
Copies the specified resource file into the current directory from the jar file. If the file already exists, no copy is performed.

Parameters:
fileName - the name of the file to copy, relative to the jar file -- such as "com/limegroup/gnutella/gui/images/image.gif"
newFile - the new File instance where the resource file will be copied to -- if this argument is null, the file will be copied to the current directory
forceOverwrite - specifies whether or not to overwrite the file if it already exists

convertFileName

public static java.lang.String convertFileName(java.lang.String name)
Replaces OS specific illegal characters from any filename with '_', including ( / \n \r \t ) on all operating systems, ( ? * \ < > | " ) on Windows, ( ` ) on unix.

Parameters:
name - the filename to check for illegal characters
Returns:
String containing the cleaned filename