Apply IDE suggestions, adjust tests, ...

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1895596 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2021-12-05 15:33:39 +00:00
parent a3967026a3
commit d5538d24d8
9 changed files with 34 additions and 27 deletions

View File

@ -55,7 +55,7 @@ import org.apache.poi.util.TempFile;
} else { } else {
tempFile = TempFile.createTempFile("poi-zip-entry", ".tmp"); tempFile = TempFile.createTempFile("poi-zip-entry", ".tmp");
LOG.atInfo().log("created for temp file {} for zip entry {} of size {} bytes", LOG.atInfo().log("created for temp file {} for zip entry {} of size {} bytes",
() -> tempFile.getAbsolutePath(), () -> entry.getName(), () -> entrySize); () -> tempFile.getAbsolutePath(), entry::getName, () -> entrySize);
IOUtils.copy(inp, tempFile); IOUtils.copy(inp, tempFile);
} }
} else { } else {
@ -97,7 +97,7 @@ import org.apache.poi.util.TempFile;
/** /**
* Deletes any temp files and releases any byte arrays. * Deletes any temp files and releases any byte arrays.
* @throws IOException * @throws IOException If closing the entry fails.
* @since POI 5.1.0 * @since POI 5.1.0
*/ */
@Override @Override

View File

@ -100,7 +100,7 @@ public class EncryptedTempData {
*/ */
public void dispose() { public void dispose() {
if (!tempFile.delete()) { if (!tempFile.delete()) {
LOG.atWarn().log("{} can't be removed (or was already removed).", () -> tempFile.getAbsolutePath()); LOG.atWarn().log("{} can't be removed (or was already removed).", tempFile::getAbsolutePath);
} }
} }
} }

View File

