img
Understanding Internet Downloads
To understand and appreciate the Download Manager, it's necessary to shed some light on
how Internet downloads really work.
Internet downloads in their simplest form are merely client/server transactions. The
client, your browser, requests to download a file from a server on the Internet. The server
then responds by sending the requested file to your browser. In order for clients to communicate
with servers, they must have an established protocol for doing so. The most common protocols
for downloading files are File Transfer Protocol (FTP) and Hypertext Transfer Protocol (HTTP).
FTP is usually associated generically with exchanging files between computers, whereas
HTTP is usually associated specifically with transferring web pages and their related files
(that is, graphics, sounds, and so on). Over time, as the World Wide Web has grown in
popularity, HTTP has become the dominant protocol for downloading files from the Internet.
FTP is definitely not extinct, though.
For brevity's sake, the Download Manager developed in this chapter will only support
HTTP downloads. Nonetheless, adding support for FTP would be an excellent exercise
for extending the code. HTTP downloads come in two forms: resumable (HTTP 1.1) and
nonresumable (HTTP 1.0). The difference between these two forms lies in the way files can
be requested from servers. With the antiquated HTTP 1.0, a client can only request that a server
send it a file, whereas with HTTP 1.1, a client can request that a server send it a complete file or
only a specific portion of a file. This is the feature the Download Manager is built on.
An Over view of the Download Manager
The Download Manager uses a simple yet effective GUI interface built with Java's Swing
libraries. The Download Manager window is shown in Figure 33-1. The use of Swing gives
the interface a crisp, modern look and feel.
The GUI maintains a list of downloads that are currently being managed. Each download
in the list reports its URL, size of the file in bytes, progress as a percentage toward completion,
and current status. The downloads can each be in one of the following different states:
Downloading, Paused, Complete, Error, or Cancelled. The GUI also has controls for adding
downloads to the list and for changing the state of each download in the list. When a download
in the list is selected, depending on its current state, it can be paused, resumed, cancelled,
or removed from the list altogether.
The Download Manager is broken into a few classes for natural separation of functional
components. These are the Download, DownloadsTableModel, ProgressRenderer, and
DownloadManager classes, respectively. The DownloadManager class is responsible for the
GUI interface and makes use of the DownloadsTableModel and ProgressRenderer classes
for displaying the current list of downloads. The Download class represents a "managed"
download and is responsible for performing the actual downloading of a file. In the following
sections, we'll walk through each of these classes in detail, highlighting their inner workings
and explaining how they relate to each other.
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home