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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20