25
Thu, Apr
0 New Articles

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

$0.00 Raised:
$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • 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.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • 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

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • 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: