The complete PeopleCode example to extract a TAR file in PeopleSoft using PeopleCode is shown below.
/* Extract TAR Files in PeopleCode - Example */
Local JavaObject &TarFileReader = CreateJavaObject("org.xeustechnologies.jtar.TarInputStream", CreateJavaObject("java.io.FileInputStream", "c:\temp\myTarFile.tar"));
Local JavaObject &TarEntry;
Local JavaObject &ByteBufferArray = CreateJavaArray("byte[]", 1024);
Local number &NumberOfBytes;
/* Create all directories first */
While True
&TarEntry = &TarFileReader.getNextEntry();
If &TarEntry = Null Then
Break;
Else
If (&TarEntry.isDirectory()) Then
Local JavaObject &dir = CreateJavaObject("java.io.File", "c:\temp\" | &TarEntry.getName());
Local boolean &b = &dir.mkdir();
End-If;
End-If;
End-While;
&TarFileReader.close();
/* Now we handle files */
&TarFileReader = CreateJavaObject("org.xeustechnologies.jtar.TarInputStream", CreateJavaObject("java.io.FileInputStream", "c:\temp\myTarFile.tar"));
While True
&TarEntry = &TarFileReader.getNextEntry();
If &TarEntry = Null Then
Break;
Else
If (&TarEntry.isDirectory()) Then
/* do nothing */
Else
Local JavaObject &out = CreateJavaObject("java.io.FileOutputStream", "c:\temp\" | &TarEntry.getName(), True);
&NumberOfBytes = &TarFileReader.read(&ByteBufferArray);
While &NumberOfBytes > 0
&out.write(&ByteBufferArray, 0, &NumberOfBytes);
&NumberOfBytes = &TarFileReader.read(&ByteBufferArray);
End-While;
End-If;
End-If;
End-While;
&TarFileReader.close();
You can easily insert this code into an AE program in PeopleSoft. You can even wrap this into a function / method and reuse it as many times as you want.
No comments:
Post a Comment