mirror of
https://github.com/apache/poi.git
synced 2026-02-27 12:30:08 +08:00
Use OpenRewrite to update code to make use of Java 11
This commit is contained in:
parent
89fa331beb
commit
d486e50822
@ -21,7 +21,7 @@ package org.apache.poi.examples.crypt;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
@ -72,7 +72,7 @@ public final class OOXMLPasswordsTry {
|
||||
};
|
||||
|
||||
// Try each password in turn, reporting progress
|
||||
try (Stream<String> lines = Files.lines(Paths.get(words))) {
|
||||
try (Stream<String> lines = Files.lines(Path.of(words))) {
|
||||
Optional<String> found = lines.filter(counter).filter(w -> isValid(d, w)).findFirst();
|
||||
System.out.println(found.map(s -> "Password found: " + s).orElse("Error - No password matched"));
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ package org.apache.poi.examples.ss;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
@ -95,7 +95,7 @@ public final class ConditionalFormats {
|
||||
if (wb instanceof XSSFWorkbook) {
|
||||
file += "x";
|
||||
}
|
||||
try (OutputStream out = Files.newOutputStream(Paths.get(file))) {
|
||||
try (OutputStream out = Files.newOutputStream(Path.of(file))) {
|
||||
wb.write(out);
|
||||
}
|
||||
System.out.println("Generated: " + file);
|
||||
|
||||
@ -23,7 +23,7 @@ import org.apache.poi.util.DefaultTempFileCreationStrategy;
|
||||
import org.apache.poi.util.TempFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class TempFileUtils {
|
||||
private TempFileUtils() {
|
||||
@ -31,7 +31,7 @@ public final class TempFileUtils {
|
||||
|
||||
@SuppressWarnings("java:S106")
|
||||
public static void checkTempFiles() {
|
||||
File tempDir = Paths.get(System.getProperty(TempFile.JAVA_IO_TMPDIR), DefaultTempFileCreationStrategy.POIFILES).toFile();
|
||||
File tempDir = Path.of(System.getProperty(TempFile.JAVA_IO_TMPDIR), DefaultTempFileCreationStrategy.POIFILES).toFile();
|
||||
if(tempDir.exists()) {
|
||||
String[] tempFiles = tempDir.list();
|
||||
if(tempFiles != null && tempFiles.length > 0) {
|
||||
|
||||
@ -25,7 +25,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -64,7 +64,7 @@ public final class BarChartDemo {
|
||||
}
|
||||
|
||||
try (FileInputStream argIS = new FileInputStream(args[0]);
|
||||
BufferedReader modelReader = Files.newBufferedReader(Paths.get(args[1]), StandardCharsets.UTF_8)) {
|
||||
BufferedReader modelReader = Files.newBufferedReader(Path.of(args[1]), StandardCharsets.UTF_8)) {
|
||||
|
||||
String chartTitle = modelReader.readLine(); // first line is chart title
|
||||
String seriesText = modelReader.readLine();
|
||||
|
||||
@ -26,7 +26,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -72,7 +72,7 @@ public final class ChartFromScratch {
|
||||
return;
|
||||
}
|
||||
|
||||
try (BufferedReader modelReader = Files.newBufferedReader(Paths.get(args[0]), StandardCharsets.UTF_8)) {
|
||||
try (BufferedReader modelReader = Files.newBufferedReader(Path.of(args[0]), StandardCharsets.UTF_8)) {
|
||||
|
||||
String chartTitle = modelReader.readLine(); // first line is chart title
|
||||
String seriesText = modelReader.readLine();
|
||||
|
||||
@ -41,7 +41,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -64,7 +64,7 @@ public final class DoughnutChartFromScratch {
|
||||
return;
|
||||
}
|
||||
|
||||
try (BufferedReader modelReader = Files.newBufferedReader(Paths.get(args[0]), StandardCharsets.UTF_8)) {
|
||||
try (BufferedReader modelReader = Files.newBufferedReader(Path.of(args[0]), StandardCharsets.UTF_8)) {
|
||||
|
||||
String chartTitle = modelReader.readLine(); // first line is chart title
|
||||
String seriesText = modelReader.readLine();
|
||||
|
||||
@ -25,7 +25,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -61,7 +61,7 @@ public final class PieChartDemo {
|
||||
}
|
||||
|
||||
try (FileInputStream argIS = new FileInputStream(args[0]);
|
||||
BufferedReader modelReader = Files.newBufferedReader(Paths.get(args[1]), StandardCharsets.UTF_8)) {
|
||||
BufferedReader modelReader = Files.newBufferedReader(Path.of(args[1]), StandardCharsets.UTF_8)) {
|
||||
String chartTitle = modelReader.readLine(); // first line is chart title
|
||||
|
||||
try (XMLSlideShow pptx = new XMLSlideShow(argIS)) {
|
||||
|
||||
@ -26,7 +26,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -63,7 +63,7 @@ public final class BarChartExample {
|
||||
}
|
||||
|
||||
try (FileInputStream argIS = new FileInputStream(args[0]);
|
||||
BufferedReader modelReader = Files.newBufferedReader(Paths.get(args[1]), StandardCharsets.UTF_8)) {
|
||||
BufferedReader modelReader = Files.newBufferedReader(Path.of(args[1]), StandardCharsets.UTF_8)) {
|
||||
|
||||
String chartTitle = modelReader.readLine(); // first line is chart title
|
||||
String seriesText = modelReader.readLine();
|
||||
|
||||
@ -24,7 +24,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -67,7 +67,7 @@ public final class ChartFromScratch {
|
||||
return;
|
||||
}
|
||||
|
||||
try (BufferedReader modelReader = Files.newBufferedReader(Paths.get(args[0]), StandardCharsets.UTF_8)) {
|
||||
try (BufferedReader modelReader = Files.newBufferedReader(Path.of(args[0]), StandardCharsets.UTF_8)) {
|
||||
|
||||
String chartTitle = modelReader.readLine(); // first line is chart title
|
||||
String seriesText = modelReader.readLine();
|
||||
|
||||
@ -25,7 +25,6 @@ import java.lang.instrument.Instrumentation;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.HashSet;
|
||||
@ -78,7 +77,7 @@ public class OOXMLLiteAgent {
|
||||
private static final Set<Integer> hashes = new HashSet<>();
|
||||
|
||||
static void load(String path) throws IOException {
|
||||
logPath = Paths.get(path);
|
||||
logPath = Path.of(path);
|
||||
if (Files.exists(logPath)) {
|
||||
try (Stream<String> stream = Files.lines(logPath)) {
|
||||
stream.forEach((s) -> hashes.add(s.hashCode()));
|
||||
@ -109,7 +108,7 @@ public class OOXMLLiteAgent {
|
||||
}
|
||||
|
||||
void load(String path) throws IOException {
|
||||
this.logPath = Paths.get(path);
|
||||
this.logPath = Path.of(path);
|
||||
if (Files.exists(this.logPath)) {
|
||||
try (Stream<String> stream = Files.lines(this.logPath)) {
|
||||
stream.forEach((s) -> hashes.add(s.hashCode()));
|
||||
|
||||
@ -73,14 +73,14 @@ public class POIXMLPropertiesTextExtractor implements POIXMLTextExtractor {
|
||||
}
|
||||
|
||||
private void appendDateIfPresent(StringBuilder text, String thing, Optional<Date> value) {
|
||||
if (!value.isPresent()) {
|
||||
if (value.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
appendIfPresent(text, thing, dateFormat.format(value.get()));
|
||||
}
|
||||
|
||||
private void appendIfPresent(StringBuilder text, String thing, Optional<String> value) {
|
||||
if (!value.isPresent()) {
|
||||
if (value.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
appendIfPresent(text, thing, value.get());
|
||||
|
||||
@ -31,7 +31,7 @@ import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@ -711,7 +711,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
|
||||
}
|
||||
String name = path.substring(path.lastIndexOf(File.separatorChar) + 1);
|
||||
|
||||
try (InputStream is = Files.newInputStream(Paths.get(path))) {
|
||||
try (InputStream is = Files.newInputStream(Path.of(path))) {
|
||||
addThumbnail(name, is);
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,7 +138,7 @@ public class PackagePropertiesMarshaller implements PartMarshaller {
|
||||
}
|
||||
|
||||
private Element setElementTextContent(String localName, NamespaceImpl namespace, Optional<?> property, String propertyValue) {
|
||||
if (!property.isPresent())
|
||||
if (property.isEmpty())
|
||||
return null;
|
||||
|
||||
Element root = xmlDoc.getDocumentElement();
|
||||
|
||||
@ -27,7 +27,7 @@ import java.io.PrintStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.poi.xdgf.usermodel.XDGFPage;
|
||||
import org.apache.poi.xdgf.usermodel.XDGFShape;
|
||||
@ -92,7 +92,7 @@ public class HierarchyPrinter {
|
||||
String inFilename = args[0];
|
||||
String outDir = args[1];
|
||||
|
||||
try (InputStream is = Files.newInputStream(Paths.get(inFilename))) {
|
||||
try (InputStream is = Files.newInputStream(Path.of(inFilename))) {
|
||||
XmlVisioDocument doc = new XmlVisioDocument(is);
|
||||
printHierarchy(doc, outDir);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
@ -129,7 +129,7 @@ public class VsdxToPng {
|
||||
renderer = new ShapeDebuggerRenderer();
|
||||
}
|
||||
|
||||
try (InputStream is = Files.newInputStream(Paths.get(inFilename))) {
|
||||
try (InputStream is = Files.newInputStream(Path.of(inFilename))) {
|
||||
XmlVisioDocument doc = new XmlVisioDocument(is);
|
||||
renderToPng(doc, pngDir, 2000 / 11.0, renderer);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
@ -83,7 +83,7 @@ class TestTempFileThreaded {
|
||||
}
|
||||
|
||||
TempFile.setTempFileCreationStrategy(createTempFileCreationStrategy(
|
||||
Paths.get(tmpDir, POIFILES, "TestTempFileThreaded").toFile()));
|
||||
Path.of(tmpDir, POIFILES, "TestTempFileThreaded").toFile()));
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
|
||||
@ -310,7 +310,7 @@ class TestXSSFBReader {
|
||||
ordered.verify(handler).startRow(7);
|
||||
ordered.verify(handler).stringCell(eq("A8"), eq("longer int"), isNull());
|
||||
ordered.verify(handler).doubleCell(eq("B8"), eq(1.23456789012345E15d), isNull(), any(ExcelNumberFormat.class));
|
||||
ordered.verify(handler).stringCell(eq("C8"), isNull(), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("C8"), isNull(), notNull());
|
||||
ordered.verify(handler).endRow(7);
|
||||
|
||||
ordered.verify(handler).startRow(8);
|
||||
@ -325,7 +325,7 @@ class TestXSSFBReader {
|
||||
|
||||
ordered.verify(handler).startRow(10);
|
||||
ordered.verify(handler).stringCell(eq("A11"), eq("comment"), isNull());
|
||||
ordered.verify(handler).stringCell(eq("B11"), eq("contents"), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("B11"), eq("contents"), notNull());
|
||||
ordered.verify(handler).endRow(10);
|
||||
|
||||
ordered.verify(handler).startRow(11);
|
||||
@ -372,38 +372,38 @@ class TestXSSFBReader {
|
||||
ordered.verify(handler).endRow(20);
|
||||
|
||||
ordered.verify(handler).startRow(22);
|
||||
ordered.verify(handler).stringCell(eq("A23"), isNull(), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("A23"), isNull(), notNull());
|
||||
ordered.verify(handler).endRow(22);
|
||||
|
||||
ordered.verify(handler).startRow(23);
|
||||
ordered.verify(handler).stringCell(eq("C24"), isNull(), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("C24"), isNull(), notNull());
|
||||
ordered.verify(handler).endRow(23);
|
||||
|
||||
ordered.verify(handler).startRow(27);
|
||||
ordered.verify(handler).stringCell(eq("B28"), isNull(), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("B28"), isNull(), notNull());
|
||||
ordered.verify(handler).endRow(27);
|
||||
|
||||
ordered.verify(handler).startRow(29);
|
||||
ordered.verify(handler).stringCell(eq("B30"), eq("the"), isNull());
|
||||
ordered.verify(handler).stringCell(eq("C30"), isNull(), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("C30"), isNull(), notNull());
|
||||
ordered.verify(handler).endRow(29);
|
||||
|
||||
ordered.verify(handler).startRow(32);
|
||||
ordered.verify(handler).stringCell(eq("B33"), eq("the"), isNull());
|
||||
ordered.verify(handler).stringCell(eq("C33"), isNull(), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("C33"), isNull(), notNull());
|
||||
ordered.verify(handler).stringCell(eq("D33"), eq("quick"), isNull());
|
||||
ordered.verify(handler).endRow(32);
|
||||
|
||||
ordered.verify(handler).startRow(34);
|
||||
ordered.verify(handler).stringCell(eq("B35"), eq("comment6"), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("B35"), eq("comment6"), notNull());
|
||||
ordered.verify(handler).endRow(34);
|
||||
|
||||
ordered.verify(handler).startRow(64);
|
||||
ordered.verify(handler).stringCell(eq("I65"), isNull(), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("I65"), isNull(), notNull());
|
||||
ordered.verify(handler).endRow(64);
|
||||
|
||||
ordered.verify(handler).startRow(65);
|
||||
ordered.verify(handler).stringCell(eq("I66"), isNull(), notNull(XSSFComment.class));
|
||||
ordered.verify(handler).stringCell(eq("I66"), isNull(), notNull());
|
||||
ordered.verify(handler).endRow(65);
|
||||
|
||||
ordered.verify(handler).headerFooter(eq("OddLeftHeader OddCenterHeader OddRightHeader"), eq(true), eq("header"));
|
||||
|
||||
@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
@ -76,7 +77,7 @@ public final class TestXSSFSheetRowGrouping {
|
||||
}
|
||||
|
||||
private boolean isCollapsed() {
|
||||
return Math.random() > 0.5d;
|
||||
return ThreadLocalRandom.current().nextDouble() > 0.5d;
|
||||
}
|
||||
|
||||
private void writeToFile(Workbook p_wb) {
|
||||
|
||||
@ -20,7 +20,7 @@ package org.apache.poi.hmef.dev;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hmef.HMEFMessage;
|
||||
@ -68,7 +68,7 @@ public final class HMEFDumper {
|
||||
continue;
|
||||
}
|
||||
|
||||
try (InputStream stream = Files.newInputStream(Paths.get(arg))) {
|
||||
try (InputStream stream = Files.newInputStream(Path.of(arg))) {
|
||||
HMEFDumper dumper = new HMEFDumper(stream);
|
||||
dumper.setTruncatePropertyData(truncatePropData);
|
||||
dumper.dump();
|
||||
|
||||
@ -20,7 +20,7 @@ package org.apache.poi.hpbf.dev;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.poi.hpbf.HPBFDocument;
|
||||
import org.apache.poi.hpbf.model.QuillContents;
|
||||
@ -55,7 +55,7 @@ public final class PLCDumper {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
try (InputStream fis = Files.newInputStream(Paths.get(args[0]))) {
|
||||
try (InputStream fis = Files.newInputStream(Path.of(args[0]))) {
|
||||
PLCDumper dump = new PLCDumper(fis);
|
||||
|
||||
System.out.println("Dumping " + args[0]);
|
||||
|
||||
@ -26,7 +26,7 @@ import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream;
|
||||
@ -216,7 +216,7 @@ public final class PPTXMLDump {
|
||||
System.out.println("Dumping " + arg);
|
||||
|
||||
if (outFile) {
|
||||
OutputStream fos = Files.newOutputStream(Paths.get(ppt.getName() + ".xml"));
|
||||
OutputStream fos = Files.newOutputStream(Path.of(ppt.getName() + ".xml"));
|
||||
OutputStreamWriter out = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
|
||||
dump.dump(out);
|
||||
out.close();
|
||||
|
||||
@ -20,7 +20,7 @@ package org.apache.poi.hslf.extractor;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.poi.hslf.usermodel.HSLFPictureData;
|
||||
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
|
||||
@ -47,7 +47,7 @@ public final class ImageExtractor {
|
||||
|
||||
PictureType type = pict.getType();
|
||||
try (OutputStream out = Files.newOutputStream(
|
||||
Paths.get("pict_" + i++ + type.extension))) {
|
||||
Path.of("pict_" + i++ + type.extension))) {
|
||||
out.write(data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,7 +143,7 @@ public final class PPDrawing extends RecordAtom implements Iterable<EscherRecord
|
||||
|
||||
private static Stream<EscherTextboxWrapper> getTextboxHelper(EscherContainerRecord spContainer) {
|
||||
Optional<EscherTextboxRecord> oTB = firstEscherRecord(spContainer, EscherRecordTypes.CLIENT_TEXTBOX);
|
||||
if (!oTB.isPresent()) {
|
||||
if (oTB.isEmpty()) {
|
||||
return Stream.empty();
|
||||
}
|
||||
|
||||
@ -309,9 +309,7 @@ public final class PPDrawing extends RecordAtom implements Iterable<EscherRecord
|
||||
return Stream.of(dgContainer).
|
||||
flatMap(findEscherContainer(EscherRecordTypes.SPGR_CONTAINER)).
|
||||
flatMap(findEscherContainer(EscherRecordTypes.SP_CONTAINER)).
|
||||
map(PPDrawing::findInSpContainer).
|
||||
filter(Optional::isPresent).
|
||||
map(Optional::get).
|
||||
map(PPDrawing::findInSpContainer).flatMap(Optional::stream).
|
||||
toArray(StyleTextProp9Atom[]::new);
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@
|
||||
package org.apache.poi.hwpf.model;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.apache.poi.util.Internal;
|
||||
|
||||
@ -117,7 +118,7 @@ public final class ListData
|
||||
|
||||
int resetListID()
|
||||
{
|
||||
_lstf.setLsid( (int) ( Math.random() * System.currentTimeMillis() ) );
|
||||
_lstf.setLsid( (int) ( ThreadLocalRandom.current().nextDouble() * System.currentTimeMillis() ) );
|
||||
return _lstf.getLsid();
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +22,8 @@ import org.apache.poi.hwpf.model.ListTables;
|
||||
import org.apache.poi.util.Internal;
|
||||
|
||||
import org.apache.poi.hwpf.model.LFO;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import org.apache.poi.hwpf.model.LFOData;
|
||||
import org.apache.poi.hwpf.model.ListData;
|
||||
import org.apache.poi.hwpf.model.ListFormatOverrideLevel;
|
||||
@ -65,7 +67,7 @@ public final class HWPFList
|
||||
public HWPFList( boolean numbered, StyleSheet styleSheet )
|
||||
{
|
||||
_listData = new ListData(
|
||||
(int) ( Math.random() * System.currentTimeMillis() ), numbered );
|
||||
(int) ( ThreadLocalRandom.current().nextDouble() * System.currentTimeMillis() ), numbered );
|
||||
_lfo = new LFO();
|
||||
_lfo.setLsid( _listData.getLsid() );
|
||||
_lfoData = new LFOData();
|
||||
|
||||
@ -20,6 +20,8 @@ package org.apache.poi.hwpf.model;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.apache.poi.hwpf.HWPFDocFixture;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@ -36,7 +38,7 @@ public final class TestPlexOfCps {
|
||||
int last = 0;
|
||||
for (int x = 0; x < 110; x++) {
|
||||
byte[] intHolder = new byte[4];
|
||||
int span = (int) (110.0f * Math.random());
|
||||
int span = (int) (110.0f * ThreadLocalRandom.current().nextDouble());
|
||||
LittleEndian.putInt(intHolder, 0, span);
|
||||
_plexOfCps.addProperty(new GenericPropertyNode(last, last + span, intHolder));
|
||||
last += span;
|
||||
|
||||
@ -22,7 +22,7 @@ import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.poifs.common.POIFSConstants;
|
||||
@ -66,7 +66,7 @@ public final class POIFSDump {
|
||||
}
|
||||
|
||||
System.out.println("Dumping " + filename);
|
||||
try (InputStream is = Files.newInputStream(Paths.get(filename));
|
||||
try (InputStream is = Files.newInputStream(Path.of(filename));
|
||||
POIFSFileSystem fs = new POIFSFileSystem(is)) {
|
||||
DirectoryEntry root = fs.getRoot();
|
||||
String filenameWithoutPath = new File(filename).getName();
|
||||
|
||||
@ -21,7 +21,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
@ -70,7 +70,7 @@ public class POIFSLister {
|
||||
}
|
||||
|
||||
public static void viewFileOld(final String filename, boolean withSizes) throws IOException {
|
||||
try (InputStream fis = Files.newInputStream(Paths.get(filename));
|
||||
try (InputStream fis = Files.newInputStream(Path.of(filename));
|
||||
POIFSFileSystem fs = new POIFSFileSystem(fis)) {
|
||||
displayDirectory(fs.getRoot(), "", withSizes);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ import java.nio.channels.Channels;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
@ -822,8 +822,8 @@ public class POIFSFileSystem extends BlockStore
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
try (InputStream istream = Files.newInputStream(Paths.get(args[0]))) {
|
||||
try (OutputStream ostream = Files.newOutputStream(Paths.get(args[1]))) {
|
||||
try (InputStream istream = Files.newInputStream(Path.of(args[0]))) {
|
||||
try (OutputStream ostream = Files.newOutputStream(Path.of(args[1]))) {
|
||||
try (POIFSFileSystem fs = new POIFSFileSystem(istream)) {
|
||||
fs.writeFilesystem(ostream);
|
||||
}
|
||||
|
||||
@ -22,8 +22,11 @@ import org.apache.poi.ss.formula.eval.NumberEval;
|
||||
import org.apache.poi.ss.formula.eval.OperandResolver;
|
||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||
import org.apache.poi.ss.formula.functions.FreeRefFunction;
|
||||
|
||||
import org.apache.poi.ss.formula.OperationEvaluationContext;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
/**
|
||||
* Implementation of Excel 'Analysis ToolPak' function RANDBETWEEN()<br>
|
||||
*
|
||||
@ -75,7 +78,7 @@ final class RandBetween implements FreeRefFunction{
|
||||
top = bottom;
|
||||
}
|
||||
|
||||
return new NumberEval((bottom + (long)(Math.random() * ((top - bottom) + 1))));
|
||||
return new NumberEval((bottom + (long)(ThreadLocalRandom.current().nextDouble() * ((top - bottom) + 1))));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -27,6 +27,7 @@ import java.math.BigInteger;
|
||||
import java.math.MathContext;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public abstract class NumericFunction implements Function {
|
||||
|
||||
@ -189,7 +190,7 @@ public abstract class NumericFunction implements Function {
|
||||
public static final Function RAND = NumericFunction::evaluateRand;
|
||||
|
||||
private static ValueEval evaluateRand(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
|
||||
return (args.length != 0) ? ErrorEval.VALUE_INVALID : new NumberEval(Math.random());
|
||||
return (args.length != 0) ? ErrorEval.VALUE_INVALID : new NumberEval(ThreadLocalRandom.current().nextDouble());
|
||||
}
|
||||
|
||||
public static final Function POISSON = Poisson::evaluate;
|
||||
|
||||
@ -23,7 +23,6 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.attribute.FileAttribute;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
@ -130,7 +129,7 @@ public class DefaultTempFileCreationStrategy implements TempFileCreationStrategy
|
||||
|
||||
protected Path getPOIFilesDirectoryPath() throws IOException {
|
||||
if (initDir == null) {
|
||||
return Paths.get(getJavaIoTmpDir(), POIFILES);
|
||||
return Path.of(getJavaIoTmpDir(), POIFILES);
|
||||
} else {
|
||||
return initDir.toPath();
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ import java.awt.Toolkit;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Properties;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ -67,7 +67,7 @@ public class FontMetricsDumper {
|
||||
props.setProperty("font." + fontName + ".widths", widths.toString());
|
||||
}
|
||||
|
||||
try (OutputStream fileOut = Files.newOutputStream(Paths.get("font_metrics.properties"))) {
|
||||
try (OutputStream fileOut = Files.newOutputStream(Path.of("font_metrics.properties"))) {
|
||||
props.store(fileOut, "Font Metrics");
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ package org.apache.poi.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -85,7 +85,7 @@ public class HexRead {
|
||||
}
|
||||
|
||||
public static byte[] readData( String filename, String section ) throws IOException {
|
||||
return readData(Files.newInputStream(Paths.get(filename)), section);
|
||||
return readData(Files.newInputStream(Path.of(filename)), section);
|
||||
}
|
||||
|
||||
@SuppressWarnings("fallthrough")
|
||||
|
||||
@ -19,7 +19,6 @@ package org.apache.poi.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* Username-aware subclass of {@link DefaultTempFileCreationStrategy}
|
||||
@ -45,7 +44,7 @@ public class UserNameAwareTempFileCreationStrategy extends DefaultTempFileCreati
|
||||
if (null != username && !username.isEmpty()) {
|
||||
poifilesDir += "_" + username;
|
||||
}
|
||||
return Paths.get(tmpDir, poifilesDir);
|
||||
return Path.of(tmpDir, poifilesDir);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -29,6 +29,7 @@ import java.util.Calendar;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.apache.poi.hssf.HSSFTestDataSamples;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
@ -365,7 +366,7 @@ public final class TestHSSFDataFormatter {
|
||||
log("\n==== DEFAULT NUMBER FORMAT ====");
|
||||
while (it.hasNext()) {
|
||||
Cell cell = it.next();
|
||||
cell.setCellValue(cell.getNumericCellValue() * Math.random() / 1000000 - 1000);
|
||||
cell.setCellValue(cell.getNumericCellValue() * ThreadLocalRandom.current().nextDouble() / 1000000 - 1000);
|
||||
log(formatter.formatCellValue(cell));
|
||||
|
||||
String formatted = formatter.formatCellValue(cell);
|
||||
|
||||
@ -26,7 +26,7 @@ import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -369,7 +369,7 @@ public final class ExcelCetabFunctionExtractor {
|
||||
throw new IllegalStateException("Did not find file " + SOURCE_DOC_FILE_NAME + " in the resources");
|
||||
}
|
||||
|
||||
try (InputStream stream = Files.newInputStream(Paths.get(SOURCE_DOC_FILE_NAME))) {
|
||||
try (InputStream stream = Files.newInputStream(Path.of(SOURCE_DOC_FILE_NAME))) {
|
||||
File outFile = new File("functionMetadataCetab.txt");
|
||||
|
||||
processFile(stream, outFile);
|
||||
|
||||
@ -21,7 +21,6 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.apache.poi.util.DefaultTempFileCreationStrategy.POIFILES;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@ -33,7 +32,7 @@ class UserNameAwareTempFileCreationStrategyTest {
|
||||
UserNameAwareTempFileCreationStrategy strategy = new UserNameAwareTempFileCreationStrategy();
|
||||
String tmpDir = System.getProperty(TempFile.JAVA_IO_TMPDIR);
|
||||
String username = System.getProperty("user.name");
|
||||
String expectedPath = Paths.get(tmpDir, POIFILES + "_" + username).toString();
|
||||
String expectedPath = Path.of(tmpDir, POIFILES + "_" + username).toString();
|
||||
|
||||
Path actualPath = strategy.getPOIFilesDirectoryPath();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user