Compress AS/400 Files Using IFS Access

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

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, you’ll need to use either IBM’s Client Access product or the AS/400 NetServer and its access to the Windows Server Message Block. Once you’ve 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. I’ve 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 you’ve never tried to set up a NetServer mapped network drive over the Internet, then you’re in for a real headache when you do. While mapping a drive over the Internet using NetServer is possible, it’s 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 what’s 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:


• IFSFile—Used 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.

• IFSJavaFile—Used 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, there’s very little difference between these two classes.

• IFSFileInputStream—Used to read data from an AS/400 IFS object represented by either IFSFile or IFSJavaFile.

• IFSTextFileInputStream—Used 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.

• IFSFileOutputStream—Used to write data from Java to an AS/400 IFS object represented by either IFSFile or IFSJavaFile.

• IFSTextFileOutputStream—Used 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.

• IFSRandomAccessFile—Used to represent a file on the AS/400 for reading and writing AS/400 data. You’ll use this class to write data to files in a method much more reminiscent of the way you’d do it with any standard high-level language on the AS/400, such as RPG or COBOL.

• IFSFileDialog—Used to traverse the AS/400 IFS and allows you to select a file. You’ll 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 aren’t 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 don’t need any of the built-in functionality of the IBM-supplied AS/400 IFS classes. As always, it’ll 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, you’ll need a Java compiler such as the one that comes with the free Java Development Kit from Sun Microsystems. You’ll 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 IBM’s 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 toolkit’s Vaccess classes and some standard Java Swing components to present users with a list of objects they’ve 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, you’ll 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.

That’s 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. I’ve included several notes in the header section of the code that will help you bulletproof the application, and I’ve 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/400’s 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 what’s 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!


Compress_AS-_400_Files_Using_IFS_Access04-00.png 397x262

SHANNON ODONNELL
Shannon O'Donnell has held a variety of positions, most of them as a consultant, in dozens of industries. This breadth of experience gives him insight into multiple aspects of how the AS/400 is used in the real world. Shannon continues to work as a consultant. He is an IBM Certified Professional--AS/400 RPG Programmer and the author of an industry-leading certification test for RPG IV programmers available from ReviewNet.net.
 
BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: