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:

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

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

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

  • FileServer.java : 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.

  • FileClient.java : 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.

  • ProgressTest.java : 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 FileClient.java file calls the FileServer.java file to invoke the remote methods to display a file list and download a specified file. The FileServer.java file calls the FileRemoteImpl.java file, which finds and returns a list of files available at the specified location to the FileClient.java file. To download a particular file, the FileRemoteImpl.java file reads and transfers that file to the client computer. The FileRemoteImpl.java file implements the FileRemote.java file, which creates a remote interface to declare the remote method. The FileRemoteImpl.java file calls the FileInfo.java file to store the file description. The FileClient.java file calls the ProgressTest.java file to open the Download Status dialog box.




Java InstantCode. Developing Applications Using Java NIO
Java InstantCode. Developing Applications Using Java NIO
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 55

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net