com.ccg.net
Class URLCat

java.lang.Object
  extended by com.ccg.util.Convert
      extended by com.ccg.util.TagLookup
          extended by com.ccg.util.CommandLineUtility
              extended by com.ccg.net.URLCat
All Implemented Interfaces:
Lookup, Runnable
Direct Known Subclasses:
SerializedCat

public class URLCat
extends CommandLineUtility

Command line utility to fetch document data, status or info from a URL.

This utility is useful for determining information about a particular URL. In particular it is capable of displaying the following information:

General Information
General information about the URL specified, and some information about the client and server involved.
Header Information
Header information (modification times, et al) which the server is willing to provide for the URL specified.
Content
The actual contents (body) of the URL specified.

The command line arguments recognized are of the form:

 java com.ccg.net.URLCat -url URL [-info] [-header] [-body] \
    [-out FILE] [-useCache [true|false]] [-hex] [-flush [true|false]]
 
-url URL
This option is required. You use this to specify the document you want information on.
-info
This is optional, specify it if you want so see some general information abou the URL in question.
-header
This is optional, specify it if you want so see the "header" information the web server has for the URL in question.
-body
This is optional, specify it if you want so see the contents (body) of the URL in question. Note, this is the default selection if neither the "-info" or "-header" options are specified - you only need to specify it if you want more than one type of information in the same query.
-out FILE
You can use this if you'd like the output to be written to a file rather than the standard output.
-hex
Does a hex dump of data read (as opposed to the default ASCII)
-useCache [true|false]
Requests that we should try to use cached data if available (default is to disable the used of caches and try to fetch a fresh copy from the server).
-flush [true|false]
Flushes received data as soon as its received (you'll see it immediately on the console). Less efficient, but useful in diagnostic situations.
-k.0 NAME0 [-v.0 VAL0] [-k.1 NAME1 [-v.1 VAL1]...]
If you need to POST parameters to the HTTP server, you can specify the NAME/VALUE pairs using arguments in this form. The NAME and VALUES will be encoded in the proper form for passing to the server. For example, to pass: "name=Paul Blankenbaker" and "age=37", use:
 -k.0 name -v.0 "Paul Blankenbaker" -k.1 age -v.1 37
 

Some of the arguments recognized by the CommandLineUtility class can also be used (such as: "-args FILE").

Here are two sample usages, the first one retrieves the document "http://my.yahoo.com" and stores it in a file, the second gets just the header information, the third gets just the general information, and the fourth retreives ALL three in one shot:


 java com.ccg.net.URLCat -url "http://my.yahoo.com/" -out /tmp/my.html
 
 java com.ccg.net.URLCat -url "http://my.yahoo.com/" -header

 java com.ccg.net.URLCat -url "http://my.yahoo.com/" -info

 java com.ccg.net.URLCat -url "http://my.yahoo.com/" -info -header -body

 

Since:
1.0
Version:
$Revision: 1.8 $
Author:
$Author: pkb $

Constructor Summary
URLCat(String[] args)
          Constructs the object with a set of command line arguments.
 
Method Summary
 InputStream getURLInputStream()
          Fetch a InputStream to read data in from.
 boolean getUseCaches()
          Indicates whether we try to make use of HTTP cacheing.
 boolean isFlushEnabled()
          Is should we flush the output as soon as data is received and written set?
 boolean isHexDump()
          Will a hex dump of the content received be done?
static void main(String[] args)
          Main entry point into the application.
 void run()
          Does the actual reading and processing of the information.
 void setFlushEnabled(boolean val)
          Set should we flush the output as soon as data is received and written.
 void setHexDump(boolean val)
          Set whether we should do a hex instead of a ASCII dump.
 void setUseCaches(boolean val)
          Set should we enable the use of HTTP caches?
 
Methods inherited from class com.ccg.util.CommandLineUtility
getFiles, getInputStream, getLineNumberReader, getOutputStream, getPrintWriter, getStrings, setInputStream, setOutputStream
 
Methods inherited from class com.ccg.util.TagLookup
get, getBoolean, getChoice, getColor, getDate, getDate, getFont, getIndexedList, getInputStream, getLocale, getLookup, getNumber, getNumber, getOutputStream, getString, getString, getStrings, getTag, getTimeSpan, getTimeSpan, setLookup, setTag
 
Methods inherited from class com.ccg.util.Convert
choiceValue, getDateFormat, getNumberFormat, setDateFormat, setNumberFormat, toBoolean, toColor, toDate, toFont, toInputStream, toLocale, toNumber, toOutputStream, toString, toTimeSpan
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

URLCat

public URLCat(String[] args)
Constructs the object with a set of command line arguments.

This method constructs a new URLCat object and initializes with a array of string values which are treated as command line arguments. The command line arguments are processed (as specified in the class overview and parent class).

Parameters:
args - Array of command line arguments.
Since:
1.0
Method Detail

setFlushEnabled

public void setFlushEnabled(boolean val)
Set should we flush the output as soon as data is received and written.

Parameters:
val - New boolean value to assign.
See Also:
isFlushEnabled()

isFlushEnabled

public boolean isFlushEnabled()
Is should we flush the output as soon as data is received and written set?

Returns:
Current boolean value assigned.
See Also:
setFlushEnabled(boolean)

getURLInputStream

public InputStream getURLInputStream()
                              throws IOException
Fetch a InputStream to read data in from.

This method will open the connection to the desired URL and POST any arguments (if necessary). It will then return a InputStream which one may read the data returned from the server.

Note, the POST method will be used if the NAME/VALUE pairs are specified on the command line (as indicated in the class overview). If no NAME/VALUE pairs are specified, then the standard GET will be used to retrieve the information.

Returns:
InputStream to read the data from.
Throws:
IOException - If there is a problem establishing the connection.
Since:
1.0
See Also:
run()

run

public void run()
Does the actual reading and processing of the information.

This method is responsible for the actual reading and processing of information related to the URL in question. It will do one or more of the following (depending upon the command line arguments specified - see the class overview for more details about the supported command line arguments):


setUseCaches

public void setUseCaches(boolean val)
Set should we enable the use of HTTP caches?

Parameters:
val - New boolean value to assign. see #getUseCaches

getUseCaches

public boolean getUseCaches()
Indicates whether we try to make use of HTTP cacheing.

Returns:
Current boolean value assigned. see #setUseCaches

setHexDump

public void setHexDump(boolean val)
Set whether we should do a hex instead of a ASCII dump.

Parameters:
val - New boolean value to assign. see #getHexDump

isHexDump

public boolean isHexDump()
Will a hex dump of the content received be done?

Returns:
Current boolean value assigned. see #setHexDump

main

public static void main(String[] args)
Main entry point into the application.

Simply constructs the object and passes control to the run() method.

Parameters:
args - Array of command line arguments.


Copyright 1998-1998-2006 null. All Rights Reserved.