diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2016-03-21 00:14:21 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2016-03-21 00:14:21 +0000 |
commit | fe653de0e656256db8bcbef399116d598355b5bc (patch) | |
tree | 2b934b78fea768a14dcc54e537260e89f5aebaf6 /src/java | |
parent | e826364ac22efb471eb0f720040a438cabf00027 (diff) | |
download | poi-fe653de0e656256db8bcbef399116d598355b5bc.tar.gz poi-fe653de0e656256db8bcbef399116d598355b5bc.zip |
fix eclipse warnings
close resources
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1735912 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
7 files changed, 32 insertions, 27 deletions
diff --git a/src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java b/src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java index 4d6acf9627..256d0230f7 100644 --- a/src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java +++ b/src/java/org/apache/poi/hssf/dev/BiffDrawingToXml.java @@ -32,7 +32,6 @@ import org.apache.poi.hssf.model.InternalWorkbook; import org.apache.poi.hssf.record.DrawingGroupRecord;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
-import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.StringUtil;
/**
@@ -133,16 +132,15 @@ public class BiffDrawingToXml { }
public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {
- NPOIFSFileSystem fs = new NPOIFSFileSystem(xlsWorkbook);
- HSSFWorkbook workbook = new HSSFWorkbook(fs);
+ HSSFWorkbook workbook = new HSSFWorkbook(xlsWorkbook);
InternalWorkbook internalWorkbook = workbook.getInternalWorkbook();
DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);
- r.decode();
StringBuilder builder = new StringBuilder();
builder.append("<workbook>\n");
String tab = "\t";
- if (!excludeWorkbookRecords) {
+ if (!excludeWorkbookRecords && r != null) {
+ r.decode();
List<EscherRecord> escherRecords = r.getEscherRecords();
for (EscherRecord record : escherRecords) {
builder.append(record.toXml(tab));
@@ -160,6 +158,7 @@ public class BiffDrawingToXml { builder.append("</workbook>\n");
fos.write(builder.toString().getBytes(StringUtil.UTF8));
fos.close();
+ workbook.close();
}
}
diff --git a/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java b/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java index a2d3d6f0e1..5fb39d9216 100644 --- a/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java +++ b/src/java/org/apache/poi/poifs/crypt/binaryrc4/BinaryRC4Decryptor.java @@ -116,6 +116,7 @@ public class BinaryRC4Decryptor extends Decryptor { return skey;
}
+ @SuppressWarnings("resource")
public InputStream getDataStream(DirectoryNode dir) throws IOException,
GeneralSecurityException {
DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY);
diff --git a/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java b/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java index e3f8414395..09f82e5a6a 100644 --- a/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java +++ b/src/java/org/apache/poi/poifs/crypt/cryptoapi/CryptoAPIDecryptor.java @@ -57,13 +57,13 @@ public class CryptoAPIDecryptor extends Decryptor { Cipher cipher;
byte oneByte[] = { 0 };
- public void seek(int pos) {
- if (pos > count) {
- throw new ArrayIndexOutOfBoundsException(pos);
+ public void seek(int newpos) {
+ if (newpos > count) {
+ throw new ArrayIndexOutOfBoundsException(newpos);
}
- this.pos = pos;
- mark = pos;
+ this.pos = newpos;
+ mark = newpos;
}
public void setBlock(int block) throws GeneralSecurityException {
@@ -233,9 +233,11 @@ public class CryptoAPIDecryptor extends Decryptor { sbis.setBlock(entry.block);
InputStream is = new BoundedInputStream(sbis, entry.streamSize);
fsOut.createDocument(is, entry.streamName);
+ is.close();
}
leis.close();
+ sbis.close();
sbis = null;
bos.reset();
fsOut.writeFilesystem(bos);
diff --git a/src/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java b/src/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java index 00d2f77e33..a6d6dbfa0b 100644 --- a/src/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java +++ b/src/java/org/apache/poi/poifs/crypt/standard/StandardDecryptor.java @@ -122,6 +122,7 @@ public class StandardDecryptor extends Decryptor { return CryptoFunctions.getCipher(key, em.getCipherAlgorithm(), cm, null, Cipher.DECRYPT_MODE); } + @SuppressWarnings("resource") public InputStream getDataStream(DirectoryNode dir) throws IOException { DocumentInputStream dis = dir.createDocumentInputStream(DEFAULT_POIFS_ENTRY); diff --git a/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java b/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java index ae6304fbb5..b782d83299 100644 --- a/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java +++ b/src/java/org/apache/poi/poifs/crypt/standard/StandardEncryptor.java @@ -123,14 +123,9 @@ public class StandardEncryptor extends Encryptor { protected long countBytes;
protected final File fileOut;
protected final DirectoryNode dir;
-
- protected StandardCipherOutputStream(DirectoryNode dir) throws IOException {
- super(null);
-
- this.dir = dir;
- fileOut = TempFile.createTempFile("encrypted_package", "crypt");
- FileOutputStream rawStream = new FileOutputStream(fileOut);
+ @SuppressWarnings("resource")
+ private StandardCipherOutputStream(DirectoryNode dir, File fileOut) throws IOException {
// although not documented, we need the same padding as with agile encryption
// and instead of calculating the missing bytes for the block size ourselves
// we leave it up to the CipherOutputStream, which generates/saves them on close()
@@ -141,9 +136,15 @@ public class StandardEncryptor extends Encryptor { // KeyData.blockSize value. Any padding bytes can be used. Note that the StreamSize
// field of the EncryptedPackage field specifies the number of bytes of
// unencrypted data as specified in section 2.3.4.4.
- CipherOutputStream cryptStream = new CipherOutputStream(rawStream, getCipher(getSecretKey(), "PKCS5Padding"));
-
- this.out = cryptStream;
+ super(
+ new CipherOutputStream(new FileOutputStream(fileOut), getCipher(getSecretKey(), "PKCS5Padding"))
+ );
+ this.fileOut = fileOut;
+ this.dir = dir;
+ }
+
+ protected StandardCipherOutputStream(DirectoryNode dir) throws IOException {
+ this(dir, TempFile.createTempFile("encrypted_package", "crypt"));
}
@Override
diff --git a/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java b/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java index a288709185..439f47e761 100644 --- a/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java +++ b/src/java/org/apache/poi/poifs/eventfilesystem/POIFSReader.java @@ -212,13 +212,13 @@ public class POIFSReader private void processProperties(final BlockList small_blocks, final BlockList big_blocks, - final Iterator properties, + final Iterator<Property> properties, final POIFSDocumentPath path) throws IOException { while (properties.hasNext()) { - Property property = ( Property ) properties.next(); + Property property = properties.next(); String name = property.getName(); if (property.isDirectory()) @@ -235,8 +235,8 @@ public class POIFSReader } else { - int startBlock = property.getStartBlock(); - Iterator listeners = registry.getListeners(path, name); + int startBlock = property.getStartBlock(); + Iterator<POIFSReaderListener> listeners = registry.getListeners(path, name); if (listeners.hasNext()) { @@ -257,8 +257,7 @@ public class POIFSReader } while (listeners.hasNext()) { - POIFSReaderListener listener = - ( POIFSReaderListener ) listeners.next(); + POIFSReaderListener listener = listeners.next(); listener.processPOIFSReaderEvent( new POIFSReaderEvent( @@ -303,6 +302,7 @@ public class POIFSReader public void processPOIFSReaderEvent(final POIFSReaderEvent event) { + @SuppressWarnings("resource") DocumentInputStream istream = event.getStream(); POIFSDocumentPath path = event.getPath(); String name = event.getName(); diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java index ab8d905041..972780a060 100644 --- a/src/java/org/apache/poi/ss/util/CellUtil.java +++ b/src/java/org/apache/poi/ss/util/CellUtil.java @@ -205,7 +205,8 @@ public final class CellUtil { * @since POI 3.14 beta 2 */ public static void setCellStyleProperties(Cell cell, Map<String, Object> properties) { - Workbook workbook = cell.getSheet().getWorkbook(); + @SuppressWarnings("resource") + Workbook workbook = cell.getSheet().getWorkbook(); CellStyle originalStyle = cell.getCellStyle(); CellStyle newStyle = null; Map<String, Object> values = getFormatProperties(originalStyle); |