Author: centic
Date: Fri Sep 22 21:16:09 2017
New Revision: 1809354

URL: http://svn.apache.org/viewvc?rev=1809354&view=rev
Log:
Adjust many examples for Java 8: try-with-resource, multi-catch and other code 
cleanup.

Modified:
    
poi/trunk/src/examples/src/org/apache/poi/crypt/examples/OOXMLPasswordsTry.java
    poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java
    poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java
    
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java
    poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteTitle.java
    poi/trunk/src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java
    poi/trunk/src/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java
    poi/trunk/src/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java
    poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java
    poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java
    
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java
    poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java
    poi/trunk/src/examples/src/org/apache/poi/hslf/examples/SoundFinder.java
    poi/trunk/src/examples/src/org/apache/poi/hslf/examples/TableDemo.java
    poi/trunk/src/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Alignment.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateCells.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateDateCells.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EventExample.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/MergedCells.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/NewLinesInCells.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/NewSheet.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/NewWorkbook.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawing.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/OfficeDrawingWithGraphics.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Outlines.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/ReadWriteWorkbook.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/RepeatingRowsAndColumns.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/SplitAndFreezePanes.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/WorkingWithFonts.java
    
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/ZoomSheet.java
    poi/trunk/src/examples/src/org/apache/poi/hwpf/Word2Forrest.java
    poi/trunk/src/examples/src/org/apache/poi/ss/examples/AligningCells.java
    poi/trunk/src/examples/src/org/apache/poi/ss/examples/CalendarDemo.java
    poi/trunk/src/examples/src/org/apache/poi/ss/examples/CellStyleDetails.java
    
poi/trunk/src/examples/src/org/apache/poi/ss/examples/formula/SettingExternalFunction.java
    
poi/trunk/src/examples/src/org/apache/poi/ss/examples/formula/UserDefinedFunctionExample.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/DataExtraction.java
    
poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/MergePresentations.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial1.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial2.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial3.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial4.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial5.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial6.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/Tutorial7.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step1.java
    poi/trunk/src/examples/src/org/apache/poi/xslf/usermodel/tutorial/Step2.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/eventusermodel/examples/FromHowTo.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/streaming/examples/Outlining.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/AligningCells.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/BigGridDemo.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CalendarDemo.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CellComments.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreatePivotTable.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreatePivotTable2.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateTable.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateUserDefinedDataFormats.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/CustomXMLMapping.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/EmbeddedObjects.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/FitSheetToOnePage.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/HeadersAndFooters.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/HyperlinkExample.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/IterateCells.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/LineChart.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/NewLinesInCells.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/Outlining.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ScatterChart.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/SelectedSheet.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/ShiftRows.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/SplitAndFreezePanes.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkbookProperties.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithBorders.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithPageSetup.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithPictures.java
    
poi/trunk/src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithRichText.java
    
poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BetterHeaderFooterExample.java
    
poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/HeaderFooterTable.java
    
poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/SimpleDocument.java
    
poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/SimpleDocumentWithHeader.java
    
poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/SimpleImages.java
    
poi/trunk/src/examples/src/org/apache/poi/xwpf/usermodel/examples/SimpleTable.java

