edu.neu.ccs.util
Class WebTools

java.lang.Object
  extended byedu.neu.ccs.util.WebTools

public class WebTools
extends Object

Class WebTools is a special purpose class for reading data from a web site.

Since:
2.3.3
Version:
2.3.3

Constructor Summary
private WebTools()
          Prevent instantiation.
 
Method Summary
static String appendSlashIfNeeded(String baseURL)
          Appends a slash to a URL string if it is not present.
static byte[] readDataFromWeb(String urlString)
          Returns the byte array of data from the web site item with the given URL string.
static String[] readFileNamesFromWeb(String filelistURL, String filelist)
          Returns the file names in the filelist text file located at the given filelist url.
static String[] readNonEmptyLinesFromWeb(String urlString)
          Returns the non-empty lines from the string contents of a web site text file with the given URL string.
static String readTextFileFromWeb(String urlString)
          Returns the string contents of a web site text file with the given URL string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebTools

private WebTools()
Prevent instantiation.

Method Detail

readDataFromWeb

public static byte[] readDataFromWeb(String urlString)

Returns the byte array of data from the web site item with the given URL string.

Assumes the data may be read in one call to the input stream reader associated with the URL.

Throws RuntimeException if an error occurs.

Parameters:
urlString - the URL of a web site item as a string
Returns:
the contents of the web site item as byte array data

readTextFileFromWeb

public static String readTextFileFromWeb(String urlString)

Returns the string contents of a web site text file with the given URL string.

Assumes the data may be read in one call to the input stream reader associated with the URL.

Throws RuntimeException if an error occurs.

Parameters:
urlString - the URL of a web site text file as a string
Returns:
the contents of the web site text file

readNonEmptyLinesFromWeb

public static String[] readNonEmptyLinesFromWeb(String urlString)

Returns the non-empty lines from the string contents of a web site text file with the given URL string.

Assumes the data may be read in one call to the input stream reader associated with the URL.

Throws RuntimeException if an error occurs.

Parameters:
urlString - the URL of a web site text file as a string
Returns:
the non-empty lines of the web site text file

readFileNamesFromWeb

public static String[] readFileNamesFromWeb(String filelistURL,
                                            String filelist)

Returns the file names in the filelist text file located at the given filelist url.

Appends slash to the filelist url string if it is not present.

Assumes that filelist is the name of a text file at the filelist url that contains a list of file names.

Assumes the data may be read in one call to the input stream reader associated with the URL.

If an error occurs, returns a zero-length string array rather than throw an exception.

Parameters:
filelistURL - the URL of a text file with file names
filelist - the name of a text file with file names
Returns:
the array of file names

appendSlashIfNeeded

public static String appendSlashIfNeeded(String baseURL)
Appends a slash to a URL string if it is not present.

Parameters:
baseURL - a URL string that may need a trailing slash
Returns:
the base URL with possibly a trailing slash appended