mirror of
https://github.com/apache/poi.git
synced 2026-02-27 20:40:08 +08:00
Close some streams/workbooks properly
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895624 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
811d4faf7b
commit
97abbdd6ab
@ -18,6 +18,7 @@
|
||||
package org.apache.poi.xssf.usermodel;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.poi.ooxml.POIXMLDocumentPart;
|
||||
import org.apache.poi.ooxml.POIXMLException;
|
||||
@ -65,13 +66,13 @@ public class XSSFPictureData extends POIXMLDocumentPart implements PictureData {
|
||||
* Construct XSSFPictureData from a package part
|
||||
*
|
||||
* @param part the package part holding the drawing data,
|
||||
*
|
||||
*
|
||||
* @since POI 3.14-Beta1
|
||||
*/
|
||||
protected XSSFPictureData(PackagePart part) {
|
||||
super(part);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the picture data as a byte array.
|
||||
* <p>
|
||||
@ -86,8 +87,8 @@ public class XSSFPictureData extends POIXMLDocumentPart implements PictureData {
|
||||
* @return the picture data.
|
||||
*/
|
||||
public byte[] getData() {
|
||||
try {
|
||||
return IOUtils.toByteArray(getPackagePart().getInputStream());
|
||||
try (InputStream inputStream = getPackagePart().getInputStream()) {
|
||||
return IOUtils.toByteArray(inputStream);
|
||||
} catch(IOException e) {
|
||||
throw new POIXMLException(e);
|
||||
}
|
||||
@ -116,7 +117,7 @@ public class XSSFPictureData extends POIXMLDocumentPart implements PictureData {
|
||||
}
|
||||
|
||||
/**
|
||||
* *PictureData objects store the actual content in the part directly without keeping a
|
||||
* *PictureData objects store the actual content in the part directly without keeping a
|
||||
* copy like all others therefore we need to handle them differently.
|
||||
*/
|
||||
@Override
|
||||
|
||||
@ -19,6 +19,7 @@ package org.apache.poi.ss.util;
|
||||
|
||||
import org.apache.poi.common.usermodel.HyperlinkType;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -30,6 +31,16 @@ public abstract class BaseTestCellUtilCopy {
|
||||
|
||||
protected Cell srcCell, destCell; //used for testCopyCellFrom_CellCopyPolicy
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() throws IOException {
|
||||
if (srcCell != null) {
|
||||
srcCell.getRow().getSheet().getWorkbook().close();
|
||||
}
|
||||
if (destCell != null) {
|
||||
destCell.getRow().getSheet().getWorkbook().close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void testCopyCellFrom_CellCopyPolicy_default() {
|
||||
setUp_testCopyCellFrom_CellCopyPolicy();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user