Fix bad file name print-out,

Improve exeption handling,
Add BufferedInputStream support for file reading.
This commit is contained in:
giberta1 2002-04-15 10:46:14 +00:00
parent 271c6a6f9e
commit 61209c439c

View File

@ -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)
catch( Exception Expt)
{
System.out.println( "MQ/Series Exception: (" + MQ_Expt + ") !");
}
QMng.disconnect();
System.out.println( "QManager Close: (" + QMng + ") !");
catch(Exception Expt)
{
System.out.println( "JAVA IO Exception: (" + Expt + ") !");
Expt.printStackTrace();
}
throw Expt;
}
}
private void MQSDeInit()
private void MQSDeInit() throws Exception
{
try
{
@ -85,21 +91,15 @@ public class MQSLoad
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 <Output_MsgQueue_Name> <Input_File_Name>");
@ -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;
InputStream input_file = new FileInputStream(File_Name);
System.out.println("Input File Open: (" + input_file + ") !");
BufferedInputStream input_file = new BufferedInputStream( new FileInputStream(File_Name));
while( ( input_char = (byte)input_file.read()) != -1)
{
switch( input_char)
{
case '\r':
case ';':
{
break;
}
try
{
System.out.println("Input File Open: (" + input_file + ") !");
case '\n':
{
System.out.println( "Sending Msg Nb (" + ++msg_nb + ") !");
while( ( input_char = (byte)input_file.read()) != -1)
{
switch( input_char)
{
case '\r':
case ';':
{
break;
}
output_msg.messageId = MQC.MQMI_NONE;
MQSPut_Msg(output_msg);
output_msg.clearMessage();
case '\n':
{
System.out.println( "Sending Msg Nb (" + ++msg_nb + ") !");
break;
}
output_msg.messageId = MQC.MQMI_NONE;
MQSPut_Msg(output_msg);
output_msg.clearMessage();
default:
{
output_msg.writeByte( input_char);
break;
}
}
}
break;
}
default:
{
output_msg.writeByte( input_char);
break;
}
}
}
}
catch( Exception Expt)
{
input_file.close();
throw Expt;
}
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();
}
}