import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.InvalidOperationException;
-import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
import org.apache.poi.openxml4j.exceptions.PartAlreadyExistsException;
import org.apache.poi.openxml4j.opc.internal.ContentType;
* @throws InvalidFormatException
* If the specified file doesn't exist, and a parsing error
* occur.
- * @throws InvalidOperationException
+ * @throws InvalidOperationException If the zip file cannot be opened.
+ * @throws InvalidFormatException if the package is not valid.
*/
public static OPCPackage open(String path, PackageAccess access)
throws InvalidFormatException, InvalidOperationException {
success = true;
} finally {
if (! success) {
- try {
- pack.close();
- } catch (final IOException e) {
- throw new InvalidOperationException("Could not close OPCPackage while cleaning up", e);
- }
+ IOUtils.closeQuietly(pack);
}
}
}
return pkg;
}
- /**
- * Configure the package.
- *
- * @param pkg
- */
private static void configurePackage(OPCPackage pkg) {
try {
// Content type manager
* (PackageAccess.Write). This method is call when other methods need write
* right.
*
- * @throws InvalidOperationException
- * Throws if a read operation is done on a write only package.
+ * @throws InvalidOperationException if a read operation is done on a write only package.
* @see org.apache.poi.openxml4j.opc.PackageAccess
*/
void throwExceptionIfWriteOnly() throws InvalidOperationException {
* Compliance with Rule M4.1, and ignore all others silently too.
*
* @return All this package's parts.
+ * @throws InvalidFormatException if the package is not valid.
*/
public ArrayList<PackagePart> getParts() throws InvalidFormatException {
throwExceptionIfWriteOnly();
* @param part
* The part to add (or replace).
* @return The part added to the package, the same as the one specified.
- * @throws InvalidFormatException
+ * @throws InvalidOperationException
* If rule M1.12 is not verified : Packages shall not contain
* equivalent part names and package implementers shall neither
* create nor recognize packages with equivalent part names.
* Retrieves all package relationships.
*
* @return All package relationships of this package.
- * @throws OpenXML4JException
+ * @throws InvalidOperationException if a read operation is done on a write only package.
* @see #getRelationshipsHelper(String)
*/
@Override
* The path of the file to open or create.
* @param access
* The package access mode.
- * @throws InvalidOperationException
+ * @throws InvalidOperationException If the zip file cannot be opened.
*/
ZipPackage(String path, PackageAccess access) throws InvalidOperationException {
this(new File(path), access);
* The file to open or create.
* @param access
* The package access mode.
- * @throws InvalidOperationException
+ * @throws InvalidOperationException If the zip file cannot be opened.
*/
ZipPackage(File file, PackageAccess access) throws InvalidOperationException {
super(access);
* list is not empty, it will be emptied.
*
* @return All parts contain in this package.
- * @throws InvalidFormatException
- * Throws if the package is not valid.
+ * @throws InvalidFormatException if the package is not valid.
*/
@Override
protected PackagePart[] getPartsImpl() throws InvalidFormatException {