diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2021-05-21 22:32:09 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2021-05-21 22:32:09 +0000 |
commit | f21019db12ad2234d5681f49a0c5a40064fc2418 (patch) | |
tree | f3a00622b503797787d392260bc3f97a44b844ae /poi-examples/src | |
parent | 7eaca60a1a364ce6e232363d27823e971a992705 (diff) | |
download | poi-f21019db12ad2234d5681f49a0c5a40064fc2418.tar.gz poi-f21019db12ad2234d5681f49a0c5a40064fc2418.zip |
add forbidden-apis plugin to gradle builds
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1890090 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-examples/src')
3 files changed, 19 insertions, 18 deletions
diff --git a/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/InCellLists.java b/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/InCellLists.java index cfec4222d8..77282d980d 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/InCellLists.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/hssf/usermodel/InCellLists.java @@ -18,12 +18,13 @@ package org.apache.poi.examples.hssf.usermodel; -import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCellStyle; import org.apache.poi.hssf.usermodel.HSSFDataFormat; @@ -49,6 +50,8 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; */ @SuppressWarnings({"java:S106","java:S4823"}) public class InCellLists { + private static final Logger LOG = LogManager.getLogger(InCellLists.class); + // This character looks like a solid, black, loser case letter 'o' // positioned up from the base line of the text. @@ -65,7 +68,7 @@ public class InCellLists { * @param outputFilename A String that encapsulates the name of and path to * the Excel spreadsheet file this code will create. */ - public void demonstrateMethodCalls(String outputFilename) throws IOException { + public void demonstrateMethodCalls(String outputFilename) { try (HSSFWorkbook workbook = new HSSFWorkbook()) { HSSFSheet sheet = workbook.createSheet("In Cell Lists"); HSSFRow row = sheet.createRow(0); @@ -161,14 +164,11 @@ public class InCellLists { row.setHeight((short) 2800); // Save the completed workbook - try (FileOutputStream fos = new FileOutputStream(new File(outputFilename))) { + try (FileOutputStream fos = new FileOutputStream(outputFilename)) { workbook.write(fos); } } catch (IOException ioEx) { - System.out.println("Caught a: " + ioEx.getClass().getName()); - System.out.println("Message: " + ioEx.getMessage()); - System.out.println("Stacktrace follows..........."); - ioEx.printStackTrace(System.out); + LOG.atWarn().withThrowable(ioEx).log("Unexpected IOException"); } } @@ -496,10 +496,10 @@ public class InCellLists { * complex list structures descending through two, three or even more * levels. */ - public final class MultiLevelListItem { + public static final class MultiLevelListItem { - private String itemText; - private List<String> lowerLevelItems; + private final String itemText; + private final List<String> lowerLevelItems; /** * Create a new instance of the MultiLevelListItem class using the diff --git a/poi-examples/src/main/java/org/apache/poi/examples/ss/ToCSV.java b/poi-examples/src/main/java/org/apache/poi/examples/ss/ToCSV.java index c38709bbfc..75ea1c3499 100644 --- a/poi-examples/src/main/java/org/apache/poi/examples/ss/ToCSV.java +++ b/poi-examples/src/main/java/org/apache/poi/examples/ss/ToCSV.java @@ -28,6 +28,8 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.DataFormatter; @@ -132,6 +134,7 @@ import org.apache.poi.ss.usermodel.WorkbookFactory; */ @SuppressWarnings({"java:S106","java:S4823","java:S1192"}) public class ToCSV { + private static final Logger LOG = LogManager.getLogger(ToCSV.class); private Workbook workbook; private ArrayList<ArrayList<String>> csvData; @@ -691,10 +694,7 @@ public class ToCSV { // program. It should however, ideally be replaced with one or more // catch clauses optimised to handle more specific problems. catch(Exception ex) { - System.out.println("Caught an: " + ex.getClass().getName()); - System.out.println("Message: " + ex.getMessage()); - System.out.println("Stacktrace follows:....."); - ex.printStackTrace(System.out); + LOG.atWarn().withThrowable(ex).log("Unexpected exception"); converted = false; } diff --git a/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java b/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java index f21f512284..139b9115d3 100644 --- a/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java +++ b/poi-examples/src/test/java/org/apache/poi/integration/TestXLSX2CSV.java @@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.PrintStream; +import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; @@ -37,11 +38,11 @@ public class TestXLSX2CSV { private final UnsynchronizedByteArrayOutputStream errorBytes = new UnsynchronizedByteArrayOutputStream(); @BeforeEach - public void setUp() { + public void setUp() throws UnsupportedEncodingException { // remember and replace default error streams err = System.err; - PrintStream error = new PrintStream(errorBytes); + PrintStream error = new PrintStream(errorBytes, true, "UTF-8"); System.setErr(error); } @@ -77,7 +78,7 @@ public class TestXLSX2CSV { @Test public void testSampleFile() throws Exception { final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream(); - PrintStream out = new PrintStream(outputBytes); + PrintStream out = new PrintStream(outputBytes, true, "UTF-8"); // The package open is instantaneous, as it should be. try (OPCPackage p = OPCPackage.open(XSSFTestDataSamples.getSampleFile("sample.xlsx").getAbsolutePath(), PackageAccess.READ)) { @@ -96,7 +97,7 @@ public class TestXLSX2CSV { @Test public void testMinColumns() throws Exception { final UnsynchronizedByteArrayOutputStream outputBytes = new UnsynchronizedByteArrayOutputStream(); - PrintStream out = new PrintStream(outputBytes); + PrintStream out = new PrintStream(outputBytes, true, "UTF-8"); // The package open is instantaneous, as it should be. try (OPCPackage p = OPCPackage.open(XSSFTestDataSamples.getSampleFile("sample.xlsx").getAbsolutePath(), PackageAccess.READ)) { |