mqsload/MQSLoad.java
giberta1 b016367fbb Create this file !
Initial MQSLoad version.
2001-07-12 09:57:24 +00:00

196 lines
7.0 KiB
Java

// $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 <Output_MsgQueue_Name> <Input_File_Name>");
}
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();
}
}
}