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