From b016367fbb7f8c6f1909c19c1726a4faa2786196 Mon Sep 17 00:00:00 2001 From: giberta1 Date: Thu, 12 Jul 2001 09:57:24 +0000 Subject: [PATCH] Create this file ! Initial MQSLoad version. --- MQSLoad.java | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 MQSLoad.java diff --git a/MQSLoad.java b/MQSLoad.java new file mode 100644 index 0000000..2229a4c --- /dev/null +++ b/MQSLoad.java @@ -0,0 +1,195 @@ +// $RCSfile: MQSLoad.java,v $ +// $Revision: 1.1 $ +// $Name: $ +// $Date: 2001/07/12 09:57:24 $ +// $Author: giberta1 $ + +/* + * 07/12/2001 - 11:45:14 + * + * MQSLoad.java - MQ/Seires data file to queue loader + * Copyright (C) 2001 Arnaud G. Gibert + * arnaud.gibert@midas-kapiti.fr + * www.midas-kapiti.fr + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +import com.ibm.mq.*; +import java.io.*; + + + + + +public class MQSLoad +{ + private MQQueueManager QMng; + private String QMng_Name = ""; + private MQQueue MsgQ; + private String MsgQ_Name; + private int MsgQ_Open_Options = MQC.MQOO_OUTPUT | MQC.MQOO_FAIL_IF_QUIESCING; + private String File_Name; + + + public static void main( String args[]) + { + new MQSLoad( args); + } + + + + private void MQSInit() + { + try + { + QMng = new MQQueueManager( QMng_Name); + System.out.println( "QManager Open: (" + QMng + ") !"); + MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null); + System.out.println( "MsgQ Open: (" + MsgQ + ") !"); + } + + catch(MQException MQ_Expt) + { + System.out.println( "MQ/Series Exception: (" + MQ_Expt + ") !"); + } + + catch(Exception Expt) + { + System.out.println( "JAVA IO Exception: (" + Expt + ") !"); + Expt.printStackTrace(); + } + } + + + + private void MQSDeInit() + { + try + { + MsgQ.close(); + System.out.println( "MsgQ Close: (" + MsgQ + ") !"); + QMng.disconnect(); + System.out.println( "QManager Close: (" + QMng + ") !"); + } + + catch(MQException MQ_Expt) + { + System.out.println( "MQ/Series Exception: (" + MQ_Expt + ") !"); + } + + catch(Exception Expt) + { + System.out.println( "JAVA IO Exception: (" + Expt + ") !"); + Expt.printStackTrace(); + } + } + + + + private void MQSPut_Msg( MQMessage Msg) + { + try + { + MQPutMessageOptions pmo = new MQPutMessageOptions(); + MsgQ.put( Msg, pmo); + } + + catch( MQException MQ_Expt) + { + System.out.println( "MQ/Series Exception: (" + MQ_Expt + ") !"); + } + + catch(Exception Expt) + { + System.out.println( "JAVA IO Exception: (" + Expt + ") !"); + Expt.printStackTrace(); + } + } + + + + public MQSLoad( String args[]) + { + try + { + byte input_char; + int msg_nb = 0; + MQMessage output_msg = new MQMessage(); + + + if( args.length != 2) + { + System.out.println( "Usage: MQSLoad "); + } + else + { + System.out.println( "MQS Load Starting..."); + + MsgQ_Name = args[0]; + File_Name = args[1]; + + System.out.println( "Output MsgQueue Name: (" + File_Name + ") Input File Name: (" + File_Name + ")"); + + + MQSInit(); + + output_msg.format = MQC.MQFMT_STRING; + + InputStream input_file = new FileInputStream(File_Name); + System.out.println("Input File Open: (" + input_file + ") !"); + + while( ( input_char = (byte)input_file.read()) != -1) + { + switch( input_char) + { + case '\r': + case ';': + { + break; + } + + case '\n': + { + System.out.println( "Sending Msg Nb (" + ++msg_nb + ") !"); + + output_msg.messageId = MQC.MQMI_NONE; + MQSPut_Msg(output_msg); + output_msg.clearMessage(); + + break; + } + + default: + { + output_msg.writeByte( input_char); + break; + } + } + } + + MQSDeInit(); + System.out.println( "MQS Load Completed !"); + } + } + + catch( Exception Expt) + { + System.out.println("JAVA IO Exception: (" + Expt + ") !"); + Expt.printStackTrace(); + } + } +} +