As an AS/400 programmer, you know that the easiest way to access objects in the AS/400 Integrated File System (AS/400 IFS) from a Windows PC is to map a network drive. To do this, youll need to use either IBMs Client Access product or the AS/400 NetServer and its access to the Windows Server Message Block. Once youve mapped the network drive, you can then reference objects there as if they were on a local hard drive. While this method works fine for the most part, it does have its drawbacks. Chief among them is the instability mapping a network drive in Windows 9x/NT causes, especially using the Client Access for Windows product and its CWBBS.EXE Network mapping daemon. Ive had more Windows PCs lock up and crash because of this program running in the background than for any other reason.
While NetServer alleviates some of these problems, I find that it introduces certain problems of its own, namely, the enormous hassle you have to go through to get your PC setup to use the AS/400 NetServer (locally or over the Internet). NetServer requires that you make the Network Properties workgroup name match the name of your AS/400 NetServer instance. This is fine if you are not using the PC for any other network function needing its own unique workgroup name, but in a typical IT shop with multiple AS/400s and NT networks, that workgroup name is liable to be required for other legitimate reasons. You must also ensure that users are logged on to their PCs with a user profile and password that matches a valid AS/400 user profile and password. And if youve never tried to set up a NetServer mapped network drive over the Internet, then youre in for a real headache when you do. While mapping a drive over the Internet using NetServer is possible, its not exactly easy.
An Alternative to Client Access and NetServer
There is an alternative. You can use the Java AS/400 IFS Access classes to rather easily get to objects in the AS/400 IFS, whether your system is 2 feet away or halfway around the world. And whats even better, these classes are so easy to use that even if you only have a rudimentary understanding of Java, you can quickly write a program to take advantage of them.
The Java AS/400 IFS classes consist of the following:
IFSFileUsed to represent a file in the AS/400 IFS. Use this class to identify a file/object in the AS/400 IFS and then use the standard Java I/O write, read, create, delete, etc., methods to manipulate the object.
IFSJavaFileUsed much the same as the IFSFile class. The big difference between this class and the IFSFile class is that the IFSJavaFile class is optimized to use the standard java.io.File methods, whereas the IFSFile class is optimized more for the AS/400 IFS. Functionally, theres very little difference between these two classes.
IFSFileInputStreamUsed to read data from an AS/400 IFS object represented by either IFSFile or IFSJavaFile.
IFSTextFileInputStreamUsed to represent a stream of characters read from an AS/400 IFS file object. This class is used to convert AS/400 data from a given coded character set (CCSID) to Unicode.
IFSFileOutputStreamUsed to write data from Java to an AS/400 IFS object represented by either IFSFile or IFSJavaFile.
IFSTextFileOutputStreamUsed to represent a stream of character data being written to an AS/400 IFS file object. This class is used to convert Unicode data to another CCSID that can be understood by the AS/400.
IFSRandomAccessFileUsed to represent a file on the AS/400 for reading and writing AS/400 data. Youll use this class to write data to files in a method much more reminiscent of the way youd do it with any standard high-level language on the AS/400, such as RPG or COBOL.
IFSFileDialogUsed to traverse the AS/400 IFS and allows you to select a file. Youll use this class to prompt the user to select an AS/400 IFS object you want to work with.
Using the AS/400 IFS Access Classes
As you can see, there arent very many classes involved in accessing the AS/400 IFS via Java. And in fact, depending on what you want to do with the AS/400 IFS object, you may only need to use one or two of them anyway. And, truth be told, you can use the standard Java I/O classes to access the AS/400 IFS if you dont need any of the built-in functionality of the IBM-supplied AS/400 IFS classes. As always, itll depend on your particular needs. However, having said that, let me just say that using the AS/400 IFS access classes is extremely easy, as you can see by the example code shown in Figure 1. This simple Java application does nothing more than prompt users to log on to their AS/400 and build a list of AS/400 IFS objects starting in the /home directory, then writing to the standard output the name and path of the object selected. To try out this program, youll need a Java compiler such as the one that comes with the free Java Development Kit from Sun Microsystems. Youll also need to have the AS/400 Java Toolkit (jt400.jar) on your PC. You can either download this toolkit from your own AS/400 from the directory /QIBM/ProdData/HTTP/Public/jt400/lib, or you can download the open source version, JTOPEN, from IBMs Web site at www.as400. ibm.com/toolbox/.
The AS/400 Zip Tool
The code shown in Figure 1 is pretty basic, and, by itself, not that useful. In order to demonstrate the real power of the AS/400 IFS Access classes, I felt that something a little more useful, albeit complex, was needed. With that in mind, I wrote a utility called
ZipTool.java. ZipTool (Figure 2, on page 85) is a GUI-based Java application that allows a user to create standard Windows zip files made up of objects compressed from both the local (or networked) hard drive or the AS/400 IFS. ZipTool will also allow the user to unzip objects from any zip file to either a local drive (or networked drive) or the AS/400 IFS. And all without requiring a mapped network drive! Keep in mind, this is a PC-based tool that accesses your AS/400 and not a tool that runs on your AS/400.
ZipTool uses a combination of several AS/400 IFS Access classes along with some of the toolkits Vaccess classes and some standard Java Swing components to present users with a list of objects theyve compressed or zipped. To use this tool, compile it on your PC and then run the command Java zip tool. You can choose to create a new zip file (make sure to give the file name the extension of .zip) or open an existing zip file. You can add objects to a new zip file by clicking on the appropriate button. If you add local objects, you will be presented with the standard Java FileDialog panel. If you select the button to add AS/400 IFS objects, youll be presented with the IFSFileDialog panel. Select the object(s) you want to add and exit the application. The zip file can now be emailed to other users or placed on a Web site for downloading. If you open an existing zip file, you can choose to unzip the objects in it (one at a time or multiple selections) by clicking on the list entry to select it and then right clicking to select the destination (AS/400 IFS or local drive). If the AS/400 IFS is selected, ZipTool will build a list of directories using the AS/400 Java toolkit class, VIFSDirectory, and then display the list of directories in a standard Java tree pane. If the local drive is selected as the destination, a standard java JFileChooser panel is displayed to allow the user to select the local (or networked) directory to unzip the object(s) to.
Thats It!
Keep in mind that this is a demo version of this tool, so if you want to build on what I started, feel free. It would be fairly simple to provide support for zipping and unzipping of AS/400 Save Files and then distributing them as zip files to your remote sites, or even from your Web site. Ive included several notes in the header section of the code that will help you bulletproof the application, and Ive provided several suggestions for functional enhancements you might want to add to it. The main thing I wanted to demonstrate with this tool is how easy it is to access the AS/400 IFS without requiring you to use the error- prone Client Access for Windows CWBBS.EXE program or the AS/400s cumbersome NetServer. There are many more things you can do with the Java Access classes that free you from the limited functionality of the standard IBM utilities. Spend a little time exploring whats out there and let us know what you come up with!
REFERENCES AND RELATED MATERIALS
AS/400 Java Toolkit: www.as400.ibm.com/toolbox
Sun Microsystems: www.javasoft.com
//*********************************************
// To Compile: javac DemoIFSFileDialog.java
//*********************************************
import com.ibm.as400.access.*;
import com.ibm.as400.vaccess.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class DemoIFSFileDialog
{
public static void main (String[] args)
{
try
{
AS400 system = new AS400();
system.connectService(AS400.FILE);
try
{
Frame frame = new Frame(IFSFileDialog Demo);
IFSFileDialog fileDialog = new IFSFileDialog(frame, AS/400 IFS, system);
fileDialog.setDirectory(/home);
try
{
int pressed = fileDialog.showDialog();
if (pressed == IFSFileDialog.OK)
{
String Absolute_File_Path = fileDialog.getAbsolutePath();
System.out.println(File Selected is: + Absolute_File_Path);
}
else
if (pressed == IFSFileDialog.CANCEL)
{ System.out.println(User pressed cancel); }
}
catch(Exception ie){System.out.println(ie);}
}
catch(Exception ie){System.out.println(ie);}
}
catch(Exception ie){System.out.println(ie);}
System.exit(0);
}
}
Figure 1: This simple application allows you to select a file in the AS/400 IFS.
Figure 2: The ZipTool utility is an AS/400 and PC zip utility!
LATEST COMMENTS
MC Press Online