Joe,
Here's the code...ZipIFSFolder.java
package com.nal.eReqs;
import java.io.*;
import java.util.zip.*;
import com.ibm.as400.access.AS400;
import com.ibm.as400.access.IFSFile;
import com.ibm.as400.access.IFSFileInputStream;
import com.ibm.as400.access.AS400SecurityException;
public class ZipIFSFolder {
public static void ZipFolder(String eReq)
throws IOException {
// Create a buffer for reading the files
byte[] buf = new byte[2147483647];
byte[] buffer = new byte[2147483647];
String filenames[] = new String[500];
AS400 erq400 = new AS400("server","username","password");
String inFilename = "/eReqs/attachments/archivei.zip";
String outFilename = "/eReqs/attachments/archiveo.zip";
//for reading from the existing zip
ZipInputStream in = new ZipInputStream(new
FileInputStream(inFilename));
// Create the ZIP file
ZipOutputStream out = new ZipOutputStream(new
FileOutputStream(outFilename));
try {
// retrieve contents of IFS folder
String directory = new String("/eReqs/attachments/" + eReq.trim()
+ "/");
IFSFile file = new IFSFile(erq400, directory);
try {
if (file.exists()) {
IFSFile files[] = file.listFiles();
// These are the files to include in the ZIP file
filenames = new String[files.length];
for (int j = 0; j < files.length; j++) {
if (files[j] != null) {
if (files[j].isFile())
filenames[j] = directory.trim() +
files[j].getName();
}
}
} else {
filenames = new String[500];
}
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
try {
ZipEntry one;
ZipEntry two;
int count;
// rewrite zip entries from old zip file
while ((one = in.getNextEntry()) != null) {
two = new ZipEntry(one.getName());
out.putNextEntry(two);
while ((count = in.read(buffer)) > 0) {
out.write(buffer, 0, count);
}
}
// Compress the new files
for (int i=0; i<filenames.length; i++) {
IFSFileInputStream inFile = new IFSFileInputStream(erq400,
filenames[i]);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(filenames[i]));
System.out.println("Processing: " + filenames[i]);
// Transfer bytes from the file to the ZIP file
int len;
while ((len = inFile.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
inFile.close();
}
// Complete the ZIP file
out.close();
} catch (AS400SecurityException e4) {
System.out.println("Error: " + e4.getMessage());
e4.printStackTrace();
}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
erq400.disconnectAllServices();
}
public static void main(String args[]) {
try {
if (args[0] != null) {
ZipFolder(args[0]);
} else {
ZipFolder("105373");
}
} catch (IOException e) {
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
}
Shane Cessna
Senior iSeries Programmer
North American Lighting, Inc.
217.465.6600 x7776
"Joe Sam Shirah" <joe_sam@xxxxxxxxxxxxx>
Sent by: java400-l-bounces@xxxxxxxxxxxx
06/11/2007 02:13 PM
Please respond to
Java Programming on and around the iSeries / AS400
<java400-l@xxxxxxxxxxxx>
To
"Java Programming on and around the iSeries / AS400"
<java400-l@xxxxxxxxxxxx>
cc
Subject
Re: length of time a java pgm runs in batch...
Hi Shane,
There's no time limit differences between batch and interactive. Ask
yourself the same question for, say, an RPG or CL program, and you'll get
the same answer in terms of basic system operation.
Hard to say what the problem is without seeing the code, but I
wouldn't
be surprised if it's a directory problem. If the timing is similar, the
output may not be where you expect it. That's a complete crystal ball
guess, and likely has the same level of reliability. You probably need to
send more detail to get a good answer.
Joe Sam
Joe Sam Shirah -
http://www.conceptgo.com
conceptGO - Consulting/Development/Outsourcing
Java Filter Forum:
http://www.ibm.com/developerworks/java/
Just the JDBC FAQs:
http://www.jguru.com/faq/JDBC
Going International?
http://www.jguru.com/faq/I18N
Que Java400?
http://www.jguru.com/faq/Java400
----- Original Message -----
From: <Shane_Cessna@xxxxxxx>
To: <java400-l@xxxxxxxxxxxx>
Sent: Monday, June 11, 2007 2:56 PM
Subject: length of time a java pgm runs in batch...
All:
I have a java program that is taking files from the IFS and putting them
in a zip file...if I run this interactively under QSH, it runs fine...it
takes a while, but it runs fine and does what I want it to do...However,
if I run this in batch, it says that it completes normally, but the
program doesn't zip up the files...it runs a while too but just doesn't
act like it wants to do what I tell it. Is there some limit on how long
a
Java program can run in batch as opposed to interactively? If so, what
can I change so that my program will run in batch?
Shane Cessna
Senior iSeries Programmer
North American Lighting, Inc.
217.465.6600 x7776
--
This is the Java Programming on and around the iSeries / AS400
(JAVA400-L)
mailing list
To post a message email: JAVA400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/java400-l.
As an Amazon Associate we earn from qualifying purchases.