|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Unzip using JCN |
« View previous topic :: View next topic » |
Author |
Message
|
richdad |
Posted: Mon Jan 09, 2023 10:31 am Post subject: Unzip using JCN |
|
|
Newbie
Joined: 09 Jan 2023 Posts: 2
|
Hi ,
i have a requirement that the server will send zip files to my queue , from there i need to unzip the contents using jcn and proceed.
I am new to JCN node. can someone help me with sample JCN code.
Thanks. |
|
Back to top |
|
 |
bruce2359 |
Posted: Mon Jan 09, 2023 10:39 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
Moved to Broker forum. _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
 |
richdad |
Posted: Mon Jan 09, 2023 10:45 am Post subject: |
|
|
Newbie
Joined: 09 Jan 2023 Posts: 2
|
|
Back to top |
|
 |
axeleli12 |
Posted: Sun Mar 05, 2023 3:09 am Post subject: |
|
|
Newbie
Joined: 10 Dec 2022 Posts: 2
|
Sure, I can help you with a sample JCN code to unzip a file. Here's an example:
Code: |
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import com.jcn.client.JCN;
public class UnzipFile {
public static void main(String[] args) throws IOException {
JCN jcn = new JCN();
// Connect to the queue
jcn.connect("your-queue-name", "your-queue-password");
// Get the message from the queue
String message = jcn.getMessage();
// Get the zip file as a byte array
byte[] zipFileBytes = message.getBytes();
// Create a new ZipInputStream
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(zipFileBytes));
// Loop through all the entries in the zip file
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
// Get the file name
String fileName = zipEntry.getName();
// Create a new file with the same name
File newFile = new File(fileName);
// Create the file's parent directories if they don't exist
if (!newFile.getParentFile().exists()) {
newFile.getParentFile().mkdirs();
}
// Create a new FileOutputStream
FileOutputStream fos = new FileOutputStream(newFile);
// Read from the ZipInputStream and write to the FileOutputStream
byte[] buffer = new byte[1024];
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
// Close the FileOutputStream
fos.close();
// Get the next entry in the zip file
zipEntry = zis.getNextEntry();
}
// Close the ZipInputStream
zis.close();
// Disconnect from the queue
jcn.disconnect();
}
} |
This code uses the JCN client library to connect to a queue, get a message, and then unzip the contents of the message. You'll need to replace "your-queue-name" and "your-queue-password" with the actual name and password of your queue. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|