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 $ // $RCSfile: MQSLoad.java,v $
// $Revision: 1.1 $ // $Revision: 1.2 $
// $Name: $ // $Name: $
// $Date: 2001/07/12 09:57:24 $ // $Date: 2002/04/15 10:46:14 $
// $Author: giberta1 $ // $Author: giberta1 $
/* /*
@ -51,31 +51,37 @@ public class MQSLoad
private void MQSInit() private void MQSInit() throws Exception
{ {
try try
{ {
QMng = new MQQueueManager( QMng_Name); QMng = new MQQueueManager( QMng_Name);
System.out.println( "QManager Open: (" + QMng + ") !"); System.out.println( "QManager Open: (" + QMng + ") !");
}
catch( Exception Expt)
{
throw Expt;
}
try
{
MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null); MsgQ = QMng.accessQueue( MsgQ_Name, MsgQ_Open_Options, null, null, null);
System.out.println( "MsgQ Open: (" + MsgQ + ") !"); 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) throw Expt;
{ }
System.out.println( "JAVA IO Exception: (" + Expt + ") !");
Expt.printStackTrace();
}
} }
private void MQSDeInit() private void MQSDeInit() throws Exception
{ {
try try
{ {
@ -84,22 +90,16 @@ public class MQSLoad
QMng.disconnect(); QMng.disconnect();
System.out.println( "QManager Close: (" + QMng + ") !"); System.out.println( "QManager Close: (" + QMng + ") !");
} }
catch(MQException MQ_Expt) catch( Exception Expt)
{ {
System.out.println( "MQ/Series Exception: (" + MQ_Expt + ") !"); throw Expt;
}
catch(Exception Expt)
{
System.out.println( "JAVA IO Exception: (" + Expt + ") !");
Expt.printStackTrace();
} }
} }
private void MQSPut_Msg( MQMessage Msg) private void MQSPut_Msg( MQMessage Msg) throws Exception
{ {
try try
{ {
@ -107,15 +107,9 @@ public class MQSLoad
MsgQ.put( Msg, pmo); MsgQ.put( Msg, pmo);
} }
catch( MQException MQ_Expt) catch( Exception Expt)
{ {
System.out.println( "MQ/Series Exception: (" + MQ_Expt + ") !"); throw Expt;
}
catch(Exception Expt)
{
System.out.println( "JAVA IO Exception: (" + Expt + ") !");
Expt.printStackTrace();
} }
} }
@ -123,13 +117,14 @@ public class MQSLoad
public MQSLoad( String args[]) public MQSLoad( String args[])
{ {
try byte input_char;
{ int msg_nb = 0;
byte input_char; MQMessage output_msg = new MQMessage();
int msg_nb = 0;
MQMessage output_msg = new MQMessage();
try
{
if( args.length != 2) if( args.length != 2)
{ {
System.out.println( "Usage: MQSLoad <Output_MsgQueue_Name> <Input_File_Name>"); System.out.println( "Usage: MQSLoad <Output_MsgQueue_Name> <Input_File_Name>");
@ -141,44 +136,65 @@ public class MQSLoad
MsgQ_Name = args[0]; MsgQ_Name = args[0];
File_Name = args[1]; 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(); 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); input_file.close();
System.out.println("Input File Open: (" + input_file + ") !"); }
while( ( input_char = (byte)input_file.read()) != -1) catch( Exception Expt)
{ {
switch( input_char) MQSDeInit();
{ throw Expt;
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(); MQSDeInit();
System.out.println( "MQS Load Completed !"); System.out.println( "MQS Load Completed !");
@ -187,7 +203,7 @@ public class MQSLoad
catch( Exception Expt) catch( Exception Expt)
{ {
System.out.println("JAVA IO Exception: (" + Expt + ") !"); System.out.println("Exception: (" + Expt + ") !");
Expt.printStackTrace(); Expt.printStackTrace();
} }
} }