From: Nick Burch Date: Thu, 3 Jul 2014 05:45:21 +0000 (+0000) Subject: Now that XSSFWorkbook can be closed, the older path based constructor no longer needs... X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=f33843810a3730031259367e5c493230c87fc7ba;p=poi.git Now that XSSFWorkbook can be closed, the older path based constructor no longer needs to be deprecated #56537 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1607536 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 5d5068b12e..727989c2ed 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -38,6 +38,7 @@ import org.apache.poi.POIXMLDocument; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLException; import org.apache.poi.POIXMLProperties; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackagePart; @@ -236,44 +237,35 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, IterableOnce you have finished working with the Workbook, you should close + * the package by calling {@link #close()}, to avoid leaving file + * handles open. + * + *

Opening a XSSFWorkbook from a file has a lower memory footprint + * than opening from an InputStream + * + * @param file the file to open + */ + public XSSFWorkbook(File file) throws IOException, InvalidFormatException { + this(OPCPackage.open(file)); + } + /** * Constructs a XSSFWorkbook object given a file name. * - *

- * This constructor is deprecated since POI-3.8 because it does not close - * the underlying .zip file stream. In short, there are two ways to open a OPC package: - *

- *
    - *
  1. - * from file which leads to invoking java.util.zip.ZipFile(File file) - * deep in POI internals. - *
  2. - *
  3. - * from input stream in which case we first read everything into memory and - * then pass the data to ZipInputStream. - *
  4. - *
      - *

      - * It should be noted, that (2) uses quite a bit more memory than (1), which - * doesn't need to hold the whole zip file in memory, and can take advantage - * of native methods. - *

      - *

      - * To construct a workbook from file use the - * {@link #XSSFWorkbook(org.apache.poi.openxml4j.opc.OPCPackage)} constructor: - *

      
      -     *       OPCPackage pkg = OPCPackage.open(path);
      -     *       XSSFWorkbook wb = new XSSFWorkbook(pkg);
      -     *       // work with the wb object
      -     *       ......
      -     *       pkg.close(); // gracefully closes the underlying zip file
      -     *   
      - *

      + * + *

      Once you have finished working with the Workbook, you should close + * the package by calling {@link #close()}, to avoid leaving file + * handles open. + * + *

      Opening a XSSFWorkbook from a file has a lower memory footprint + * than opening from an InputStream * - * @param path the file name. - * @deprecated + * @param path the file name. */ - @Deprecated public XSSFWorkbook(String path) throws IOException { this(openPackage(path)); }