From 61209c439cde6d7908f340c78cfa988fe6775e56 Mon Sep 17 00:00:00 2001 From: giberta1 Date: Mon, 15 Apr 2002 10:46:14 +0000 Subject: [PATCH] Fix bad file name print-out, Improve exeption handling, Add BufferedInputStream support for file reading. --- MQSLoad.java | 164 ++++++++++++++++++++++++++++----------------------- 1 file changed, 90 insertions(+), 74 deletions(-) diff --git a/MQSLoad.java b/MQSLoad.java index 2229a4c..b5563a9 100644 --- a/MQSLoad.java +++ b/MQSLoad.java @@ -1,7 +1,7 @@ // $RCSfile: MQSLoad.java,v $ -// $Revision: 1.1 $ +// $Revision: 1.2 $ // $Name: $ -// $Date: 2001/07/12 09:57:24 $ +// $Date: 2002/04/15 10:46:14 $ // $Author: giberta1 $ /* @@ -51,31 +51,37 @@ public class MQSLoad - private void MQSInit() + private void MQSInit() throws Exception { try { QMng = new MQQueueManager( QMng_Name); System.out.println( "QManager Open: (" + QMng + ") !"); + } + + catch( Exception Expt) + { + throw Expt; + } + + try + { 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(); - } + + catch( Exception Expt) + { + QMng.disconnect(); + System.out.println( "QManager Close: (" + QMng + ") !"); + + throw Expt; + } } - private void MQSDeInit() + private void MQSDeInit() throws Exception { try { @@ -84,22 +90,16 @@ public class MQSLoad QMng.disconnect(); System.out.println( "QManager Close: (" + QMng + ") !"); } - - catch(MQException MQ_Expt) + + catch( Exception Expt) { - System.out.println( "MQ/Series Exception: (" + MQ_Expt + ") !"); - } - - catch(Exception Expt) - { - System.out.println( "JAVA IO Exception: (" + Expt + ") !"); - Expt.printStackTrace(); + throw Expt; } } - private void MQSPut_Msg( MQMessage Msg) + private void MQSPut_Msg( MQMessage Msg) throws Exception { try { @@ -107,15 +107,9 @@ public class MQSLoad MsgQ.put( Msg, pmo); } - catch( MQException MQ_Expt) + catch( Exception Expt) { - System.out.println( "MQ/Series Exception: (" + MQ_Expt + ") !"); - } - - catch(Exception Expt) - { - System.out.println( "JAVA IO Exception: (" + Expt + ") !"); - Expt.printStackTrace(); + throw Expt; } } @@ -123,13 +117,14 @@ public class MQSLoad public MQSLoad( String args[]) { - try - { - byte input_char; - int msg_nb = 0; - MQMessage output_msg = new MQMessage(); - - + byte input_char; + int msg_nb = 0; + MQMessage output_msg = new MQMessage(); + + + try + { + if( args.length != 2) { System.out.println( "Usage: MQSLoad "); @@ -141,44 +136,65 @@ public class MQSLoad MsgQ_Name = args[0]; File_Name = args[1]; - System.out.println( "Output MsgQueue Name: (" + File_Name + ") Input File Name: (" + File_Name + ")"); + System.out.println( "Output MsgQueue Name: (" + MsgQ_Name + ") Input File Name: (" + File_Name + ")"); MQSInit(); - output_msg.format = MQC.MQFMT_STRING; + try + { + output_msg.format = MQC.MQFMT_STRING; + + BufferedInputStream input_file = new BufferedInputStream( new FileInputStream(File_Name)); + + try + { + 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; + } + } + } + } + + catch( Exception Expt) + { + input_file.close(); + throw Expt; + } - 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; - } - } - } + input_file.close(); + } + + catch( Exception Expt) + { + MQSDeInit(); + throw Expt; + } MQSDeInit(); System.out.println( "MQS Load Completed !"); @@ -187,7 +203,7 @@ public class MQSLoad catch( Exception Expt) { - System.out.println("JAVA IO Exception: (" + Expt + ") !"); + System.out.println("Exception: (" + Expt + ") !"); Expt.printStackTrace(); } }