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
This commit is contained in:
Dominik Stadler 2018-02-08 19:34:16 +00:00
parent ac763a24ad
commit d0adab9aee
5 changed files with 92 additions and 31 deletions

View File

@ -110,7 +110,7 @@ public interface Sheet extends Iterable<Row> {
* 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<Row> {
* 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<Row> {
* <p>
* 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
* </p>
*
* @param columnIndex - the column to set (0-based)
@ -384,7 +384,7 @@ public interface Sheet extends Iterable<Row> {
* evaluation in POI is not possible.
* </p>
*
* 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<Row> {
* <p>
* If both colSplit and rowSplit are zero then the existing freeze pane is removed
* </p>
* @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<Row> {
* <p>
* If both colSplit and rowSplit are zero then the existing freeze pane is removed
* </p>
* @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<Row> {
* Breaks occur above the specified row and left of the specified column inclusive.
*
* For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
* with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
* with columns A,B,C in the first and D,E,... in the second. Similar, <code>sheet.setRowBreak(2);</code>
* 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<Row> {
* Breaks occur above the specified row and left of the specified column inclusive.
*
* For example, <code>sheet.setColumnBreak(2);</code> breaks the sheet into two parts
* with columns A,B,C in the first and D,E,... in the second. Simuilar, <code>sheet.setRowBreak(2);</code>
* with columns A,B,C in the first and D,E,... in the second. Similar, <code>sheet.setRowBreak(2);</code>
* 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.
*

View File

@ -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 <code>LittleEndianByteArrayInputStream</code>
* that uses <code>buf</code> as its
* buffer array. The initial value of <code>pos</code>
* is <code>offset</code> and the initial value
* of <code>count</code> is the minimum of <code>offset+length</code>
* and <code>buf.length</code>.
* 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 <code>LittleEndianByteArrayInputStream</code>
* that uses <code>buf</code> as its
* buffer array. The initial value of <code>pos</code>
* is <code>offset</code> and the initial value
* of <code>count</code> is the minimum of <code>offset+buf.length</code>
* and <code>buf.length</code>.
* 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 <code>LittleEndianByteArrayInputStream</code>
* so that it uses <code>buf</code> as its
* buffer array.
* The buffer array is not copied.
* The initial value of <code>pos</code>
* is <code>0</code> and the initial value
* of <code>count</code> is the length of
* <code>buf</code>.
*
* @param buf the input buffer.
*/
public LittleEndianByteArrayInputStream(byte[] buf) {
this(buf, 0);
super(buf);
}
protected void checkPosition(int i) {

View File

@ -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 {

View File

@ -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;

View File

@ -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"));
}
}
}