@ -82,7 +82,6 @@ public class XmlVisioDocument extends POIXMLDocument {
@Override @Override
protected void onDocumentRead() { protected void onDocumentRead() {
// by the time this gets called, all other document parts should // by the time this gets called, all other document parts should
// have been loaded, so it's safe to build the document structure // have been loaded, so it's safe to build the document structure
@ -90,17 +89,17 @@ public class XmlVisioDocument extends POIXMLDocument {
// loaded yet, so it's not quite safe // loaded yet, so it's not quite safe
for (POIXMLDocumentPart part : getRelations()) { for (POIXMLDocumentPart part : getRelations()) {
// organize the document pieces // organize the document pieces
if (part instanceof XDGFPages) if (part instanceof XDGFPages) {
_pages = (XDGFPages) part; _pages = (XDGFPages) part;
} else if (part instanceof XDGFMasters) {
else if (part instanceof XDGFMasters)
_masters = (XDGFMasters) part; _masters = (XDGFMasters) part;
} }
}
if (_masters != null) if (_masters != null) {
_masters.onDocumentRead(); _masters.onDocumentRead();
}
_pages.onDocumentRead(); _pages.onDocumentRead();
} }

View File

@ -52,6 +52,7 @@ class TestXWPFBugs {
assertThrows(IOException.class, () -> { assertThrows(IOException.class, () -> {
try (InputStream fis = samples.openResourceAsStream("truncated62886.docx"); try (InputStream fis = samples.openResourceAsStream("truncated62886.docx");
OPCPackage opc = OPCPackage.open(fis)) { OPCPackage opc = OPCPackage.open(fis)) {
assertNotNull(opc);
//XWPFWordExtractor ext = new XWPFWordExtractor(opc)) { //XWPFWordExtractor ext = new XWPFWordExtractor(opc)) {
//assertNotNull(ext.getText()); //assertNotNull(ext.getText());
} }
@ -59,7 +60,7 @@ class TestXWPFBugs {
} }
/** /**
* A word document that's encrypted with non-standard * A Word document that's encrypted with non-standard
* Encryption options, and no cspname section. See bug 53475 * Encryption options, and no cspname section. See bug 53475
*/ */
@Test @Test
@ -77,7 +78,7 @@ class TestXWPFBugs {
Decryptor d = Decryptor.getInstance(info); Decryptor d = Decryptor.getInstance(info);
assertTrue(d.verifyPassword("solrcell"), "Unable to process: document is encrypted"); assertTrue(d.verifyPassword("solrcell"), "Unable to process: document is encrypted");
// Check we can read the word document in that // Check we can read the Word document in that
InputStream dataStream = d.getDataStream(filesystem); InputStream dataStream = d.getDataStream(filesystem);
OPCPackage opc = OPCPackage.open(dataStream); OPCPackage opc = OPCPackage.open(dataStream);
XWPFDocument doc = new XWPFDocument(opc); XWPFDocument doc = new XWPFDocument(opc);
@ -91,7 +92,7 @@ class TestXWPFBugs {
} }
/** /**
* A word document with aes-256, i.e. aes is always 128 bit (= 128 bit block size), * A Word document with aes-256, i.e. aes is always 128 bit (= 128 bit block size),
* but the key can be 128/192/256 bits * but the key can be 128/192/256 bits
*/ */
@Test @Test
@ -113,7 +114,7 @@ class TestXWPFBugs {
Decryptor d = Decryptor.getInstance(info); Decryptor d = Decryptor.getInstance(info);
assertTrue(d.verifyPassword("pass"), "Unable to process: document is encrypted"); assertTrue(d.verifyPassword("pass"), "Unable to process: document is encrypted");
// Check we can read the word document in that // Check we can read the Word document in that
InputStream dataStream = d.getDataStream(filesystem); InputStream dataStream = d.getDataStream(filesystem);
OPCPackage opc = OPCPackage.open(dataStream); OPCPackage opc = OPCPackage.open(dataStream);
XWPFDocument doc = new XWPFDocument(opc); XWPFDocument doc = new XWPFDocument(opc);

View File

@ -207,7 +207,7 @@ public abstract class QCPLCBit extends QCBit {
* of the text area that this applies to. * of the text area that this applies to.
*/ */
public static class Type12 extends QCPLCBit { public static class Type12 extends QCPLCBit {
private String[] hyperlinks; private final String[] hyperlinks;
private static final int oneStartsAt = 0x4c; private static final int oneStartsAt = 0x4c;
private static final int twoStartsAt = 0x68; private static final int twoStartsAt = 0x68;

View File

@ -214,6 +214,7 @@ public final class HWPFDocument extends HWPFDocumentCore {
* @param istream The InputStream that contains the Word document. * @param istream The InputStream that contains the Word document.
* @throws IOException If there is an unexpected IOException from the passed * @throws IOException If there is an unexpected IOException from the passed
* in InputStream. * in InputStream.
* @throws org.apache.poi.EmptyFileException If the given stream is empty
*/ */
public HWPFDocument(InputStream istream) throws IOException { public HWPFDocument(InputStream istream) throws IOException {
//do Ole stuff //do Ole stuff

View File

@ -46,6 +46,7 @@ import org.apache.poi.sl.usermodel.BaseTestSlideShow;
import org.apache.poi.sl.usermodel.PlaceholderDetails; import org.apache.poi.sl.usermodel.PlaceholderDetails;
import org.apache.poi.util.LocaleUtil; import org.apache.poi.util.LocaleUtil;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.opentest4j.AssertionFailedError;
/** /**
* Tests for TextRuns * Tests for TextRuns
@ -603,16 +604,21 @@ public final class TestTextRun {
.mapToInt(r -> ((DateTimeMCAtom)r).getIndex()).toArray(); .mapToInt(r -> ((DateTimeMCAtom)r).getIndex()).toArray();
assertArrayEquals(expFormatId, actFormatId); assertArrayEquals(expFormatId, actFormatId);
List<HSLFShapePlaceholderDetails> phs = shapes.stream().map(HSLFSimpleShape::getPlaceholderDetails).collect(Collectors.toList()); List<HSLFShapePlaceholderDetails> phs =
shapes.stream().map(HSLFSimpleShape::getPlaceholderDetails).collect(Collectors.toList());
for (Map.Entry<Locale,String[]> me : formats.entrySet()) { for (Map.Entry<Locale,String[]> me : formats.entrySet()) {
LocaleUtil.setUserLocale(me.getKey()); LocaleUtil.setUserLocale(me.getKey());
try {
// refresh internal members // refresh internal members
phs.forEach(PlaceholderDetails::getPlaceholder); phs.forEach(PlaceholderDetails::getPlaceholder);
String[] actDate = phs.stream().map(PlaceholderDetails::getDateFormat).map(ldt::format).toArray(String[]::new); String[] actDate = phs.stream().map(PlaceholderDetails::getDateFormat).map(ldt::format).toArray(String[]::new);
assertArrayEquals(me.getValue(), actDate); assertArrayEquals(me.getValue(), actDate);
} catch (AssertionFailedError e) {
throw new AssertionFailedError("While handling local " + me.getKey());
}
} }
} finally { } finally {
LocaleUtil.resetUserLocale(); LocaleUtil.resetUserLocale();

View File

@ -242,7 +242,7 @@ public final class SupBookRecord extends StandardRecord {
public void setURL(String pUrl) { public void setURL(String pUrl) {
//Keep the first marker character! //Keep the first marker character!
field_2_encoded_url = field_2_encoded_url.substring(0, 1) + pUrl; field_2_encoded_url = field_2_encoded_url.charAt(0) + pUrl;
} }
@Override @Override

View File

@ -34,16 +34,16 @@ import org.apache.poi.util.LittleEndianOutput;
public final class ChartFRTInfoRecord extends StandardRecord { public final class ChartFRTInfoRecord extends StandardRecord {
public static final short sid = 0x850; public static final short sid = 0x850;
private short rt; private final short rt;
private short grbitFrt; private final short grbitFrt;
private byte verOriginator; private final byte verOriginator;
private byte verWriter; private final byte verWriter;
private CFRTID[] rgCFRTID; private CFRTID[] rgCFRTID;
private static final class CFRTID { private static final class CFRTID {
public static final int ENCODED_SIZE = 4; public static final int ENCODED_SIZE = 4;
private int rtFirst; private final int rtFirst;
private int rtLast; private final int rtLast;
public CFRTID(CFRTID other) { public CFRTID(CFRTID other) {
rtFirst = other.rtFirst; rtFirst = other.rtFirst;