mirror of https://github.com/apache/poi.git
bug 59893: close open resources to prevent leaks
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1783362 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
853bad0371
commit
94279c4cc7
|
@ -165,11 +165,14 @@ public class TestDecryptor {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test58616() throws IOException, GeneralSecurityException {
|
public void test58616() throws IOException, GeneralSecurityException {
|
||||||
POIFSFileSystem pfs = new POIFSFileSystem(new FileInputStream(XSSFTestDataSamples.getSampleFile("58616.xlsx")));
|
FileInputStream fis = new FileInputStream(XSSFTestDataSamples.getSampleFile("58616.xlsx"));
|
||||||
|
POIFSFileSystem pfs = new POIFSFileSystem(fis);
|
||||||
EncryptionInfo info = new EncryptionInfo(pfs);
|
EncryptionInfo info = new EncryptionInfo(pfs);
|
||||||
Decryptor dec = Decryptor.getInstance(info);
|
Decryptor dec = Decryptor.getInstance(info);
|
||||||
//dec.verifyPassword(null);
|
//dec.verifyPassword(null);
|
||||||
dec.getDataStream(pfs);
|
dec.getDataStream(pfs);
|
||||||
|
pfs.close();
|
||||||
|
fis.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -151,7 +151,8 @@ public class TestEncryptor {
|
||||||
|
|
||||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
fs.writeFilesystem(bos);
|
fs.writeFilesystem(bos);
|
||||||
|
fs.close();
|
||||||
|
|
||||||
nfs = new NPOIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
|
nfs = new NPOIFSFileSystem(new ByteArrayInputStream(bos.toByteArray()));
|
||||||
infoActual = new EncryptionInfo(nfs.getRoot());
|
infoActual = new EncryptionInfo(nfs.getRoot());
|
||||||
Decryptor decActual = Decryptor.getInstance(infoActual);
|
Decryptor decActual = Decryptor.getInstance(infoActual);
|
||||||
|
@ -297,11 +298,13 @@ public class TestEncryptor {
|
||||||
enc.confirmPassword("password");
|
enc.confirmPassword("password");
|
||||||
OutputStream os = enc.getDataStream(fs);
|
OutputStream os = enc.getDataStream(fs);
|
||||||
pkg.save(os);
|
pkg.save(os);
|
||||||
|
os.close();
|
||||||
pkg.revert();
|
pkg.revert();
|
||||||
|
|
||||||
// Save the resulting OLE2 document, and re-open it
|
// Save the resulting OLE2 document, and re-open it
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
fs.writeFilesystem(baos);
|
fs.writeFilesystem(baos);
|
||||||
|
fs.close();
|
||||||
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||||
NPOIFSFileSystem inpFS = new NPOIFSFileSystem(bais);
|
NPOIFSFileSystem inpFS = new NPOIFSFileSystem(bais);
|
||||||
|
@ -318,6 +321,9 @@ public class TestEncryptor {
|
||||||
assertNotNull(inpPkg.getPackageProperties());
|
assertNotNull(inpPkg.getPackageProperties());
|
||||||
assertNotNull(inpPkg.getPackageProperties().getLanguageProperty());
|
assertNotNull(inpPkg.getPackageProperties().getLanguageProperty());
|
||||||
assertNull(inpPkg.getPackageProperties().getLanguageProperty().getValue());
|
assertNull(inpPkg.getPackageProperties().getLanguageProperty().getValue());
|
||||||
|
|
||||||
|
inpPkg.close();
|
||||||
|
inpFS.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -340,7 +346,8 @@ public class TestEncryptor {
|
||||||
assertTrue(b);
|
assertTrue(b);
|
||||||
|
|
||||||
// do some strange things with it ;)
|
// do some strange things with it ;)
|
||||||
XWPFDocument docx = new XWPFDocument(d.getDataStream(fs));
|
InputStream docIS = d.getDataStream(fs);
|
||||||
|
XWPFDocument docx = new XWPFDocument(docIS);
|
||||||
docx.getParagraphArray(0).insertNewRun(0).setText("POI was here! All your base are belong to us!");
|
docx.getParagraphArray(0).insertNewRun(0).setText("POI was here! All your base are belong to us!");
|
||||||
docx.getParagraphArray(0).insertNewRun(1).addBreak();
|
docx.getParagraphArray(0).insertNewRun(1).addBreak();
|
||||||
|
|
||||||
|
@ -348,6 +355,8 @@ public class TestEncryptor {
|
||||||
Encryptor e = encInfo.getEncryptor();
|
Encryptor e = encInfo.getEncryptor();
|
||||||
e.confirmPassword("AYBABTU");
|
e.confirmPassword("AYBABTU");
|
||||||
docx.write(e.getDataStream(fs));
|
docx.write(e.getDataStream(fs));
|
||||||
|
docx.close();
|
||||||
|
docIS.close();
|
||||||
|
|
||||||
docx.close();
|
docx.close();
|
||||||
fs.close();
|
fs.close();
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class ReaderWriter
|
||||||
private final DirectoryEntry root;
|
private final DirectoryEntry root;
|
||||||
|
|
||||||
// keys are DocumentDescriptors, values are byte[]s
|
// keys are DocumentDescriptors, values are byte[]s
|
||||||
private final Map<DocumentDescriptor, byte[]> dataMap;
|
private final Map<DocumentDescriptor, byte[]> dataMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor ReaderWriter
|
* Constructor ReaderWriter
|
||||||
|
@ -93,6 +93,8 @@ public class ReaderWriter
|
||||||
|
|
||||||
filesystem.writeFilesystem(ostream);
|
filesystem.writeFilesystem(ostream);
|
||||||
ostream.close();
|
ostream.close();
|
||||||
|
|
||||||
|
filesystem.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue