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