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 (Exception 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 * JD-Core Version: 0.6.2 */