diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2016-12-18 22:03:31 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2016-12-18 22:03:31 +0000 |
commit | b8bfe77718d26887ddccc7be4f5332aafad9e287 (patch) | |
tree | df9350982cab011e51bf01db95def4b7a2e0fb61 /src/java | |
parent | 89699818195ddadb13f5e00961fd87c5d0046cb5 (diff) | |
download | poi-b8bfe77718d26887ddccc7be4f5332aafad9e287.tar.gz poi-b8bfe77718d26887ddccc7be4f5332aafad9e287.zip |
SonarQube fixes - close resources
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1774969 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
4 files changed, 29 insertions, 15 deletions
diff --git a/src/java/org/apache/poi/hssf/record/FilePassRecord.java b/src/java/org/apache/poi/hssf/record/FilePassRecord.java index ab941fad5f..5955e6d135 100644 --- a/src/java/org/apache/poi/hssf/record/FilePassRecord.java +++ b/src/java/org/apache/poi/hssf/record/FilePassRecord.java @@ -89,7 +89,7 @@ public final class FilePassRecord extends StandardRecord implements Cloneable { out.writeShort(encryptionType); byte data[] = new byte[1024]; - LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(data, 0); + LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(data, 0); // NOSONAR switch (encryptionInfo.getEncryptionMode()) { case xor: diff --git a/src/java/org/apache/poi/hssf/record/ObjRecord.java b/src/java/org/apache/poi/hssf/record/ObjRecord.java index 8eb4e03afc..5220f9cc07 100644 --- a/src/java/org/apache/poi/hssf/record/ObjRecord.java +++ b/src/java/org/apache/poi/hssf/record/ObjRecord.java @@ -176,7 +176,7 @@ public final class ObjRecord extends Record implements Cloneable { public int serialize(int offset, byte[] data) { int recSize = getRecordSize(); int dataSize = recSize - 4; - LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize); + LittleEndianByteArrayOutputStream out = new LittleEndianByteArrayOutputStream(data, offset, recSize); // NOSONAR out.writeShort(sid); out.writeShort(dataSize); diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 7c50b6643d..2f3be03de9 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -435,8 +435,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss private void convertLabelRecords(List<Record> records, int offset) { - if (log.check( POILogger.DEBUG )) - log.log(POILogger.DEBUG, "convertLabelRecords called"); + if (log.check( POILogger.DEBUG )) { + log.log(POILogger.DEBUG, "convertLabelRecords called"); + } for (int k = offset; k < records.size(); k++) { Record rec = records.get(k); @@ -457,8 +458,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss records.add(k, newrec); } } - if (log.check( POILogger.DEBUG )) - log.log(POILogger.DEBUG, "convertLabelRecords exit"); + if (log.check( POILogger.DEBUG )) { + log.log(POILogger.DEBUG, "convertLabelRecords exit"); + } } /** @@ -918,8 +920,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss throw new IllegalArgumentException("sheetName must not be null"); } - if (workbook.doesContainsSheetName( sheetname, _sheets.size() )) + if (workbook.doesContainsSheetName( sheetname, _sheets.size() )) { throw new IllegalArgumentException("The workbook already contains a sheet named '" + sheetname + "'"); + } HSSFSheet sheet = new HSSFSheet(this); @@ -1190,7 +1193,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss short numberOfFonts = getNumberOfFonts(); for (short i=0; i<=numberOfFonts; i++) { // Remember - there is no 4! - if(i == 4) continue; + if(i == 4) { + continue; + } HSSFFont hssfFont = getFontAt(i); if (hssfFont.getBoldweight() == boldWeight @@ -1219,7 +1224,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss short numberOfFonts = getNumberOfFonts(); for (short i=0; i<=numberOfFonts; i++) { // Remember - there is no 4! - if(i == 4) continue; + if(i == 4) { + continue; + } HSSFFont hssfFont = getFontAt(i); if (hssfFont.getBold() == bold @@ -1256,7 +1263,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss */ @Override public HSSFFont getFontAt(short idx) { - if(fonts == null) fonts = new HashMap<Short, HSSFFont>(); + if(fonts == null) { + fonts = new HashMap<Short, HSSFFont>(); + } // So we don't confuse users, give them back // the same object every time, but create @@ -1553,8 +1562,8 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss return; } - LittleEndianByteArrayInputStream plain = new LittleEndianByteArrayInputStream(buf, 0); - LittleEndianByteArrayOutputStream leos = new LittleEndianByteArrayOutputStream(buf, 0); + LittleEndianByteArrayInputStream plain = new LittleEndianByteArrayInputStream(buf, 0); // NOSONAR + LittleEndianByteArrayOutputStream leos = new LittleEndianByteArrayOutputStream(buf, 0); // NOSONAR Encryptor enc = fpr.getEncryptionInfo().getEncryptor(); enc.setChunkSize(Biff8DecryptingStream.RC4_REKEYING_INTERVAL); byte tmp[] = new byte[1024]; @@ -1796,8 +1805,9 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss */ @Override public HSSFDataFormat createDataFormat() { - if (formatter == null) + if (formatter == null) { formatter = new HSSFDataFormat(workbook); + } return formatter; } @@ -1864,10 +1874,11 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss List<EscherRecord> escherRecords = r.getEscherRecords(); PrintWriter w = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset())); for (EscherRecord escherRecord : escherRecords) { - if (fat) + if (fat) { System.out.println(escherRecord.toString()); - else + } else { escherRecord.display(w, 0); + } } w.flush(); } @@ -2246,6 +2257,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss /** * @deprecated POI 3.16 beta 1. use {@link POIDocument#getDirectory()} instead */ + @Deprecated @Removal(version="3.18") public DirectoryNode getRootDirectory(){ return getDirectory(); diff --git a/src/java/org/apache/poi/poifs/dev/POIFSLister.java b/src/java/org/apache/poi/poifs/dev/POIFSLister.java index 357773a632..cce7080c2a 100644 --- a/src/java/org/apache/poi/poifs/dev/POIFSLister.java +++ b/src/java/org/apache/poi/poifs/dev/POIFSLister.java @@ -65,11 +65,13 @@ public class POIFSLister { public static void viewFile(final String filename, boolean withSizes) throws IOException { NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(filename)); displayDirectory(fs.getRoot(), "", withSizes); + fs.close(); } public static void viewFileOld(final String filename, boolean withSizes) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filename)); displayDirectory(fs.getRoot(), "", withSizes); + fs.close(); } public static void displayDirectory(DirectoryNode dir, String indent, boolean withSizes) { |