You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2017/11/23 20:03:26 UTC
svn commit: r1816189 - in /poi/trunk/src:
ooxml/java/org/apache/poi/poifs/crypt/temp/
ooxml/java/org/apache/poi/ss/usermodel/
ooxml/java/org/apache/poi/xssf/eventusermodel/
ooxml/java/org/apache/poi/xssf/usermodel/
scratchpad/src/org/apache/poi/hemf/re...
Author: fanningpj
Date: Thu Nov 23 20:03:25 2017
New Revision: 1816189
URL: http://svn.apache.org/viewvc?rev=1816189&view=rev
Log:
use try with resources in examples
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java
poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java
poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/HemfText.java
poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java?rev=1816189&r1=1816188&r2=1816189&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/poifs/crypt/temp/SXSSFWorkbookWithCustomZipEntrySource.java Thu Nov 23 20:03:25 2017
@@ -46,11 +46,8 @@ public class SXSSFWorkbookWithCustomZipE
EncryptedTempData tempData = new EncryptedTempData();
ZipEntrySource source = null;
try {
- OutputStream os = tempData.getOutputStream();
- try {
+ try (OutputStream os = tempData.getOutputStream()) {
getXSSFWorkbook().write(os);
- } finally {
- IOUtils.closeQuietly(os);
}
// provide ZipEntrySource to poi which decrypts on the fly
source = AesZipFileZipEntrySource.createZipEntrySource(tempData.getInputStream());
Modified: poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java?rev=1816189&r1=1816188&r2=1816189&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/ss/usermodel/WorkbookFactory.java Thu Nov 23 20:03:25 2017
@@ -250,15 +250,8 @@ public class WorkbookFactory {
throw new FileNotFoundException(file.toString());
}
- try {
- NPOIFSFileSystem fs = new NPOIFSFileSystem(file, readOnly);
- try {
- return create(fs, password);
- } catch (RuntimeException e) {
- // ensure that the file-handle is closed again
- IOUtils.closeQuietly(fs);
- throw e;
- }
+ try (NPOIFSFileSystem fs = new NPOIFSFileSystem(file, readOnly)) {
+ return create(fs, password);
} catch(OfficeXmlFileException e) {
// opening as .xls failed => try opening as .xlsx
OPCPackage pkg = OPCPackage.open(file, readOnly ? PackageAccess.READ : PackageAccess.READ_WRITE); // NOSONAR
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java?rev=1816189&r1=1816188&r2=1816189&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java Thu Nov 23 20:03:25 2017
@@ -87,14 +87,10 @@ public class XSSFBReader extends XSSFRea
* @throws IOException when there's a problem with the workbook part's stream
*/
public String getAbsPathMetadata() throws IOException {
- InputStream is = null;
- try {
- is = workbookPart.getInputStream();
- PathExtractor p = new PathExtractor(workbookPart.getInputStream());
+ try (InputStream is = workbookPart.getInputStream()) {
+ PathExtractor p = new PathExtractor(is);
p.parse();
return p.getPath();
- } finally {
- IOUtils.closeQuietly(is);
}
}
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java?rev=1816189&r1=1816188&r2=1816189&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFObjectData.java Thu Nov 23 20:03:25 2017
@@ -171,14 +171,9 @@ public class XSSFObjectData extends XSSF
}
@Override
- @SuppressWarnings("resource")
public DirectoryEntry getDirectory() throws IOException {
- InputStream is = null;
- try {
- is = getObjectPart().getInputStream();
+ try (InputStream is = getObjectPart().getInputStream()) {
return new POIFSFileSystem(is).getRoot();
- } finally {
- IOUtils.closeQuietly(is);
}
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/HemfText.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/HemfText.java?rev=1816189&r1=1816188&r2=1816189&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/HemfText.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hemf/record/HemfText.java Thu Nov 23 20:03:25 2017
@@ -230,14 +230,10 @@ public class HemfText {
String getText(Charset charset) throws IOException {
StringBuilder sb = new StringBuilder();
- Reader r = null;
- try {
- r = new InputStreamReader(new ByteArrayInputStream(rawTextBytes), charset);
+ try (Reader r = new InputStreamReader(new ByteArrayInputStream(rawTextBytes), charset)) {
for (int i = 0; i < numChars; i++) {
sb.appendCodePoint(readCodePoint(r));
}
- } finally {
- IOUtils.closeQuietly(r);
}
return sb.toString();
}
Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java?rev=1816189&r1=1816188&r2=1816189&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java (original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java Thu Nov 23 20:03:25 2017
@@ -179,10 +179,8 @@ public class HSLFSlideShowEncrypted impl
Decryptor dec = getEncryptionInfo().getDecryptor();
dec.setChunkSize(-1);
- LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream(docstream, offset); // NOSONAR
- ChunkedCipherInputStream ccis = null;
- try {
- ccis = (ChunkedCipherInputStream)dec.getDataStream(lei, docstream.length-offset, 0);
+ try (LittleEndianByteArrayInputStream lei = new LittleEndianByteArrayInputStream(docstream, offset);
+ ChunkedCipherInputStream ccis = (ChunkedCipherInputStream)dec.getDataStream(lei, docstream.length-offset, 0)) {
ccis.initCipherForBlock(persistId);
// decrypt header and read length to be decrypted
@@ -193,9 +191,6 @@ public class HSLFSlideShowEncrypted impl
} catch (Exception e) {
throw new EncryptedPowerPointFileException(e);
- } finally {
- IOUtils.closeQuietly(ccis);
- IOUtils.closeQuietly(lei);
}
}
@@ -288,10 +283,9 @@ public class HSLFSlideShowEncrypted impl
return;
}
- LittleEndianByteArrayOutputStream los = new LittleEndianByteArrayOutputStream(pictstream, offset); // NOSONAR
ChunkedCipherOutputStream ccos = null;
- try {
+ try (LittleEndianByteArrayOutputStream los = new LittleEndianByteArrayOutputStream(pictstream, offset)) {
Encryptor enc = getEncryptionInfo().getEncryptor();
enc.setChunkSize(-1);
ccos = enc.getDataStream(los, 0);
@@ -362,7 +356,6 @@ public class HSLFSlideShowEncrypted impl
throw new EncryptedPowerPointFileException(e);
} finally {
IOUtils.closeQuietly(ccos);
- IOUtils.closeQuietly(los);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org