Chapter 3: Creating a File Download Application

The New Input/Output (NIO) API supports the java.nio and java.nio.channels packages for buffer management and advance I/O file system. The NIO API allows you to use the java.rmi package for file transfer across the Java Virtual Machine (JVM). The java.nio package contains the ByteBuffer classes, which you can use to store the content of a file. The java.nio.channels package provides the FileChannel class, which you can use to read and write the file. The java.rmi package provides remote interface to call the methods from the remote client.

This chapter explains how to develop a File Download application. The application uses the above-mentioned NIO and Remote Method Invocation (RMI) packages to download files from the remote machines.

Architecture of the File Download Application

The File Download application allows an end user to view a list of files stored at a specific location on the file server. The end user can select a file from the list and download it at the specified location.

The File Download application uses the following files:

  • : Creates a remote interface that declares the remote method for the application.

  • : Creates an implementation file that defines the remote methods declared in the remote interface.

  • : Creates a class that contains details, such as name , path , and size , of a particular file.

  • : Creates a file server that binds the remote objects to the RMI registry. As a result, a client can invoke the object from the remote location.

  • : Creates a user interface for the File Download application. The user interface helps an end user display a list of files stored in the file server in a tabular form. This interface also allows the end user to select and download a particular file.

  • : Creates a Download Status dialog box that contains a progress bar. The progress bar indicates the percentage of file that has been downloaded.

Figure 3-1 shows the architecture of the File Download application:

click to expand: this figure shows the various files used in the file download application and the sequence in which they are used.
Figure 3-1: Architecture of the File Download Application

In the File Download application, the file calls the file to invoke the remote methods to display a file list and download a specified file. The file calls the file, which finds and returns a list of files available at the specified location to the file. To download a particular file, the file reads and transfers that file to the client computer. The file implements the file, which creates a remote interface to declare the remote method. The file calls the file to store the file description. The file calls the file to open the Download Status dialog box.

Java InstantCode. Developing Applications Using Java NIO
Java InstantCode. Developing Applications Using Java NIO
Year: 2004
Pages: 55 © 2008-2017.
If you may any questions please contact us: