net.sourceforge.java.util.net
Class NetworkUtils

java.lang.Object
  extended bynet.sourceforge.java.util.net.NetworkUtils

public class NetworkUtils
extends Object

Collection of network related utility methods.

Author:
Sebastian Machhausen

Field Summary
private static String DEFAULT_HTTP_PREFIX
           The default http prefix
static String[] DEFAULT_NEWSFEED_FILE_EXTENSIONS
           The default newsfeed file extensions
 
Constructor Summary
NetworkUtils()
           
 
Method Summary
static String addHttp(String url)
           Adds the default http:// prefix to the specified url.
static String extractFilename(String url)
           Extracts the filename from the specified url String.
static String extractFilename(URL url)
           Extracts the filename from the specified URL.
static Program getDefaultBrowser()
           Gets the Program used as default browser on the system.
static String getHostUrl(String url)
           Gets a valid url host String from the specified url, i.e. strips off everything besides the protocol and host from the given url.
static boolean isNewsFeed(String url)
           Returns true if the specified url is a potential newsfeed juding on the default newsfeed file extensions as deposited in DEFAULT_NEWSFEED_FILE_EXTENSIONS.
static boolean isValidUrl(String url)
           Tests if the specified url is valid.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_HTTP_PREFIX

private static final String DEFAULT_HTTP_PREFIX

The default http prefix

See Also:
Constant Field Values

DEFAULT_NEWSFEED_FILE_EXTENSIONS

public static final String[] DEFAULT_NEWSFEED_FILE_EXTENSIONS

The default newsfeed file extensions

Constructor Detail

NetworkUtils

public NetworkUtils()
Method Detail

isValidUrl

public static boolean isValidUrl(String url)

Tests if the specified url is valid. This does not have to mean that that it is reachable too.

Parameters:
url - the url to test for validity
Returns:
true if the specified url is valid; false if invalid

addHttp

public static String addHttp(String url)

Adds the default http:// prefix to the specified url. If it already contains the default http:// prefix it remains unmodified.

Parameters:
url - the url to add the http:// prefix to
Returns:
the url preceded by the default http:// prefix

extractFilename

public static String extractFilename(URL url)

Extracts the filename from the specified URL.

Parameters:
url - the URL to extract the filename of
Returns:
the extracted filename

extractFilename

public static String extractFilename(String url)

Extracts the filename from the specified url String.

Parameters:
url - the url to extract the filename of
Returns:
the extracted filename

isNewsFeed

public static boolean isNewsFeed(String url)

Returns true if the specified url is a potential newsfeed juding on the default newsfeed file extensions as deposited in DEFAULT_NEWSFEED_FILE_EXTENSIONS.

Parameters:
url - the url to verify
Returns:
code>true if the specified url is a potential newsfeed; false otherwise

getHostUrl

public static String getHostUrl(String url)

Gets a valid url host String from the specified url, i.e. strips off everything besides the protocol and host from the given url.

Parameters:
url - the url to determine the host from
Returns:
a valid host url; null if an invalid url was specified

getDefaultBrowser

public static Program getDefaultBrowser()

Gets the Program used as default browser on the system.

Returns:
the Program used as default browser on the system; null if no default browser set