--- miscJava/thn_mqutils/src/com/traiana/utils/mq/MqFilesSender.java 2013/05/10 09:16:32 1980 +++ miscJava/thn_mqutils/src/com/traiana/utils/mq/MqFilesSender.java 2013/05/10 09:45:55 1981 @@ -1,65 +1,64 @@ -/* */ 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()); -/* */ } -/* */ } -/* */ } +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; + + +public class MqFilesSender +{ + public static void main(String[] args) + { + if (args.length < 6) { + System.out.println("usage: java com.traiana.utils.mq.MqFilesSender [qmgr] [port] [mqServerName] [channelName] [queueName] [file or directory] {optional ccsid} {debug}"); + return; + } + MQ sender = null; + try { + int ccsid = args.length >= 7 ? Integer.parseInt(args[6]) : 0; + boolean debug = args.length == 8 ? Boolean.valueOf(args[7]).booleanValue() : false; + sender = new MQ(args[0], Integer.parseInt(args[1]), args[2], args[3], ccsid, debug); + sender.InitQueue(args[4]); + File source = new File(args[5]); + if (source.isDirectory()) { + File[] files = source.listFiles(); + for (File file : files) { + sendFileToQueue(file, sender); + } + } else { + sendFileToQueue(source, sender); + } + } catch (MQException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (sender != null) + try { + sender.close(); + } catch (MQException e) { + e.printStackTrace(); + } + } + } + + private static void sendFileToQueue(File file, MQ sender) throws IOException, MQException { + if (file.isFile()) { + System.out.println("writting file: " + file.getName() + " to queue."); + FileInputStream in = new FileInputStream(file); + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(in.available()); + byte[] buff = new byte[10000]; + int length; + while ((length = in.read(buff)) != -1) { + byteOut.write(buff, 0, length); + } + byteOut.flush(); + sender.sendToQueue(byteOut.toByteArray()); + } + } +} /* Location: C:\Users\thn\workspace\mq-utils.jar * Qualified Name: com.traiana.utils.mq.MqFilesSender