@@ -144,10 +144,8 @@ public static void main(String[] args) {
144144 }
145145
146146 for (String fileName : fileNames ) {
147- try {
148- FileInputStream in = new FileInputStream (fileName );
147+ try (FileInputStream in = new FileInputStream (fileName );) {
149148 preProcessedCommands .load (in );
150- in .close ();
151149 } catch (FileNotFoundException ex ) {
152150 System .out .println ("Can't find file " + fileName );
153151 System .exit (2 );
@@ -595,14 +593,17 @@ static void addDir(File dirObj, ZipOutputStream out) throws IOException {
595593 addDir (files [i ], out );
596594 continue ;
597595 }
598- FileInputStream in = new FileInputStream (files [i ].getPath ());
599- out .putNextEntry (new ZipEntry (files [i ].getPath ().substring (pathToDir .length ())));
600- int len ;
601- while ((len = in .read (tmpBuf )) > 0 ) {
602- out .write (tmpBuf , 0 , len );
596+ try (FileInputStream in = new FileInputStream (files [i ].getPath ());) {
597+ out .putNextEntry (new ZipEntry (files [i ].getPath ().substring (pathToDir .length ())));
598+ int len ;
599+ while ((len = in .read (tmpBuf )) > 0 ) {
600+ out .write (tmpBuf , 0 , len );
601+ }
602+ out .closeEntry ();
603+ }catch (IOException ex )
604+ {
605+ s_logger .error ("addDir:Exception:" + ex .getMessage (),ex );
603606 }
604- out .closeEntry ();
605- in .close ();
606607 }
607608 }
608609
@@ -619,16 +620,14 @@ private static void deleteDir(File dir) {
619620 private static void writeAlertTypes (String dirName ) {
620621 XStream xs = new XStream ();
621622 xs .alias ("alert" , Alert .class );
622- try {
623- ObjectOutputStream out = xs .createObjectOutputStream (new FileWriter (dirName + "/alert_types.xml" ), "alerts" );
623+ try (ObjectOutputStream out = xs .createObjectOutputStream (new FileWriter (dirName + "/alert_types.xml" ), "alerts" );) {
624624 for (Field f : AlertManager .class .getFields ()) {
625625 if (f .getClass ().isAssignableFrom (Number .class )) {
626626 String name = f .getName ().substring (11 );
627627 Alert alert = new Alert (name , f .getInt (null ));
628628 out .writeObject (alert );
629629 }
630630 }
631- out .close ();
632631 } catch (IOException e ) {
633632 s_logger .error ("Failed to create output stream to write an alert types " , e );
634633 } catch (IllegalAccessException e ) {
0 commit comments