From: Dominik Stadler Date: Thu, 8 Feb 2018 19:34:16 +0000 (+0000) Subject: Various smaller adjustments: Remove filename in test, remove unused parameters, fix... X-Git-Tag: REL_4_0_0_FINAL~256 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=21e5140462255224d9261a7575e89b35255ec0ac;p=poi.git Various smaller adjustments: Remove filename in test, remove unused parameters, fix a few simple typos in JavaDoc and add more JavaDoc and some more tests git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1823595 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/ss/usermodel/Sheet.java b/src/java/org/apache/poi/ss/usermodel/Sheet.java index 2d77479677..7e3eb3c574 100644 --- a/src/java/org/apache/poi/ss/usermodel/Sheet.java +++ b/src/java/org/apache/poi/ss/usermodel/Sheet.java @@ -110,7 +110,7 @@ public interface Sheet extends Iterable { * method will include such rows and thus the returned value might be higher * than expected! * - * @return last row contained n this sheet (0-based) + * @return last row contained on this sheet (0-based) */ int getLastRowNum(); @@ -118,7 +118,7 @@ public interface Sheet extends Iterable { * Get the visibility state for a given column * * @param columnIndex - the column to get (0-based) - * @param hidden - the visiblity state of the column + * @param hidden - the visibility state of the column */ void setColumnHidden(int columnIndex, boolean hidden); @@ -205,7 +205,7 @@ public interface Sheet extends Iterable { *

* Please note, that this method works correctly only for workbooks * with the default font size (Arial 10pt for .xls and Calibri 11pt for .xlsx). - * If the default font is changed the column width can be streched + * If the default font is changed the column width can be stretched *

* * @param columnIndex - the column to set (0-based) @@ -384,7 +384,7 @@ public interface Sheet extends Iterable { * evaluation in POI is not possible. *

* - * To force recalcuation of formulas in the entire workbook + * To force recalculation of formulas in the entire workbook * use {@link Workbook#setForceFormulaRecalculation(boolean)} instead. * * @param value true if the application will perform a full recalculation of @@ -719,7 +719,7 @@ public interface Sheet extends Iterable { *

* If both colSplit and rowSplit are zero then the existing freeze pane is removed *

- * @param colSplit Horizonatal position of split. + * @param colSplit Horizontal position of split. * @param rowSplit Vertical position of split. * @param leftmostColumn Left column visible in right pane. * @param topRow Top row visible in bottom pane @@ -731,14 +731,14 @@ public interface Sheet extends Iterable { *

* If both colSplit and rowSplit are zero then the existing freeze pane is removed *

- * @param colSplit Horizonatal position of split. + * @param colSplit Horizontal position of split. * @param rowSplit Vertical position of split. */ void createFreezePane(int colSplit, int rowSplit); /** * Creates a split pane. Any existing freezepane or split pane is overwritten. - * @param xSplitPos Horizonatal position of split (in 1/20th of a point). + * @param xSplitPos Horizontal position of split (in 1/20th of a point). * @param ySplitPos Vertical position of split (in 1/20th of a point). * @param topRow Top row visible in bottom pane * @param leftmostColumn Left column visible in right pane. @@ -804,7 +804,7 @@ public interface Sheet extends Iterable { * Breaks occur above the specified row and left of the specified column inclusive. * * For example, sheet.setColumnBreak(2); breaks the sheet into two parts - * with columns A,B,C in the first and D,E,... in the second. Simuilar, sheet.setRowBreak(2); + * with columns A,B,C in the first and D,E,... in the second. Similar, sheet.setRowBreak(2); * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part * and rows starting with rownum=4 in the second. * @@ -842,7 +842,7 @@ public interface Sheet extends Iterable { * Breaks occur above the specified row and left of the specified column inclusive. * * For example, sheet.setColumnBreak(2); breaks the sheet into two parts - * with columns A,B,C in the first and D,E,... in the second. Simuilar, sheet.setRowBreak(2); + * with columns A,B,C in the first and D,E,... in the second. Similar, sheet.setRowBreak(2); * breaks the sheet into two parts with first three rows (rownum=1...3) in the first part * and rows starting with rownum=4 in the second. * diff --git a/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java b/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java index fcb44f653e..0a28333e25 100644 --- a/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java +++ b/src/java/org/apache/poi/util/LittleEndianByteArrayInputStream.java @@ -23,16 +23,55 @@ import java.io.ByteArrayInputStream; * Adapts a plain byte array to {@link LittleEndianInput} */ public class LittleEndianByteArrayInputStream extends ByteArrayInputStream implements LittleEndianInput { - public LittleEndianByteArrayInputStream(byte[] buf, int startOffset, int maxReadLen) { // NOSONAR - super(buf, startOffset, maxReadLen); + /** + * Creates LittleEndianByteArrayInputStream + * that uses buf as its + * buffer array. The initial value of pos + * is offset and the initial value + * of count is the minimum of offset+length + * and buf.length. + * The buffer array is not copied. The buffer's mark is + * set to the specified offset. + * + * @param buf the input buffer. + * @param offset the offset in the buffer of the first byte to read. + * @param length the maximum number of bytes to read from the buffer. + */ + public LittleEndianByteArrayInputStream(byte[] buf, int offset, int length) { // NOSONAR + super(buf, offset, length); } - - public LittleEndianByteArrayInputStream(byte[] buf, int startOffset) { - this(buf, startOffset, buf.length - startOffset); + + /** + * Creates LittleEndianByteArrayInputStream + * that uses buf as its + * buffer array. The initial value of pos + * is offset and the initial value + * of count is the minimum of offset+buf.length + * and buf.length. + * The buffer array is not copied. The buffer's mark is + * set to the specified offset. + * + * @param buf the input buffer. + * @param offset the offset in the buffer of the first byte to read. + */ + public LittleEndianByteArrayInputStream(byte[] buf, int offset) { + this(buf, offset, buf.length - offset); } - + + /** + * Creates a LittleEndianByteArrayInputStream + * so that it uses buf as its + * buffer array. + * The buffer array is not copied. + * The initial value of pos + * is 0 and the initial value + * of count is the length of + * buf. + * + * @param buf the input buffer. + */ public LittleEndianByteArrayInputStream(byte[] buf) { - this(buf, 0); + super(buf); } protected void checkPosition(int i) { diff --git a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java index 68799fdca5..9f49886563 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java +++ b/src/ooxml/java/org/apache/poi/xwpf/model/XWPFHeaderFooterPolicy.java @@ -18,8 +18,6 @@ package org.apache.poi.xwpf.model; import org.apache.poi.POIXMLDocumentPart; import org.apache.poi.POIXMLDocumentPart.RelationPart; -import org.apache.poi.util.POILogFactory; -import org.apache.poi.util.POILogger; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.apache.poi.xwpf.usermodel.XWPFFactory; import org.apache.poi.xwpf.usermodel.XWPFFooter; @@ -187,8 +185,7 @@ public class XWPFHeaderFooterPolicy { XWPFFactory.getInstance(), i); wrapper.setXWPFDocument(doc); - String pStyle = "Header"; - CTHdrFtr hdr = buildHdr(type, pStyle, wrapper, pars); + CTHdrFtr hdr = buildHdr(type, wrapper, pars); wrapper.setHeaderFooter(hdr); hdrDoc.setHdr(hdr); assignHeader(wrapper, type); @@ -224,8 +221,7 @@ public class XWPFHeaderFooterPolicy { XWPFFactory.getInstance(), i); wrapper.setXWPFDocument(doc); - String pStyle = "Footer"; - CTHdrFtr ftr = buildFtr(type, pStyle, wrapper, pars); + CTHdrFtr ftr = buildFtr(type, wrapper, pars); wrapper.setHeaderFooter(ftr); ftrDoc.setFtr(ftr); assignFooter(wrapper, type); @@ -245,16 +241,16 @@ public class XWPFHeaderFooterPolicy { return i; } - private CTHdrFtr buildFtr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) { + private CTHdrFtr buildFtr(Enum type, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) { //CTHdrFtr ftr = buildHdrFtr(pStyle, pars); // MB 24 May 2010 - CTHdrFtr ftr = buildHdrFtr(pStyle, pars, wrapper); // MB 24 May 2010 + CTHdrFtr ftr = buildHdrFtr(pars, wrapper); // MB 24 May 2010 setFooterReference(type, wrapper); return ftr; } - private CTHdrFtr buildHdr(Enum type, String pStyle, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) { + private CTHdrFtr buildHdr(Enum type, XWPFHeaderFooter wrapper, XWPFParagraph[] pars) { //CTHdrFtr hdr = buildHdrFtr(pStyle, pars); // MB 24 May 2010 - CTHdrFtr hdr = buildHdrFtr(pStyle, pars, wrapper); // MB 24 May 2010 + CTHdrFtr hdr = buildHdrFtr(pars, wrapper); // MB 24 May 2010 setHeaderReference(type, wrapper); return hdr; } @@ -271,11 +267,11 @@ public class XWPFHeaderFooterPolicy { * that had previoulsy been instantiated in the createHeader(int, XWPFParagraph[]) or * createFooter(int, XWPFParagraph[]) methods. */ - private CTHdrFtr buildHdrFtr(String pStyle, XWPFParagraph[] paragraphs, XWPFHeaderFooter wrapper) { + private CTHdrFtr buildHdrFtr(XWPFParagraph[] paragraphs, XWPFHeaderFooter wrapper) { CTHdrFtr ftr = wrapper._getHdrFtr(); if (paragraphs != null) { for (int i = 0; i < paragraphs.length; i++) { - CTP p = ftr.addNewP(); + /*CTP p =*/ ftr.addNewP(); ftr.setPArray(i, paragraphs[i].getCTP()); } // } else { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java index 2d0aec1671..bb9a9a6a45 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestSXSSFBugs.java @@ -110,18 +110,18 @@ public final class TestSXSSFBugs extends BaseTestBugzillaIssues { @Test public void bug61648() throws Exception { // works as expected - writeWorkbook(new XSSFWorkbook(), "/tmp/61648.xlsx", XSSFITestDataProvider.instance); + writeWorkbook(new XSSFWorkbook(), XSSFITestDataProvider.instance); // does not work try { - writeWorkbook(new SXSSFWorkbook(), "/tmp/61648s.xlsx", SXSSFITestDataProvider.instance); + writeWorkbook(new SXSSFWorkbook(), SXSSFITestDataProvider.instance); fail("Should catch exception here"); } catch (RuntimeException e) { // this is not implemented yet } } - void writeWorkbook(Workbook wb, String filename, ITestDataProvider testDataProvider) throws IOException { + void writeWorkbook(Workbook wb, ITestDataProvider testDataProvider) throws IOException { Sheet sheet = wb.createSheet("array formula test"); int rowIndex = 0; diff --git a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java index 1b327669ae..32373c2be7 100644 --- a/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java +++ b/src/testcases/org/apache/poi/util/TestLittleEndianStreams.java @@ -97,4 +97,30 @@ public final class TestLittleEndianStreams extends TestCase { assertTrue(e.getMessage().contains("Buffer overrun")); } } + + public void testBufferOverrunStartOffset() { + byte[] srcBuf = HexRead.readFromString("99 88 77 88 99"); + LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf, 2); + + // only one byte left, so this should fail + try { + lei.readFully(new byte[4]); + fail("Should catch exception here"); + } catch (RuntimeException e) { + assertTrue(e.getMessage().contains("Buffer overrun")); + } + } + + public void testBufferOverrunStartOffset2() { + byte[] srcBuf = HexRead.readFromString("99 88 77 88 99"); + LittleEndianInput lei = new LittleEndianByteArrayInputStream(srcBuf, 2, 2); + + // only one byte left, so this should fail + try { + lei.readFully(new byte[4]); + fail("Should catch exception here"); + } catch (RuntimeException e) { + assertTrue(e.getMessage().contains("Buffer overrun")); + } + } }