/[projects]/miscJava/thn_mqutils/src/main/java/com/traiana/utils/mq/MqFilesSender.java
ViewVC logotype

Annotation of /miscJava/thn_mqutils/src/main/java/com/traiana/utils/mq/MqFilesSender.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2738 - (hide annotations) (download)
Fri Oct 2 10:14:15 2015 UTC (8 years, 8 months ago) by torben
File size: 1983 byte(s)
use maven to build this
1 torben 1981 package com.traiana.utils.mq;
2 torben 1980
3 torben 1981 import com.ibm.mq.MQException;
4     import java.io.ByteArrayOutputStream;
5     import java.io.File;
6     import java.io.FileInputStream;
7     import java.io.IOException;
8    
9    
10     public class MqFilesSender
11     {
12     public static void main(String[] args)
13     {
14     if (args.length < 6) {
15     System.out.println("usage: java com.traiana.utils.mq.MqFilesSender [qmgr] [port] [mqServerName] [channelName] [queueName] [file or directory] {optional ccsid} {debug}");
16     return;
17     }
18     MQ sender = null;
19     try {
20     int ccsid = args.length >= 7 ? Integer.parseInt(args[6]) : 0;
21     boolean debug = args.length == 8 ? Boolean.valueOf(args[7]).booleanValue() : false;
22     sender = new MQ(args[0], Integer.parseInt(args[1]), args[2], args[3], ccsid, debug);
23     sender.InitQueue(args[4]);
24     File source = new File(args[5]);
25     if (source.isDirectory()) {
26     File[] files = source.listFiles();
27     for (File file : files) {
28     sendFileToQueue(file, sender);
29     }
30     } else {
31     sendFileToQueue(source, sender);
32     }
33     } catch (MQException e) {
34     e.printStackTrace();
35     } catch (IOException e) {
36     e.printStackTrace();
37     } finally {
38     if (sender != null)
39     try {
40     sender.close();
41     } catch (MQException e) {
42     e.printStackTrace();
43     }
44     }
45     }
46    
47     private static void sendFileToQueue(File file, MQ sender) throws IOException, MQException {
48     if (file.isFile()) {
49     System.out.println("writting file: " + file.getName() + " to queue.");
50     FileInputStream in = new FileInputStream(file);
51     ByteArrayOutputStream byteOut = new ByteArrayOutputStream(in.available());
52     byte[] buff = new byte[10000];
53     int length;
54     while ((length = in.read(buff)) != -1) {
55     byteOut.write(buff, 0, length);
56     }
57     byteOut.flush();
58     sender.sendToQueue(byteOut.toByteArray());
59     }
60     }
61     }
62    
63 torben 1980 /* Location: C:\Users\thn\workspace\mq-utils.jar
64     * Qualified Name: com.traiana.utils.mq.MqFilesSender
65     * JD-Core Version: 0.6.2
66     */

  ViewVC Help
Powered by ViewVC 1.1.20