diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2016-06-24 22:04:12 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2016-06-24 22:04:12 +0000 |
commit | f0a56b51d3610b64eb3cf93cae9c6ff220cd434d (patch) | |
tree | 66901e969589e8f82f4cf46fb6692ff216f3946a /src/examples | |
parent | b849a0c1623e74751302534f92fa8aac24fd1961 (diff) | |
download | poi-f0a56b51d3610b64eb3cf93cae9c6ff220cd434d.tar.gz poi-f0a56b51d3610b64eb3cf93cae9c6ff220cd434d.zip |
Sonar fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1750171 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/examples')
3 files changed, 34 insertions, 24 deletions
diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java index 9294b5babc..27f168e31e 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/HSSFReadWrite.java @@ -30,6 +30,7 @@ import org.apache.poi.hssf.usermodel.HSSFRichTextString; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.util.CellRangeAddress; /** @@ -69,13 +70,13 @@ public final class HSSFReadWrite { f.setFontHeightInPoints((short) 12); f.setColor((short) 0xA); - f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + f.setBold(true); f2.setFontHeightInPoints((short) 10); f2.setColor((short) 0xf); - f2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); + f2.setBold(true); cs.setFont(f); cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); - cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN); + cs2.setBorderBottom(BorderStyle.THIN); cs2.setFillPattern((short) 1); // fill w fg cs2.setFillForegroundColor((short) 0xA); cs2.setFont(f2); @@ -107,7 +108,7 @@ public final class HSSFReadWrite { rownum++; rownum++; HSSFRow r = s.createRow(rownum); - cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK); + cs3.setBorderBottom(BorderStyle.THICK); for (int cellnum = 0; cellnum < 50; cellnum++) { HSSFCell c = r.createCell(cellnum); c.setCellStyle(cs3); @@ -123,8 +124,11 @@ public final class HSSFReadWrite { // end deleted sheet FileOutputStream out = new FileOutputStream(outputFilename); - wb.write(out); - out.close(); + try { + wb.write(out); + } finally { + out.close(); + } wb.close(); } diff --git a/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java b/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java index 1230449d71..ace1ef3a98 100644 --- a/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java +++ b/src/examples/src/org/apache/poi/hssf/usermodel/examples/InCellLists.java @@ -71,8 +71,6 @@ public class InCellLists { HSSFSheet sheet = null;
HSSFRow row = null;
HSSFCell cell = null;
- File outputFile = null;
- FileOutputStream fos = null;
ArrayList<MultiLevelListItem> multiLevelListItems = null;
ArrayList<String> listItems = null;
try {
@@ -170,9 +168,12 @@ public class InCellLists { row.setHeight((short)2800);
// Save the completed workbook
- outputFile = new File(outputFilename);
- fos = new FileOutputStream(outputFile);
- workbook.write(fos);
+ FileOutputStream fos = new FileOutputStream(new File(outputFilename));
+ try {
+ workbook.write(fos);
+ } finally {
+ fos.close();
+ }
}
catch(FileNotFoundException fnfEx) {
System.out.println("Caught a: " + fnfEx.getClass().getName());
@@ -190,9 +191,6 @@ public class InCellLists { if (workbook != null) {
workbook.close();
}
- if (fos != null) {
- fos.close();
- }
}
}
diff --git a/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java b/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java index eb7532c7b4..0403bc7952 100644 --- a/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java +++ b/src/examples/src/org/apache/poi/ss/examples/SSPerformanceTest.java @@ -18,21 +18,27 @@ */ package org.apache.poi.ss.examples; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.ss.util.CellReference; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; -import org.apache.poi.xssf.streaming.SXSSFWorkbook; - import java.io.FileOutputStream; import java.io.IOException; import java.util.Calendar; import java.util.HashMap; import java.util.Map; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellStyle; +import org.apache.poi.ss.usermodel.Font; +import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.util.CellRangeAddress; +import org.apache.poi.ss.util.CellReference; +import org.apache.poi.xssf.streaming.SXSSFWorkbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + public class SSPerformanceTest { - public static void main(String[] args) { + public static void main(String[] args) throws IOException { if (args.length != 4) usage("need four command arguments"); String type = args[0]; @@ -52,6 +58,8 @@ public class SSPerformanceTest { } long timeFinished = System.currentTimeMillis(); System.out.println("Elapsed " + (timeFinished-timeStarted)/1000 + " seconds"); + + workBook.close(); } private static void addContent(Workbook workBook, boolean isHType, int rows, int cols) { @@ -147,7 +155,7 @@ public class SSPerformanceTest { Font headerFont = wb.createFont(); headerFont.setFontHeightInPoints((short) 14); - headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD); + headerFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); @@ -159,7 +167,7 @@ public class SSPerformanceTest { Font monthFont = wb.createFont(); monthFont.setFontHeightInPoints((short)12); monthFont.setColor(IndexedColors.RED.getIndex()); - monthFont.setBoldweight(Font.BOLDWEIGHT_BOLD); + monthFont.setBold(true); style = wb.createCellStyle(); style.setAlignment(CellStyle.ALIGN_CENTER); style.setVerticalAlignment(CellStyle.VERTICAL_CENTER); |