Download A Softbot for the World Wide Web

Transcript
4.7 By-products
65
4.7.2 The Whatsit? tool
In this section, I will describe a simple tool called whatsit? which analyzes dierent graphics le formats used on the World Wide Web.
Given a list of URLs or local les the Whatsit? loads the specied images, checks the signature, in order to nd out the format13 and according to that, it parses the le content,
in order to nd parameters for width, height and depth of the image. While developing
the Personal Picture Finder, I revised several newsgroups for Java developers to nd out
if such a tool is already in existance and publicly available. Coming across a great variety of similar requests, but no answers I decided to publish my implementation in the
appendix of this thesis (see appendix A.2.4). Due to its object oriented design, the API
can be reused for a variety of other applications, especially to enable agents living on the
internet to automatically nd out what kind of data14 they are dealing with15.
Using the list of les or URLs given in the command line, whatsit? loads them sequentially, checks the header signature and parses the les depending on their format in order
to nd out width, height and depth of the image.
Example:16
$ java whatsit /home/endres/pictures/ana.gif \
http://rimbaud/gif/apache_logo.gif \
Photo.jpg
/home/endres/pictures/ana.gif:
GIF 87a, 546x536x8, 132490 bytes.
http://rimbaud/gif/apache_logo.gif: GIF 89a, 400x148x8, 23439 bytes.
Photo.jpg:
JPG 1.01, 493x373x24, 112556 bytes.
$
Let us take a closer look at the program code. After importing the packages java.io (for
I/O operations like accessing les from the local le system), java.net (for establishing
connections to the WWW) and endres.graph (for analyzing graphics le formats17), the
denition of class whatsit follows. As an application it needs a main-method. This main
method checks the command line parameters and sequentially creates a new instance of
the whatsit-class for every parameter. The constructor of this class then reads the le via
the readle()-method and in case the le is accessible, it executes the checkFile()-method.
readle() checks if the given parameter describes a URL or the name of a le on the
local le system and then opens an according DataInputStream and reads the le in a
Especially when working on heterogenous sources like the WWW one should not assume that every
le is what it seems to be according to its extensions. GIFs with a .jpg-extension or vice versa occur and
usually are displayed properly on common browsers.
14 An older version of whatsit? recognized some more le formats used on the web, like java classes
or postscript documents. The code example described in this thesis is restricted to graphics le formats
only.
15 For example a spider or crawler has to know whether the link he follows leads to another webpage
or to another le, like for instance a postscript document.
16 Java is platform independent. I assume a UNIX shell for this example. One might as well execute it
on any other platform.
17 The package endres.graph is explained in detail in the next section.
13