Modified: 
poi/trunk/src/examples/src/org/apache/poi/crypt/examples/OOXMLPasswordsTry.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/crypt/examples/OOXMLPasswordsTry.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/crypt/examples/OOXMLPasswordsTry.java 
(original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/crypt/examples/OOXMLPasswordsTry.java 
Fri Sep 22 21:16:09 2017
@@ -69,7 +69,7 @@ public class OOXMLPasswordsTry implement
         
         // Try each password in turn, reporting progress
         String valid = null;
-        String password = null;
+        String password;
         while ((password = r.readLine()) != null) {
             if (isValid(password)) {
                 valid = password;

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/CopyCompare.java 
Fri Sep 22 21:16:09 2017
@@ -123,9 +123,9 @@ public class CopyCompare
         final CopyFile cf = new CopyFile(copyFileName);
         r.registerListener(cf);
         r.setNotifyEmptyDirectories(true);
-        FileInputStream fis = new FileInputStream(originalFileName);
-        r.read(fis);
-        fis.close();
+        try (FileInputStream fis = new FileInputStream(originalFileName)) {
+            r.read(fis);
+        }
         
         /* Write the new POIFS to disk. */
         cf.close();
@@ -183,7 +183,7 @@ public class CopyCompare
         for (final Entry e1 : d1) {
             final String n1 = e1.getName();
             if (!d2.hasEntry(n1)) {
-                msg.append("Document \"" + n1 + "\" exists only in the 
source.\n");
+                msg.append("Document \"").append(n1).append("\" exists only in 
the source.\n");
                 equal = false;
                 break;
             }
@@ -194,8 +194,7 @@ public class CopyCompare
             } else if (e1.isDocumentEntry() && e2.isDocumentEntry()) {
                 equal = equal((DocumentEntry) e1, (DocumentEntry) e2, msg);
             } else {
-                msg.append("One of \"" + e1 + "\" and \"" + e2 + "\" is a " +
-                           "document while the other one is a directory.\n");
+                msg.append("One of \"").append(e1).append("\" and 
\"").append(e2).append("\" is a ").append("document while the other one is a 
directory.\n");
                 equal = false;
             }
         }
@@ -208,8 +207,7 @@ public class CopyCompare
             try {
                 e1 = d1.getEntry(n2);
             } catch (FileNotFoundException ex) {
-                msg.append("Document \"" + e2 + "\" exitsts, document \"" +
-                           e1 + "\" does not.\n");
+                msg.append("Document \"").append(e2).append("\" exitsts, 
document \"").append(e1).append("\" does not.\n");
                 equal = false;
                 break;
             }
@@ -243,11 +241,9 @@ public class CopyCompare
     throws NoPropertySetStreamException, MarkUnsupportedException,
            UnsupportedEncodingException, IOException
     {
-        final DocumentInputStream dis1 = new DocumentInputStream(d1);
-        final DocumentInputStream dis2 = new DocumentInputStream(d2);
-        try {
+        try (DocumentInputStream dis1 = new DocumentInputStream(d1); 
DocumentInputStream dis2 = new DocumentInputStream(d2)) {
             if (PropertySet.isPropertySetStream(dis1) &&
-                PropertySet.isPropertySetStream(dis2)) {
+                    PropertySet.isPropertySetStream(dis2)) {
                 final PropertySet ps1 = PropertySetFactory.create(dis1);
                 final PropertySet ps2 = PropertySetFactory.create(dis2);
                 if (!ps1.equals(ps2)) {
@@ -265,9 +261,6 @@ public class CopyCompare
                     }
                 } while (i1 > -1);
             }
-        } finally {
-            dis2.close();
-            dis1.close();
         }
         return true;
     }
@@ -339,11 +332,7 @@ public class CopyCompare
                      * copy it unmodified to the destination POIFS. */
                     copy(poiFs, path, name, stream);
                 }
-            } catch (MarkUnsupportedException ex) {
-                t = ex;
-            } catch (IOException ex) {
-                t = ex;
-            } catch (WritingNotSupportedException ex) {
+            } catch (MarkUnsupportedException | WritingNotSupportedException | 
IOException ex) {
                 t = ex;
             }
 

Modified: poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/ReadTitle.java Fri 
Sep 22 21:16:09 2017
@@ -57,7 +57,7 @@ public class ReadTitle
         @Override
         public void processPOIFSReaderEvent(final POIFSReaderEvent event)
         {
-            SummaryInformation si = null;
+            SummaryInformation si;
             try
             {
                 si = (SummaryInformation)

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteAuthorAndTitle.java
 Fri Sep 22 21:16:09 2017
@@ -187,11 +187,7 @@ public class WriteAuthorAndTitle
                      * copy it unmodified to the destination POIFS. */
                     copy(poiFs, event.getPath(), event.getName(), stream);
                 }
-            } catch (MarkUnsupportedException ex) {
-                t = ex;
-            } catch (IOException ex) {
-                t = ex;
-            } catch (WritingNotSupportedException ex) {
+            } catch (MarkUnsupportedException | WritingNotSupportedException | 
IOException ex) {
                 t = ex;
             }
 

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteTitle.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteTitle.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteTitle.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hpsf/examples/WriteTitle.java Fri 
Sep 22 21:16:09 2017
@@ -79,23 +79,21 @@ public class WriteTitle
         ms.setProperty(p);
 
         /* Create the POI file system the property set is to be written to. */
-        final POIFSFileSystem poiFs = new POIFSFileSystem();
+        try (final POIFSFileSystem poiFs = new POIFSFileSystem()) {
+            /* For writing the property set into a POI file system it has to be
+             * handed over to the POIFS.createDocument() method as an input 
stream
+             * which produces the bytes making out the property set stream. */
+            final InputStream is = mps.toInputStream();
 
-        /* For writing the property set into a POI file system it has to be
-         * handed over to the POIFS.createDocument() method as an input stream
-         * which produces the bytes making out the property set stream. */
-        final InputStream is = mps.toInputStream();
+            /* Create the summary information property set in the POI file
+             * system. It is given the default name most (if not all) summary
+             * information property sets have. */
+            poiFs.createDocument(is, SummaryInformation.DEFAULT_STREAM_NAME);
 
-        /* Create the summary information property set in the POI file
-         * system. It is given the default name most (if not all) summary
-         * information property sets have. */
-        poiFs.createDocument(is, SummaryInformation.DEFAULT_STREAM_NAME);
-
-        /* Write the whole POI file system to a disk file. */
-        FileOutputStream fos = new FileOutputStream(fileName);
-        poiFs.writeFilesystem(fos);
-        fos.close();
-        poiFs.close();
+            /* Write the whole POI file system to a disk file. */
+            try (FileOutputStream fos = new FileOutputStream(fileName)) {
+                poiFs.writeFilesystem(fos);
+            }
+        }
     }
-
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hslf/examples/ApacheconEU08.java 
Fri Sep 22 21:16:09 2017
@@ -51,28 +51,28 @@ import org.apache.poi.sl.usermodel.Verti
 public final class ApacheconEU08 {
 
     public static void main(String[] args) throws IOException {
-        SlideShow<?,?> ppt = new HSLFSlideShow();
-        // SlideShow<?,?> ppt = new XMLSlideShow();
-        ppt.setPageSize(new Dimension(720, 540));
+        try (SlideShow<?,?> ppt = new HSLFSlideShow()) {
+            // SlideShow<?,?> ppt = new XMLSlideShow();
+            ppt.setPageSize(new Dimension(720, 540));
 
-        slide1(ppt);
-        slide2(ppt);
-        slide3(ppt);
-        slide4(ppt);
-        slide5(ppt);
-        slide6(ppt);
-        slide7(ppt);
-        slide8(ppt);
-        slide9(ppt);
-        slide10(ppt);
-        slide11(ppt);
-        slide12(ppt);
+            slide1(ppt);
+            slide2(ppt);
+            slide3(ppt);
+            slide4(ppt);
+            slide5(ppt);
+            slide6(ppt);
+            slide7(ppt);
+            slide8(ppt);
+            slide9(ppt);
+            slide10(ppt);
+            slide11(ppt);
+            slide12(ppt);
 
-        String ext = ppt.getClass().getName().contains("HSLF") ? "ppt" : 
"pptx";
-        FileOutputStream out = new FileOutputStream("apachecon_eu_08."+ext);
-        ppt.write(out);
-        out.close();
-        ppt.close();
+            String ext = ppt.getClass().getName().contains("HSLF") ? "ppt" : 
"pptx";
+            try (FileOutputStream out = new 
FileOutputStream("apachecon_eu_08." + ext)) {
+                ppt.write(out);
+            }
+        }
     }
 
     public static void slide1(SlideShow<?,?> ppt) throws IOException {

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hslf/examples/BulletsDemo.java 
Fri Sep 22 21:16:09 2017
@@ -32,11 +32,9 @@ import org.apache.poi.hslf.usermodel.HSL
 public final class BulletsDemo {
 
     public static void main(String[] args) throws IOException {
-
-        HSLFSlideShow ppt = new HSLFSlideShow();
-        try {
+        try (HSLFSlideShow ppt = new HSLFSlideShow()) {
             HSLFSlide slide = ppt.createSlide();
-    
+
             HSLFTextBox shape = new HSLFTextBox();
             HSLFTextParagraph rt = shape.getTextParagraphs().get(0);
             rt.getTextRuns().get(0).setFontSize(42d);
@@ -46,19 +44,17 @@ public final class BulletsDemo {
             rt.setBulletChar('\u263A'); //bullet character
             shape.setText(
                     "January\r" +
-                    "February\r" +
-                    "March\r" +
-                    "April");
+                            "February\r" +
+                            "March\r" +
+                            "April");
             slide.addShape(shape);
-    
+
             shape.setAnchor(new java.awt.Rectangle(50, 50, 500, 300));  
//position of the text box in the slide
             slide.addShape(shape);
-    
-            FileOutputStream out = new FileOutputStream("bullets.ppt");
-            ppt.write(out);
-            out.close();
-        } finally {
-            ppt.close();
+
+            try (FileOutputStream out = new FileOutputStream("bullets.ppt")) {
+                ppt.write(out);
+            }
         }
    }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java 
(original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/CreateHyperlink.java 
Fri Sep 22 21:16:09 2017
@@ -32,35 +32,31 @@ import org.apache.poi.hslf.usermodel.HSL
 public abstract class CreateHyperlink {
     
     public static void main(String[] args) throws IOException {
-        HSLFSlideShow ppt = new HSLFSlideShow();
-
-        try {
+        try (HSLFSlideShow ppt = new HSLFSlideShow()) {
             HSLFSlide slideA = ppt.createSlide();
             ppt.createSlide();
             HSLFSlide slideC = ppt.createSlide();
-    
+
             // link to a URL
             HSLFTextBox textBox1 = slideA.createTextBox();
             textBox1.setText("Apache POI");
             textBox1.setAnchor(new Rectangle(100, 100, 200, 50));
-    
+
             HSLFHyperlink link1 = 
textBox1.getTextParagraphs().get(0).getTextRuns().get(0).createHyperlink();
             link1.linkToUrl("http://www.apache.org";);
             link1.setLabel(textBox1.getText());
-    
+
             // link to another slide
             HSLFTextBox textBox2 = slideA.createTextBox();
             textBox2.setText("Go to slide #3");
             textBox2.setAnchor(new Rectangle(100, 300, 200, 50));
-    
+
             HSLFHyperlink link2 = 
textBox2.getTextParagraphs().get(0).getTextRuns().get(0).createHyperlink();
             link2.linkToSlide(slideC);
-    
-            FileOutputStream out = new FileOutputStream("hyperlink.ppt");
-            ppt.write(out);
-            out.close();
-        } finally {
-            ppt.close();
+
+            try (FileOutputStream out = new FileOutputStream("hyperlink.ppt")) 
{
+                ppt.write(out);
+            }
         }
    }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hslf/examples/DataExtraction.java 
Fri Sep 22 21:16:09 2017
@@ -52,10 +52,10 @@ public final class DataExtraction {
 
         //extract all sound files embedded in this presentation
         HSLFSoundData[] sound = ppt.getSoundData();
-        for (int i = 0; i < sound.length; i++) {
-            String type = sound[i].getSoundType();  //*.wav
-            String name = sound[i].getSoundName();  //typically file name
-            byte[] data = sound[i].getData();       //raw bytes
+        for (HSLFSoundData aSound : sound) {
+            String type = aSound.getSoundType();  //*.wav
+            String name = aSound.getSoundName();  //typically file name
+            byte[] data = aSound.getData();       //raw bytes
 
             //save the sound  on disk
             FileOutputStream out = new FileOutputStream(name + type);

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Graphics2DDemo.java 
Fri Sep 22 21:16:09 2017
@@ -39,36 +39,34 @@ public final class Graphics2DDemo {
      * A simple bar chart demo
      */
     public static void main(String[] args) throws Exception {
-        HSLFSlideShow ppt = new HSLFSlideShow();
-
-        try {
+        try (HSLFSlideShow ppt = new HSLFSlideShow()) {
             //bar chart data. The first value is the bar color, the second is 
the width
             Object[] def = new Object[]{
-                Color.yellow, 40,
-                Color.green, 60,
-                Color.gray, 30,
-                Color.red, 80,
+                    Color.yellow, 40,
+                    Color.green, 60,
+                    Color.gray, 30,
+                    Color.red, 80,
             };
-    
+
             HSLFSlide slide = ppt.createSlide();
-    
+
             HSLFGroupShape group = new HSLFGroupShape();
             //define position of the drawing in the slide
-            Rectangle bounds = new java.awt.Rectangle(200, 100, 350, 300);
+            Rectangle bounds = new Rectangle(200, 100, 350, 300);
             group.setAnchor(bounds);
-            group.setInteriorAnchor(new java.awt.Rectangle(0, 0, 100, 100));
+            group.setInteriorAnchor(new Rectangle(0, 0, 100, 100));
             slide.addShape(group);
             Graphics2D graphics = new PPGraphics2D(group);
-    
+
             //draw a simple bar graph
             int x = 10, y = 10;
             graphics.setFont(new Font("Arial", Font.BOLD, 10));
-            for (int i = 0, idx = 1; i < def.length; i+=2, idx++) {
+            for (int i = 0, idx = 1; i < def.length; i += 2, idx++) {
                 graphics.setColor(Color.black);
-                int width = ((Integer)def[i+1]).intValue();
-                graphics.drawString("Q" + idx, x-5, y+10);
-                graphics.drawString(width + "%", x + width+3, y + 10);
-                graphics.setColor((Color)def[i]);
+                int width = ((Integer) def[i + 1]).intValue();
+                graphics.drawString("Q" + idx, x - 5, y + 10);
+                graphics.drawString(width + "%", x + width + 3, y + 10);
+                graphics.setColor((Color) def[i]);
                 graphics.fill(new Rectangle(x, y, width, 10));
                 y += 15;
             }
@@ -76,12 +74,10 @@ public final class Graphics2DDemo {
             graphics.setFont(new Font("Arial", Font.BOLD, 14));
             graphics.draw(group.getInteriorAnchor());
             graphics.drawString("Performance", x + 30, y + 10);
-    
-            FileOutputStream out = new FileOutputStream("hslf-graphics.ppt");
-            ppt.write(out);
-            out.close();
-        } finally {
-            ppt.close();
+
+            try (FileOutputStream out = new 
FileOutputStream("hslf-graphics.ppt")) {
+                ppt.write(out);
+            }
         }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java 
(original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/HeadersFootersDemo.java 
Fri Sep 22 21:16:09 2017
@@ -27,25 +27,21 @@ import org.apache.poi.hslf.usermodel.HSL
  */
 public abstract class HeadersFootersDemo {
     public static void main(String[] args) throws IOException {
-        HSLFSlideShow ppt = new HSLFSlideShow();
-        
-        try {
+        try (HSLFSlideShow ppt = new HSLFSlideShow()) {
             HeadersFooters slideHeaders = ppt.getSlideHeadersFooters();
             slideHeaders.setFootersText("Created by POI-HSLF");
             slideHeaders.setSlideNumberVisible(true);
             slideHeaders.setDateTimeText("custom date time");
-    
+
             HeadersFooters notesHeaders = ppt.getNotesHeadersFooters();
             notesHeaders.setFootersText("My notes footers");
             notesHeaders.setHeaderText("My notes header");
-    
+
             ppt.createSlide();
-    
-            FileOutputStream out = new FileOutputStream("headers_footers.ppt");
-            ppt.write(out);
-            out.close();
-        } finally {
-            ppt.close();
+
+            try (FileOutputStream out = new 
FileOutputStream("headers_footers.ppt")) {
+                ppt.write(out);
+            }
         }
     }
 

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hslf/examples/Hyperlinks.java Fri 
Sep 22 21:16:09 2017
@@ -37,8 +37,8 @@ import org.apache.poi.hslf.usermodel.HSL
 public final class Hyperlinks {
 
     public static void main(String[] args) throws Exception {
-        for (int i = 0; i < args.length; i++) {
-            FileInputStream is = new FileInputStream(args[i]);
+        for (String arg : args) {
+            FileInputStream is = new FileInputStream(arg);
             HSLFSlideShow ppt = new HSLFSlideShow(is);
             is.close();
 
@@ -64,7 +64,7 @@ public final class Hyperlinks {
                 System.out.println("- reading hyperlinks from the slide's 
shapes");
                 for (HSLFShape sh : slide.getShapes()) {
                     if (sh instanceof HSLFSimpleShape) {
-                        HSLFHyperlink link = 
((HSLFSimpleShape)sh).getHyperlink();
+                        HSLFHyperlink link = ((HSLFSimpleShape) 
sh).getHyperlink();
                         if (link != null) {
                             System.out.println(toStr(link, null));
                         }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hslf/examples/SoundFinder.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/SoundFinder.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hslf/examples/SoundFinder.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hslf/examples/SoundFinder.java 
Fri Sep 22 21:16:09 2017
@@ -30,23 +30,23 @@ import org.apache.poi.hslf.usermodel.HSL
  */
 public class SoundFinder {
     public static void main(String[] args) throws IOException {
-        FileInputStream fis = new FileInputStream(args[0]);
-        HSLFSlideShow ppt = new HSLFSlideShow(fis);
-        HSLFSoundData[] sounds = ppt.getSoundData();
+        try (FileInputStream fis = new FileInputStream(args[0])) {
+            try (HSLFSlideShow ppt = new HSLFSlideShow(fis)) {
+                HSLFSoundData[] sounds = ppt.getSoundData();
 
-        for (HSLFSlide slide : ppt.getSlides()) {
-            for (HSLFShape shape : slide.getShapes()) {
-                int soundRef = getSoundReference(shape);
-                if(soundRef == -1) continue;
+                for (HSLFSlide slide : ppt.getSlides()) {
+                    for (HSLFShape shape : slide.getShapes()) {
+                        int soundRef = getSoundReference(shape);
+                        if (soundRef == -1) continue;
 
-                
-                System.out.println("Slide["+slide.getSlideNumber()+"], 
shape["+shape.getShapeId()+"], soundRef: "+soundRef);
-                System.out.println("  " + sounds[soundRef].getSoundName());
-                System.out.println("  " + sounds[soundRef].getSoundType());
+
+                        System.out.println("Slide[" + slide.getSlideNumber() + 
"], shape[" + shape.getShapeId() + "], soundRef: " + soundRef);
+                        System.out.println("  " + 
sounds[soundRef].getSoundName());
+                        System.out.println("  " + 
sounds[soundRef].getSoundType());
+                    }
+                }
             }
         }
-        ppt.close();
-        fis.close();
     }
 
     /**

Modified: poi/trunk/src/examples/src/org/apache/poi/hslf/examples/TableDemo.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hslf/examples/TableDemo.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hslf/examples/TableDemo.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hslf/examples/TableDemo.java Fri 
Sep 22 21:16:09 2017
@@ -54,18 +54,14 @@ public final class TableDemo {
 
 
     public static void main(String[] args) throws Exception {
-        HSLFSlideShow ppt = new HSLFSlideShow();
-
-        try {
+        try (HSLFSlideShow ppt = new HSLFSlideShow()) {
             HSLFSlide slide = ppt.createSlide();
             create1stTable(slide);
             create2ndTable(slide);
-    
-            FileOutputStream out = new FileOutputStream("hslf-table.ppt");
-            ppt.write(out);
-            out.close();
-        } finally {
-            ppt.close();
+
+            try (FileOutputStream out = new 
FileOutputStream("hslf-table.ppt")) {
+                ppt.write(out);
+            }
         }
     }
     

Modified: poi/trunk/src/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- poi/trunk/src/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java 
(original)
+++ poi/trunk/src/examples/src/org/apache/poi/hsmf/examples/Msg2txt.java Fri 
Sep 22 21:16:09 2017
@@ -157,12 +157,12 @@ public class Msg2txt {
                if(args.length <= 0) {
                        System.err.println("No files names provided");
                } else {
-                       for(int i = 0; i < args.length; i++) {
+                       for (String arg : args) {
                                try {
-                                       Msg2txt processor = new 
Msg2txt(args[i]);
+                                       Msg2txt processor = new Msg2txt(arg);
                                        processor.processMessage();
                                } catch (IOException e) {
-                                       System.err.println("Could not process 
"+args[i]+": "+e);
+                                       System.err.println("Could not process " 
+ arg + ": " + e);
                                }
                        }
                }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/AddDimensionedImage.java
 Fri Sep 22 21:16:09 2017
@@ -251,10 +251,10 @@ public class AddDimensionedImage {
             String imageFile, double reqImageWidthMM, double reqImageHeightMM,
             int resizeBehaviour) throws FileNotFoundException, IOException,
                                                      IllegalArgumentException  
{
-        HSSFClientAnchor anchor = null;
-        HSSFPatriarch patriarch = null;
-        ClientAnchorDetail rowClientAnchorDetail = null;
-        ClientAnchorDetail colClientAnchorDetail = null;
+        HSSFClientAnchor anchor;
+        HSSFPatriarch patriarch;
+        ClientAnchorDetail rowClientAnchorDetail;
+        ClientAnchorDetail colClientAnchorDetail;
 
         // Validate the resizeBehaviour parameter.
         if((resizeBehaviour != AddDimensionedImage.EXPAND_COLUMN) &&
@@ -334,9 +334,9 @@ public class AddDimensionedImage {
     private ClientAnchorDetail fitImageToColumns(HSSFSheet sheet, int 
colNumber,
             double reqImageWidthMM, int resizeBehaviour) {
 
-        double colWidthMM = 0.0D;
-        double colCoordinatesPerMM = 0.0D;
-        int pictureWidthCoordinates = 0;
+        double colWidthMM;
+        double colCoordinatesPerMM;
+        int pictureWidthCoordinates;
         ClientAnchorDetail colClientAnchorDetail = null;
 
         // Get the colum's width in millimetres
@@ -417,21 +417,19 @@ public class AddDimensionedImage {
      */
     private ClientAnchorDetail fitImageToRows(HSSFSheet sheet, int rowNumber,
             double reqImageHeightMM, int resizeBehaviour) {
-        HSSFRow row = null;
-        double rowHeightMM = 0.0D;
-        double rowCoordinatesPerMM = 0.0D;
-        int pictureHeightCoordinates = 0;
+        double rowCoordinatesPerMM;
+        int pictureHeightCoordinates;
         ClientAnchorDetail rowClientAnchorDetail = null;
 
         // Get the row and it's height
-        row = sheet.getRow(rowNumber);
+        HSSFRow row = sheet.getRow(rowNumber);
         if(row == null) {
             // Create row if it does not exist.
             row = sheet.createRow(rowNumber);
         }
 
         // Get the row's height in millimetres
-        rowHeightMM = row.getHeightInPoints() / 
ConvertImageUnits.POINTS_PER_MILLIMETRE;
+        double rowHeightMM = row.getHeightInPoints() / 
ConvertImageUnits.POINTS_PER_MILLIMETRE;
 
         // Check that the row's height will accomodate the image at the 
required
         // dimensions. If the height of the row is LESS than the required 
height
@@ -494,13 +492,13 @@ public class AddDimensionedImage {
     private ClientAnchorDetail calculateColumnLocation(HSSFSheet sheet,
                                                        int startingColumn,
                                                        double reqImageWidthMM) 
{
-        ClientAnchorDetail anchorDetail = null;
+        ClientAnchorDetail anchorDetail;
         double totalWidthMM = 0.0D;
         double colWidthMM = 0.0D;
-        double overlapMM = 0.0D;
-        double coordinatePositionsPerMM = 0.0D;
+        double overlapMM;
+        double coordinatePositionsPerMM;
         int toColumn = startingColumn;
-        int inset = 0;
+        int inset;
 
         // Calculate how many columns the image will have to
         // span in order to be presented at the required size.
@@ -593,14 +591,14 @@ public class AddDimensionedImage {
      */
     private ClientAnchorDetail calculateRowLocation(HSSFSheet sheet,
             int startingRow, double reqImageHeightMM) {
-        ClientAnchorDetail clientAnchorDetail = null;
-        HSSFRow row = null;
+        ClientAnchorDetail clientAnchorDetail;
+        HSSFRow row;
         double rowHeightMM = 0.0D;
         double totalRowHeightMM = 0.0D;
-        double overlapMM = 0.0D;
-        double rowCoordinatesPerMM = 0.0D;
+        double overlapMM;
+        double rowCoordinatesPerMM;
         int toRow = startingRow;
-        int inset = 0;
+        int inset;
 
         // Step through the rows in the sheet and accumulate a total of their
         // heights.
@@ -672,10 +670,10 @@ public class AddDimensionedImage {
      *                             interrupted.
      */
     private byte[] imageToBytes(String imageFilename) throws IOException {
-        File imageFile = null;
+        File imageFile;
         FileInputStream fis = null;
-        ByteArrayOutputStream bos = null;
-        int read = 0;
+        ByteArrayOutputStream bos;
+        int read;
         try {
             imageFile = new File(imageFilename);
             fis = new FileInputStream(imageFile);
@@ -718,10 +716,10 @@ public class AddDimensionedImage {
      * @param args the command line arguments
      */
     public static void main(String[] args) {
-        String imageFile = null;
-        String outputFile = null;
+        String imageFile;
+        String outputFile;
         FileOutputStream fos = null;
-        HSSFSheet sheet = null;
+        HSSFSheet sheet;
         try {
             if(args.length < 2){
                 System.err.println("Usage: AddDimensionedImage imageFile 
outputFile");
@@ -730,25 +728,15 @@ public class AddDimensionedImage {
             imageFile = args[0];
             outputFile = args[1];
 
-            HSSFWorkbook workbook = new HSSFWorkbook();
-            try  {
+            try (HSSFWorkbook workbook = new HSSFWorkbook()) {
                 sheet = workbook.createSheet("Picture Test");
                 new AddDimensionedImage().addImageToSheet("A1", sheet,
                         imageFile, 125, 125,
                         AddDimensionedImage.EXPAND_ROW_AND_COLUMN);
                 fos = new FileOutputStream(outputFile);
                 workbook.write(fos);
-            } finally {
-                workbook.close();
             }
-        }
-        catch(FileNotFoundException fnfEx) {
-            System.out.println("Caught an: " + fnfEx.getClass().getName());
-            System.out.println("Message: " + fnfEx.getMessage());
-            System.out.println("Stacktrace follows...........");
-            fnfEx.printStackTrace(System.out);
-        }
-        catch(IOException ioEx) {
+        } catch(IOException ioEx) {
             System.out.println("Caught an: " + ioEx.getClass().getName());
             System.out.println("Message: " + ioEx.getMessage());
             System.out.println("Stacktrace follows...........");

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Alignment.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Alignment.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Alignment.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Alignment.java
 Fri Sep 22 21:16:09 2017
@@ -36,23 +36,22 @@ import org.apache.poi.ss.usermodel.Horiz
  */
 public class Alignment {
     public static void main(String[] args) throws IOException {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet("new sheet");
-        HSSFRow row = sheet.createRow(2);
-        createCell(wb, row, 0, HorizontalAlignment.CENTER);
-        createCell(wb, row, 1, HorizontalAlignment.CENTER_SELECTION);
-        createCell(wb, row, 2, HorizontalAlignment.FILL);
-        createCell(wb, row, 3, HorizontalAlignment.GENERAL);
-        createCell(wb, row, 4, HorizontalAlignment.JUSTIFY);
-        createCell(wb, row, 5, HorizontalAlignment.LEFT);
-        createCell(wb, row, 6, HorizontalAlignment.RIGHT);
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
+            HSSFSheet sheet = wb.createSheet("new sheet");
+            HSSFRow row = sheet.createRow(2);
+            createCell(wb, row, 0, HorizontalAlignment.CENTER);
+            createCell(wb, row, 1, HorizontalAlignment.CENTER_SELECTION);
+            createCell(wb, row, 2, HorizontalAlignment.FILL);
+            createCell(wb, row, 3, HorizontalAlignment.GENERAL);
+            createCell(wb, row, 4, HorizontalAlignment.JUSTIFY);
+            createCell(wb, row, 5, HorizontalAlignment.LEFT);
+            createCell(wb, row, 6, HorizontalAlignment.RIGHT);
 
-        // Write the output to a file
-        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-        wb.write(fileOut);
-        fileOut.close();
-        
-        wb.close();
+            // Write the output to a file
+            try (FileOutputStream fileOut = new 
FileOutputStream("workbook.xls")) {
+                wb.write(fileOut);
+            }
+        }
     }
 
     /**

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/BigExample.java
 Fri Sep 22 21:16:09 2017
@@ -39,8 +39,7 @@ public class BigExample {
         int rownum;
 
         // create a new workbook
-        HSSFWorkbook wb = new HSSFWorkbook();
-        try {
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
             // create a new sheet
             HSSFSheet s = wb.createSheet();
             // declare a row object reference
@@ -54,7 +53,7 @@ public class BigExample {
             // create 2 fonts objects
             HSSFFont f = wb.createFont();
             HSSFFont f2 = wb.createFont();
-    
+
             //set font 1 to 12 point type
             f.setFontHeightInPoints((short) 12);
             //make it red
@@ -62,118 +61,110 @@ public class BigExample {
             // make it bold
             //arial is the default font
             f.setBold(true);
-    
+
             //set font 2 to 10 point type
             f2.setFontHeightInPoints((short) 10);
             //make it the color at palette index 0xf (white)
             f2.setColor(HSSFColorPredefined.WHITE.getIndex());
             //make it bold
             f2.setBold(true);
-    
+
             //set cell stlye
             cs.setFont(f);
             //set the cell format see HSSFDataFromat for a full list
             
cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)"));
-    
+
             //set a thin border
             cs2.setBorderBottom(BorderStyle.THIN);
             //fill w fg fill color
             cs2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
             // set foreground fill to red
             cs2.setFillForegroundColor(HSSFColorPredefined.RED.getIndex());
-    
+
             // set the font
             cs2.setFont(f2);
-    
+
             // set the sheet name to HSSF Test
             wb.setSheetName(0, "HSSF Test");
             // create a sheet with 300 rows (0-299)
-            for (rownum = 0; rownum < 300; rownum++)
-            {
+            for (rownum = 0; rownum < 300; rownum++) {
                 // create a row
                 r = s.createRow(rownum);
                 // on every other row
-                if ((rownum % 2) == 0)
-                {
+                if ((rownum % 2) == 0) {
                     // make the row height bigger  (in twips - 1/20 of a point)
                     r.setHeight((short) 0x249);
                 }
-    
+
                 //r.setRowNum(( short ) rownum);
                 // create 50 cells (0-49) (the += 2 becomes apparent later
-                for (int cellnum = 0; cellnum < 50; cellnum += 2)
-                {
+                for (int cellnum = 0; cellnum < 50; cellnum += 2) {
                     // create a numeric cell
                     c = r.createCell(cellnum);
                     // do some goofy math to demonstrate decimals
                     c.setCellValue(rownum * 10000 + cellnum
                             + (((double) rownum / 1000)
                             + ((double) cellnum / 10000)));
-    
+
                     // on every other row
-                    if ((rownum % 2) == 0)
-                    {
+                    if ((rownum % 2) == 0) {
                         // set this cell to the first cell style we defined
                         c.setCellStyle(cs);
                     }
-    
+
                     // create a string cell (see why += 2 in the
                     c = r.createCell(cellnum + 1);
-    
+
                     // set the cell's string value to "TEST"
                     c.setCellValue("TEST");
                     // make this column a bit wider
-                    s.setColumnWidth(cellnum + 1, (int)((50 * 8) / ((double) 1 
/ 20)));
-    
+                    s.setColumnWidth(cellnum + 1, (int) ((50 * 8) / ((double) 
1 / 20)));
+
                     // on every other row
-                    if ((rownum % 2) == 0)
-                    {
+                    if ((rownum % 2) == 0) {
                         // set this to the white on red cell style
                         // we defined above
                         c.setCellStyle(cs2);
                     }
-    
+
                 }
             }
-    
+
             //draw a thick black border on the row at the bottom using BLANKS
             // advance 2 rows
             rownum++;
             rownum++;
-    
+
             r = s.createRow(rownum);
-    
+
             // define the third style to be the default
             // except with a thick black border at the bottom
             cs3.setBorderBottom(BorderStyle.THICK);
-    
+
             //create 50 cells
-            for (int cellnum =0; cellnum < 50; cellnum++) {
+            for (int cellnum = 0; cellnum < 50; cellnum++) {
                 //create a blank type cell (no value)
                 c = r.createCell(cellnum);
                 // set it to the thick black border style
                 c.setCellStyle(cs3);
             }
-    
+
             //end draw thick black border
-    
-    
+
+
             // demonstrate adding/naming and deleting a sheet
             // create a sheet, set its title then delete it
             wb.createSheet();
             wb.setSheetName(1, "DeletedSheet");
             wb.removeSheetAt(1);
             //end deleted sheet
-    
+
             // create a new file
-            FileOutputStream out = new FileOutputStream("workbook.xls");
-    
-            // write the workbook to the output stream
-            // close our file (don't blow out our file handles
-            wb.write(out);
-            out.close();
-        } finally {
-            wb.close();
+            try (FileOutputStream out = new FileOutputStream("workbook.xls")) {
+                // write the workbook to the output stream
+                // close our file (don't blow out our file handles
+                wb.write(out);
+            }
         }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java 
(original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Borders.java 
Fri Sep 22 21:16:09 2017
@@ -33,8 +33,7 @@ import org.apache.poi.ss.usermodel.Borde
  */
 public class Borders {
     public static void main(String[] args) throws IOException {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        try {
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
             HSSFSheet sheet = wb.createSheet("new sheet");
 
             // Create a row and put some cells in it. Rows are 0 based.
@@ -57,11 +56,9 @@ public class Borders {
             cell.setCellStyle(style);
 
             // Write the output to a file
-            FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-            wb.write(fileOut);
-            fileOut.close();
-        } finally {
-            wb.close();
+            try (FileOutputStream fileOut = new 
FileOutputStream("workbook.xls")) {
+                wb.write(fileOut);
+            }
         }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellComments.java
 Fri Sep 22 21:16:09 2017
@@ -39,68 +39,64 @@ import org.apache.poi.hssf.util.HSSFColo
 public class CellComments {
 
     public static void main(String[] args) throws IOException  {
-
-        HSSFWorkbook wb = new HSSFWorkbook();
-        try {
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
             HSSFSheet sheet = wb.createSheet("Cell comments in POI HSSF");
-    
+
             // Create the drawing patriarch. This is the top level container 
for all shapes including cell comments.
             HSSFPatriarch patr = sheet.createDrawingPatriarch();
-    
+
             //create a cell in row 3
             HSSFCell cell1 = sheet.createRow(3).createCell(1);
             cell1.setCellValue(new HSSFRichTextString("Hello, World"));
-    
+
             //anchor defines size and position of the comment in worksheet
-            HSSFComment comment1 = patr.createComment(new HSSFClientAnchor(0, 
0, 0, 0, (short)4, 2, (short) 6, 5));
-    
-             // set text in the comment
+            HSSFComment comment1 = patr.createComment(new HSSFClientAnchor(0, 
0, 0, 0, (short) 4, 2, (short) 6, 5));
+
+            // set text in the comment
             comment1.setString(new HSSFRichTextString("We can set comments in 
POI"));
-    
+
             //set comment author.
             //you can see it in the status bar when moving mouse over the 
commented cell
             comment1.setAuthor("Apache Software Foundation");
-    
+
             // The first way to assign comment to a cell is via 
HSSFCell.setCellComment method
             cell1.setCellComment(comment1);
-    
+
             //create another cell in row 6
             HSSFCell cell2 = sheet.createRow(6).createCell(1);
             cell2.setCellValue(36.6);
-    
-    
-            HSSFComment comment2 = patr.createComment(new HSSFClientAnchor(0, 
0, 0, 0, (short)4, 8, (short) 6, 11));
+
+
+            HSSFComment comment2 = patr.createComment(new HSSFClientAnchor(0, 
0, 0, 0, (short) 4, 8, (short) 6, 11));
             //modify background color of the comment
             comment2.setFillColor(204, 236, 255);
-    
+
             HSSFRichTextString string = new HSSFRichTextString("Normal body 
temperature");
-    
+
             //apply custom font to the text in the comment
             HSSFFont font = wb.createFont();
             font.setFontName("Arial");
-            font.setFontHeightInPoints((short)10);
+            font.setFontHeightInPoints((short) 10);
             font.setBold(true);
             font.setColor(HSSFColorPredefined.RED.getIndex());
             string.applyFont(font);
-    
+
             comment2.setString(string);
             comment2.setVisible(true); //by default comments are hidden. This 
one is always visible.
-    
+
             comment2.setAuthor("Bill Gates");
-    
-            /**
+
+            /*
              * The second way to assign comment to a cell is to implicitly 
specify its row and column.
              * Note, it is possible to set row and column of a non-existing 
cell.
              * It works, the comment is visible.
              */
             comment2.setRow(6);
             comment2.setColumn(1);
-    
-            FileOutputStream out = new FileOutputStream("poi_comment.xls");
-            wb.write(out);
-            out.close();
-        } finally {
-            wb.close();
+
+            try (FileOutputStream out = new 
FileOutputStream("poi_comment.xls")) {
+                wb.write(out);
+            }
         }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CellTypes.java
 Fri Sep 22 21:16:09 2017
@@ -28,8 +28,7 @@ import org.apache.poi.ss.usermodel.CellT
 
 public class CellTypes {
     public static void main(String[] args) throws IOException {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        try {
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
             HSSFSheet sheet = wb.createSheet("new sheet");
             HSSFRow row = sheet.createRow(2);
             row.createCell(0).setCellValue(1.1);
@@ -37,13 +36,11 @@ public class CellTypes {
             row.createCell(2).setCellValue("a string");
             row.createCell(3).setCellValue(true);
             row.createCell(4).setCellType(CellType.ERROR);
-    
+
             // Write the output to a file
-            FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-            wb.write(fileOut);
-            fileOut.close();
-        } finally {
-            wb.close();
+            try (FileOutputStream fileOut = new 
FileOutputStream("workbook.xls")) {
+                wb.write(fileOut);
+            }
         }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateCells.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateCells.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateCells.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateCells.java
 Fri Sep 22 21:16:09 2017
@@ -32,25 +32,24 @@ import java.io.IOException;
  */
 public class CreateCells {
     public static void main(String[] args) throws IOException {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet("new sheet");
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
+            HSSFSheet sheet = wb.createSheet("new sheet");
 
-        // Create a row and put some cells in it. Rows are 0 based.
-        HSSFRow row = sheet.createRow(0);
-        // Create a cell and put a value in it.
-        HSSFCell cell = row.createCell(0);
-        cell.setCellValue(1);
+            // Create a row and put some cells in it. Rows are 0 based.
+            HSSFRow row = sheet.createRow(0);
+            // Create a cell and put a value in it.
+            HSSFCell cell = row.createCell(0);
+            cell.setCellValue(1);
 
-        // Or do it on one line.
-        row.createCell(1).setCellValue(1.2);
-        row.createCell(2).setCellValue("This is a string");
-        row.createCell(3).setCellValue(true);
+            // Or do it on one line.
+            row.createCell(1).setCellValue(1.2);
+            row.createCell(2).setCellValue("This is a string");
+            row.createCell(3).setCellValue(true);
 
-        // Write the output to a file
-        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-        wb.write(fileOut);
-        fileOut.close();
-
-        wb.close();
+            // Write the output to a file
+            try (FileOutputStream fileOut = new 
FileOutputStream("workbook.xls")) {
+                wb.write(fileOut);
+            }
+        }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateDateCells.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateDateCells.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateDateCells.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/CreateDateCells.java
 Fri Sep 22 21:16:09 2017
@@ -35,29 +35,28 @@ import org.apache.poi.hssf.usermodel.HSS
  */
 public class CreateDateCells {
     public static void main(String[] args) throws IOException {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet("new sheet");
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
+            HSSFSheet sheet = wb.createSheet("new sheet");
 
-        // Create a row and put some cells in it. Rows are 0 based.
-        HSSFRow row = sheet.createRow(0);
+            // Create a row and put some cells in it. Rows are 0 based.
+            HSSFRow row = sheet.createRow(0);
 
-        // Create a cell and put a date value in it.  The first cell is not 
styled as a date.
-        HSSFCell cell = row.createCell(0);
-        cell.setCellValue(new Date());
+            // Create a cell and put a date value in it.  The first cell is 
not styled as a date.
+            HSSFCell cell = row.createCell(0);
+            cell.setCellValue(new Date());
 
-        // we style the second cell as a date (and time).  It is important to 
create a new cell style from the workbook
-        // otherwise you can end up modifying the built in style and effecting 
not only this cell but other cells.
-        HSSFCellStyle cellStyle = wb.createCellStyle();
-        cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy 
h:mm"));
-        cell = row.createCell(1);
-        cell.setCellValue(new Date());
-        cell.setCellStyle(cellStyle);
+            // we style the second cell as a date (and time).  It is important 
to create a new cell style from the workbook
+            // otherwise you can end up modifying the built in style and 
effecting not only this cell but other cells.
+            HSSFCellStyle cellStyle = wb.createCellStyle();
+            cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy 
h:mm"));
+            cell = row.createCell(1);
+            cell.setCellValue(new Date());
+            cell.setCellStyle(cellStyle);
 
-        // Write the output to a file
-        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-        wb.write(fileOut);
-        fileOut.close();
-        
-        wb.close();
+            // Write the output to a file
+            try (FileOutputStream fileOut = new 
FileOutputStream("workbook.xls")) {
+                wb.write(fileOut);
+            }
+        }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EmbeddedObjects.java
 Fri Sep 22 21:16:09 2017
@@ -34,34 +34,34 @@ public class EmbeddedObjects {
     @SuppressWarnings("unused")
     public static void main(String[] args) throws Exception {
         POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(args[0]));
-        HSSFWorkbook workbook = new HSSFWorkbook(fs);
-        for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
-            //the OLE2 Class Name of the object
-            String oleName = obj.getOLE2ClassName();
-            DirectoryNode dn = (obj.hasDirectoryEntry()) ? (DirectoryNode) 
obj.getDirectory() : null;
-            Closeable document = null;
-            if (oleName.equals("Worksheet")) {
-                document = new HSSFWorkbook(dn, fs, false);
-            } else if (oleName.equals("Document")) {
-                document = new HWPFDocument(dn);
-            }  else if (oleName.equals("Presentation")) {
-                document = new HSLFSlideShow(dn);
-            } else {
-                if(dn != null){
-                    // The DirectoryEntry is a DocumentNode. Examine its 
entries to find out what it is
-                    for (Entry entry : dn) {
-                         String name = entry.getName();
-                    }
+        try (HSSFWorkbook workbook = new HSSFWorkbook(fs)) {
+            for (HSSFObjectData obj : workbook.getAllEmbeddedObjects()) {
+                //the OLE2 Class Name of the object
+                String oleName = obj.getOLE2ClassName();
+                DirectoryNode dn = (obj.hasDirectoryEntry()) ? (DirectoryNode) 
obj.getDirectory() : null;
+                Closeable document = null;
+                if (oleName.equals("Worksheet")) {
+                    document = new HSSFWorkbook(dn, fs, false);
+                } else if (oleName.equals("Document")) {
+                    document = new HWPFDocument(dn);
+                } else if (oleName.equals("Presentation")) {
+                    document = new HSLFSlideShow(dn);
                 } else {
-                    // There is no DirectoryEntry
-                    // Recover the object's data from the HSSFObjectData 
instance.
-                    byte[] objectData = obj.getObjectData();
+                    if (dn != null) {
+                        // The DirectoryEntry is a DocumentNode. Examine its 
entries to find out what it is
+                        for (Entry entry : dn) {
+                            String name = entry.getName();
+                        }
+                    } else {
+                        // There is no DirectoryEntry
+                        // Recover the object's data from the HSSFObjectData 
instance.
+                        byte[] objectData = obj.getObjectData();
+                    }
+                }
+                if (document != null) {
+                    document.close();
                 }
-            }
-            if (document != null) {
-                document.close();
             }
         }
-        workbook.close();
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EventExample.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EventExample.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EventExample.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/EventExample.java
 Fri Sep 22 21:16:09 2017
@@ -31,9 +31,7 @@ import java.io.InputStream;
 /**
  * This example shows how to use the event API for reading a file.
  */
-public class EventExample
-        implements HSSFListener
-{
+public class EventExample implements HSSFListener {
     private SSTRecord sstrec;
 
     /**
@@ -97,24 +95,22 @@ public class EventExample
     {
         // create a new file input stream with the input file specified
         // at the command line
-        FileInputStream fin = new FileInputStream(args[0]);
-        // create a new org.apache.poi.poifs.filesystem.Filesystem
-        POIFSFileSystem poifs = new POIFSFileSystem(fin);
-        // get the Workbook (excel part) stream in a InputStream
-        InputStream din = poifs.createDocumentInputStream("Workbook");
-        // construct out HSSFRequest object
-        HSSFRequest req = new HSSFRequest();
-        // lazy listen for ALL records with the listener shown above
-        req.addListenerForAllRecords(new EventExample());
-        // create our event factory
-        HSSFEventFactory factory = new HSSFEventFactory();
-        // process our events based on the document input stream
-        factory.processEvents(req, din);
-        // once all the events are processed close our file input stream
-        fin.close();
-        // and our document input stream (don't want to leak these!)
-        din.close();
-        poifs.close();
+        try (FileInputStream fin = new FileInputStream(args[0])) {
+            // create a new org.apache.poi.poifs.filesystem.Filesystem
+            try (POIFSFileSystem poifs = new POIFSFileSystem(fin)) {
+                // get the Workbook (excel part) stream in a InputStream
+                try (InputStream din = 
poifs.createDocumentInputStream("Workbook")) {
+                    // construct out HSSFRequest object
+                    HSSFRequest req = new HSSFRequest();
+                    // lazy listen for ALL records with the listener shown 
above
+                    req.addListenerForAllRecords(new EventExample());
+                    // create our event factory
+                    HSSFEventFactory factory = new HSSFEventFactory();
+                    // process our events based on the document input stream
+                    factory.processEvents(req, din);
+                }
+            }
+        }
         System.out.println("done.");
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/FrillsAndFills.java
 Fri Sep 22 21:16:09 2017
@@ -33,33 +33,32 @@ import org.apache.poi.ss.usermodel.FillP
  */
 public class FrillsAndFills {
     public static void main(String[] args) throws IOException {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet("new sheet");
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
+            HSSFSheet sheet = wb.createSheet("new sheet");
 
-        // Create a row and put some cells in it. Rows are 0 based.
-        HSSFRow row = sheet.createRow(1);
+            // Create a row and put some cells in it. Rows are 0 based.
+            HSSFRow row = sheet.createRow(1);
 
-        // Aqua background
-        HSSFCellStyle style = wb.createCellStyle();
-        style.setFillBackgroundColor(HSSFColorPredefined.AQUA.getIndex());
-        style.setFillPattern(FillPatternType.BIG_SPOTS);
-        HSSFCell cell = row.createCell(1);
-        cell.setCellValue("X");
-        cell.setCellStyle(style);
+            // Aqua background
+            HSSFCellStyle style = wb.createCellStyle();
+            style.setFillBackgroundColor(HSSFColorPredefined.AQUA.getIndex());
+            style.setFillPattern(FillPatternType.BIG_SPOTS);
+            HSSFCell cell = row.createCell(1);
+            cell.setCellValue("X");
+            cell.setCellStyle(style);
 
-        // Orange "foreground", foreground being the fill foreground not the 
font color.
-        style = wb.createCellStyle();
-        style.setFillForegroundColor(HSSFColorPredefined.ORANGE.getIndex());
-        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
-        cell = row.createCell(2);
-        cell.setCellValue("X");
-        cell.setCellStyle(style);
+            // Orange "foreground", foreground being the fill foreground not 
the font color.
+            style = wb.createCellStyle();
+            
style.setFillForegroundColor(HSSFColorPredefined.ORANGE.getIndex());
+            style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+            cell = row.createCell(2);
+            cell.setCellValue("X");
+            cell.setCellStyle(style);
 
-        // Write the output to a file
-        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-        wb.write(fileOut);
-        fileOut.close();
-        
-        wb.close();
+            // Write the output to a file
+            try (FileOutputStream fileOut = new 
FileOutputStream("workbook.xls")) {
+                wb.write(fileOut);
+            }
+        }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java
 Fri Sep 22 21:16:09 2017
@@ -47,12 +47,9 @@ public final class HSSFReadWrite {
         * creates an {@link HSSFWorkbook} with the specified OS filename.
         */
        private static HSSFWorkbook readFile(String filename) throws 
IOException {
-           FileInputStream fis = new FileInputStream(filename);
-           try {
-               return new HSSFWorkbook(fis);           // NOSONAR - should not 
be closed here
-           } finally {
-               fis.close();
-           }
+               try (FileInputStream fis = new FileInputStream(filename)) {
+                       return new HSSFWorkbook(fis);        // NOSONAR - 
should not be closed here
+               }
        }
 
        /**
@@ -60,8 +57,7 @@ public final class HSSFReadWrite {
         * rows/cells.
         */
        private static void testCreateSampleSheet(String outputFilename) throws 
IOException {
-               HSSFWorkbook wb = new HSSFWorkbook();
-               try {
+               try (HSSFWorkbook wb = new HSSFWorkbook()) {
                        HSSFSheet s = wb.createSheet();
                        HSSFCellStyle cs = wb.createCellStyle();
                        HSSFCellStyle cs2 = wb.createCellStyle();
@@ -125,14 +121,9 @@ public final class HSSFReadWrite {
                        wb.removeSheetAt(1);
 
                        // end deleted sheet
-                       FileOutputStream out = new 
FileOutputStream(outputFilename);
-                       try {
+                       try (FileOutputStream out = new 
FileOutputStream(outputFilename)) {
                                wb.write(out);
-                       } finally {
-                               out.close();
                        }
-               } finally {
-                       wb.close();
                }
        }
 
@@ -166,9 +157,7 @@ public final class HSSFReadWrite {
                try {
                        if (args.length < 2) {
 
-                               HSSFWorkbook wb = 
HSSFReadWrite.readFile(fileName);
-
-                               try {
+                               try (HSSFWorkbook wb = 
HSSFReadWrite.readFile(fileName)) {
                                        System.out.println("Data dump:\n");
 
                                        for (int k = 0; k < 
wb.getNumberOfSheets(); k++) {
@@ -187,7 +176,7 @@ public final class HSSFReadWrite {
                                                                HSSFCell cell = 
row.getCell(c);
                                                                String value;
 
-                                                               if(cell != 
null) {
+                                                               if (cell != 
null) {
                                                                        switch 
(cell.getCellType()) {
 
                                                                                
case FORMULA:
@@ -223,8 +212,6 @@ public final class HSSFReadWrite {
                                                        }
                                                }
                                        }
-                               } finally {
-                                       wb.close();
                                }
                        } else if (args.length == 2) {
                                if 
(args[1].toLowerCase(Locale.ROOT).equals("write")) {
@@ -236,23 +223,16 @@ public final class HSSFReadWrite {
                                                        + " ms generation 
time");
                                } else {
                                        System.out.println("readwrite test");
-                                       HSSFWorkbook wb = 
HSSFReadWrite.readFile(fileName);
-                                       try {
-                                               FileOutputStream stream = new 
FileOutputStream(args[1]);
-                                               try {
+                                       try (HSSFWorkbook wb = 
HSSFReadWrite.readFile(fileName)) {
+                                               try (FileOutputStream stream = 
new FileOutputStream(args[1])) {
                                                        wb.write(stream);
-                                               } finally {
-                                                       stream.close();
                                                }
-                                       } finally {
-                                               wb.close();
                                        }
                                }
                        } else if (args.length == 3 && 
args[2].equalsIgnoreCase("modify1")) {
                                // delete row 0-24, row 74 - 99 && change cell 
3 on row 39 to string "MODIFIED CELL!!"
 
-                               HSSFWorkbook wb = 
HSSFReadWrite.readFile(fileName);
-                               try {
+                               try (HSSFWorkbook wb = 
HSSFReadWrite.readFile(fileName)) {
                                        HSSFSheet sheet = wb.getSheetAt(0);
 
                                        for (int k = 0; k < 25; k++) {
@@ -269,14 +249,9 @@ public final class HSSFReadWrite {
                                        HSSFCell cell = row.getCell(3);
                                        cell.setCellValue("MODIFIED CELL!!!!!");
 
-                                       FileOutputStream stream = new 
FileOutputStream(args[1]);
-                                       try {
+                                       try (FileOutputStream stream = new 
FileOutputStream(args[1])) {
                                                wb.write(stream);
-                                       } finally {
-                                               stream.close();
                                        }
-                               } finally {
-                                       wb.close();
                                }
                        }
                } catch (Exception e) {

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/HyperlinkFormula.java
 Fri Sep 22 21:16:09 2017
@@ -31,17 +31,17 @@ import org.apache.poi.ss.usermodel.CellT
  */
 public class HyperlinkFormula {
     public static void main(String[] args) throws IOException {
-       HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFSheet sheet = wb.createSheet("new sheet");
-        HSSFRow row = sheet.createRow(0);
+       try (HSSFWorkbook wb = new HSSFWorkbook()) {
+            HSSFSheet sheet = wb.createSheet("new sheet");
+            HSSFRow row = sheet.createRow(0);
 
-        HSSFCell cell = row.createCell(0);
-        cell.setCellType(CellType.FORMULA);
-        
cell.setCellFormula("HYPERLINK(\"http://127.0.0.1:8080/toto/truc/index.html?test=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\";,
 \"test\")");
+            HSSFCell cell = row.createCell(0);
+            cell.setCellType(CellType.FORMULA);
+            
cell.setCellFormula("HYPERLINK(\"http://127.0.0.1:8080/toto/truc/index.html?test=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\";,
 \"test\")");
 
-        FileOutputStream fileOut = new FileOutputStream("workbook.xls");
-        wb.write(fileOut);
-        fileOut.close();
-        wb.close();
+            try (FileOutputStream fileOut = new 
FileOutputStream("workbook.xls")) {
+                wb.write(fileOut);
+            }
+        }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/Hyperlinks.java
 Fri Sep 22 21:16:09 2017
@@ -37,61 +37,61 @@ import org.apache.poi.ss.usermodel.Font;
 public class Hyperlinks {
 
     public static void main(String[] args) throws IOException  {
-        HSSFWorkbook wb = new HSSFWorkbook();
-        HSSFCreationHelper helper = wb.getCreationHelper();
+        try (HSSFWorkbook wb = new HSSFWorkbook()) {
+            HSSFCreationHelper helper = wb.getCreationHelper();
 
-        //cell style for hyperlinks
-        //by default hyperlinks are blue and underlined
-        HSSFCellStyle hlink_style = wb.createCellStyle();
-        HSSFFont hlink_font = wb.createFont();
-        hlink_font.setUnderline(Font.U_SINGLE);
-        hlink_font.setColor(HSSFColorPredefined.BLUE.getIndex());
-        hlink_style.setFont(hlink_font);
-
-        HSSFCell cell;
-        HSSFSheet sheet = wb.createSheet("Hyperlinks");
-
-        //URL
-        cell = sheet.createRow(0).createCell(0);
-        cell.setCellValue("URL Link");
-        HSSFHyperlink link = helper.createHyperlink(HyperlinkType.URL);
-        link.setAddress("http://poi.apache.org/";);
-        cell.setHyperlink(link);
-        cell.setCellStyle(hlink_style);
-
-        //link to a file in the current directory
-        cell = sheet.createRow(1).createCell(0);
-        cell.setCellValue("File Link");
-        link = helper.createHyperlink(HyperlinkType.FILE);
-        link.setAddress("link1.xls");
-        cell.setHyperlink(link);
-        cell.setCellStyle(hlink_style);
-
-        //e-mail link
-        cell = sheet.createRow(2).createCell(0);
-        cell.setCellValue("Email Link");
-        link = helper.createHyperlink(HyperlinkType.EMAIL);
-        //note, if subject contains white spaces, make sure they are 
url-encoded
-        link.setAddress("mailto:[email protected]?subject=Hyperlinks";);
-        cell.setHyperlink(link);
-        cell.setCellStyle(hlink_style);
-
-        //link to a place in this workbook
-
-        //create a target sheet and cell
-        HSSFSheet sheet2 = wb.createSheet("Target Sheet");
-        sheet2.createRow(0).createCell(0).setCellValue("Target Cell");
-
-        cell = sheet.createRow(3).createCell(0);
-        cell.setCellValue("Worksheet Link");
-        link = helper.createHyperlink(HyperlinkType.DOCUMENT);
-        link.setAddress("'Target Sheet'!A1");
-        cell.setHyperlink(link);
-        cell.setCellStyle(hlink_style);
-
-        FileOutputStream out = new FileOutputStream("hssf-links.xls");
-        wb.write(out);
-        out.close();
-        wb.close();
+            //cell style for hyperlinks
+            //by default hyperlinks are blue and underlined
+            HSSFCellStyle hlink_style = wb.createCellStyle();
+            HSSFFont hlink_font = wb.createFont();
+            hlink_font.setUnderline(Font.U_SINGLE);
+            hlink_font.setColor(HSSFColorPredefined.BLUE.getIndex());
+            hlink_style.setFont(hlink_font);
+
+            HSSFCell cell;
+            HSSFSheet sheet = wb.createSheet("Hyperlinks");
+
+            //URL
+            cell = sheet.createRow(0).createCell(0);
+            cell.setCellValue("URL Link");
+            HSSFHyperlink link = helper.createHyperlink(HyperlinkType.URL);
+            link.setAddress("http://poi.apache.org/";);
+            cell.setHyperlink(link);
+            cell.setCellStyle(hlink_style);
+
+            //link to a file in the current directory
+            cell = sheet.createRow(1).createCell(0);
+            cell.setCellValue("File Link");
+            link = helper.createHyperlink(HyperlinkType.FILE);
+            link.setAddress("link1.xls");
+            cell.setHyperlink(link);
+            cell.setCellStyle(hlink_style);
+
+            //e-mail link
+            cell = sheet.createRow(2).createCell(0);
+            cell.setCellValue("Email Link");
+            link = helper.createHyperlink(HyperlinkType.EMAIL);
+            //note, if subject contains white spaces, make sure they are 
url-encoded
+            link.setAddress("mailto:[email protected]?subject=Hyperlinks";);
+            cell.setHyperlink(link);
+            cell.setCellStyle(hlink_style);
+
+            //link to a place in this workbook
+
+            //create a target sheet and cell
+            HSSFSheet sheet2 = wb.createSheet("Target Sheet");
+            sheet2.createRow(0).createCell(0).setCellValue("Target Cell");
+
+            cell = sheet.createRow(3).createCell(0);
+            cell.setCellValue("Worksheet Link");
+            link = helper.createHyperlink(HyperlinkType.DOCUMENT);
+            link.setAddress("'Target Sheet'!A1");
+            cell.setHyperlink(link);
+            cell.setCellStyle(hlink_style);
+
+            try (FileOutputStream out = new 
FileOutputStream("hssf-links.xls")) {
+                wb.write(out);
+            }
+        }
     }
 }

Modified: 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java?rev=1809354&r1=1809353&r2=1809354&view=diff
==============================================================================
--- 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java
 (original)
+++ 
poi/trunk/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java
 Fri Sep 22 21:16:09 2017
@@ -67,8 +67,7 @@ public class InCellLists {
      *                       the Excel spreadsheet file this code will create.
      */
     public void demonstrateMethodCalls(String outputFilename) throws 
IOException {
-        HSSFWorkbook workbook = new HSSFWorkbook();
-        try {
+        try (HSSFWorkbook workbook = new HSSFWorkbook()) {
             HSSFSheet sheet = workbook.createSheet("In Cell Lists");
             HSSFRow row = sheet.createRow(0);
 
@@ -89,7 +88,7 @@ public class InCellLists {
             this.listInCell(workbook, listItems, cell);
             // The row height and cell width are set here to ensure that the
             // list may be seen.
-            row.setHeight((short)1100);
+            row.setHeight((short) 1100);
             sheet.setColumnWidth(0, 9500);
 
             // Create a cell at A3 and insert a numbered list into that cell.
@@ -100,7 +99,7 @@ public class InCellLists {
             listItems.add("List Item Five.");
             listItems.add("List Item Six.");
             this.numberedListInCell(workbook, listItems, cell, 1, 2);
-            row.setHeight((short)1550);
+            row.setHeight((short) 1550);
 
             // Create a cell at A4 and insert a numbered list into that cell.
             // Note that a couple of items have been added to the listItems
@@ -112,7 +111,7 @@ public class InCellLists {
             listItems.add("List Item Nine.");
             listItems.add("List Item Ten.");
             this.bulletedListInCell(workbook, listItems, cell);
-            row.setHeight((short)2550);
+            row.setHeight((short) 2550);
 
             // Insert a plain, multi-level list into cell A5. Note that
             // the major difference here is that the list items are passed as
@@ -143,7 +142,7 @@ public class InCellLists {
             listItems.add("ML List Item Four - Sub Item Three.");
             multiLevelListItems.add(new MultiLevelListItem("List Item Four.", 
listItems));
             this.multiLevelListInCell(workbook, multiLevelListItems, cell);
-            row.setHeight((short)2800);
+            row.setHeight((short) 2800);
 
             // Insert a numbered multi-level list into cell A6. Note that the
             // same ArrayList as constructed for the above plain multi-level
@@ -151,8 +150,8 @@ public class InCellLists {
             row = sheet.createRow(5);
             cell = row.createCell(0);
             this.multiLevelNumberedListInCell(workbook, multiLevelListItems,
-                                              cell, 1, 1, 1, 2);
-            row.setHeight((short)2800);
+                    cell, 1, 1, 1, 2);
+            row.setHeight((short) 2800);
 
             // Insert a numbered multi-level list into cell A7. Note that the
             // same ArrayList as constructed for the plain multi-level list
@@ -160,31 +159,18 @@ public class InCellLists {
             row = sheet.createRow(6);
             cell = row.createCell(0);
             this.multiLevelBulletedListInCell(workbook, multiLevelListItems, 
cell);
-            row.setHeight((short)2800);
+            row.setHeight((short) 2800);
 
             // Save the completed workbook
-            FileOutputStream fos = new FileOutputStream(new 
File(outputFilename));
-            try {
+            try (FileOutputStream fos = new FileOutputStream(new 
File(outputFilename))) {
                 workbook.write(fos);
-            } finally {
-                fos.close();
             }
-        }
-        catch(FileNotFoundException fnfEx) {
-            System.out.println("Caught a: " + fnfEx.getClass().getName());
-            System.out.println("Message: " + fnfEx.getMessage());
-            System.out.println("Stacktrace follows...........");
-            fnfEx.printStackTrace(System.out);
-        }
-        catch(IOException ioEx) {
+        } catch (IOException ioEx) {
             System.out.println("Caught a: " + ioEx.getClass().getName());
             System.out.println("Message: " + ioEx.getMessage());
             System.out.println("Stacktrace follows...........");
             ioEx.printStackTrace(System.out);
         }
-        finally {
-            workbook.close();
-        }
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to