} else {
tempFile = TempFile.createTempFile("poi-zip-entry", ".tmp");
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);
}
} else {
/**
* Deletes any temp files and releases any byte arrays.
- * @throws IOException
+ * @throws IOException If closing the entry fails.
* @since POI 5.1.0
*/
@Override
*/
public void dispose() {
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);
}
}
}
@Override
protected void onDocumentRead() {
-
// by the time this gets called, all other document parts should
// have been loaded, so it's safe to build the document structure
// loaded yet, so it's not quite safe
for (POIXMLDocumentPart part : getRelations()) {
-
// organize the document pieces
- if (part instanceof XDGFPages)
+ if (part instanceof XDGFPages) {
_pages = (XDGFPages) part;
-
- else if (part instanceof XDGFMasters)
+ } else if (part instanceof XDGFMasters) {
_masters = (XDGFMasters) part;
+ }
}
- if (_masters != null)
+ if (_masters != null) {
_masters.onDocumentRead();
+ }
_pages.onDocumentRead();
}
assertThrows(IOException.class, () -> {
try (InputStream fis = samples.openResourceAsStream("truncated62886.docx");
OPCPackage opc = OPCPackage.open(fis)) {
+ assertNotNull(opc);
//XWPFWordExtractor ext = new XWPFWordExtractor(opc)) {
//assertNotNull(ext.getText());
}
}
/**
- * 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
*/
@Test
Decryptor d = Decryptor.getInstance(info);
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);
OPCPackage opc = OPCPackage.open(dataStream);
XWPFDocument doc = new XWPFDocument(opc);
}
/**
- * 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
*/
@Test
Decryptor d = Decryptor.getInstance(info);
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);
OPCPackage opc = OPCPackage.open(dataStream);
XWPFDocument doc = new XWPFDocument(opc);
assertEquals(731, document.getParagraphs().size());
}
}
-}
\ No newline at end of file
+}
* of the text area that this applies to.
*/
public static class Type12 extends QCPLCBit {
- private String[] hyperlinks;
+ private final String[] hyperlinks;
private static final int oneStartsAt = 0x4c;
private static final int twoStartsAt = 0x68;
* @param istream The InputStream that contains the Word document.
* @throws IOException If there is an unexpected IOException from the passed
* in InputStream.
+ * @throws org.apache.poi.EmptyFileException If the given stream is empty
*/
public HWPFDocument(InputStream istream) throws IOException {
//do Ole stuff
import org.apache.poi.sl.usermodel.PlaceholderDetails;
import org.apache.poi.util.LocaleUtil;
import org.junit.jupiter.api.Test;
+import org.opentest4j.AssertionFailedError;
/**
* Tests for TextRuns
.mapToInt(r -> ((DateTimeMCAtom)r).getIndex()).toArray();
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()) {
LocaleUtil.setUserLocale(me.getKey());
- // refresh internal members
- phs.forEach(PlaceholderDetails::getPlaceholder);
+ try {
+ // refresh internal members
+ phs.forEach(PlaceholderDetails::getPlaceholder);
- String[] actDate = phs.stream().map(PlaceholderDetails::getDateFormat).map(ldt::format).toArray(String[]::new);
- assertArrayEquals(me.getValue(), actDate);
+ String[] actDate = phs.stream().map(PlaceholderDetails::getDateFormat).map(ldt::format).toArray(String[]::new);
+ assertArrayEquals(me.getValue(), actDate);
+ } catch (AssertionFailedError e) {
+ throw new AssertionFailedError("While handling local " + me.getKey());
+ }
}
} finally {
LocaleUtil.resetUserLocale();
public void setURL(String pUrl) {
//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
public final class ChartFRTInfoRecord extends StandardRecord {
public static final short sid = 0x850;
- private short rt;
- private short grbitFrt;
- private byte verOriginator;
- private byte verWriter;
+ private final short rt;
+ private final short grbitFrt;
+ private final byte verOriginator;
+ private final byte verWriter;
private CFRTID[] rgCFRTID;
private static final class CFRTID {
public static final int ENCODED_SIZE = 4;
- private int rtFirst;
- private int rtLast;
+ private final int rtFirst;
+ private final int rtLast;
public CFRTID(CFRTID other) {
rtFirst = other.rtFirst;