Usage of try-with-resources
pom file cleanup
This commit is contained in:
parent
09d3530d44
commit
7d485d0e8b
24
pom.xml
24
pom.xml
@ -24,9 +24,8 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
<maven.compiler.parameters>true</maven.compiler.parameters>
|
||||
<maven.compiler.release>${java.version}</maven.compiler.release>
|
||||
<maven.compiler.release>21</maven.compiler.release>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
@ -100,11 +99,11 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.12.1</version>
|
||||
<configuration>
|
||||
<enablePreview>true</enablePreview>
|
||||
<parameters>true</parameters>
|
||||
<compilerArgs>
|
||||
<compilerArg>--enable-preview</compilerArg>
|
||||
<compilerArg>--add-modules</compilerArg>
|
||||
<compilerArg>java.base,jdk.incubator.vector</compilerArg>
|
||||
</compilerArgs>
|
||||
@ -118,17 +117,17 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-deploy-plugin</artifactId>
|
||||
<version>3.0.0-M1</version>
|
||||
<version>3.1.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M3</version>
|
||||
<version>3.3.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<version>3.0.0-M1</version>
|
||||
<version>3.1.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
@ -143,12 +142,17 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-site-plugin</artifactId>
|
||||
<version>3.9.1</version>
|
||||
<version>3.12.1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
<version>3.2.3</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-wrapper-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
@ -223,7 +227,7 @@
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireJavaVersion>
|
||||
<version>[${java.version},)</version>
|
||||
<version>${maven.compiler.release}</version>
|
||||
</requireJavaVersion>
|
||||
<requirePluginVersions>
|
||||
<banLatest>true</banLatest>
|
||||
|
@ -16,16 +16,14 @@
|
||||
package dev.morling.onebrc;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.util.Arrays;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class CreateMeasurements {
|
||||
|
||||
private static final String FILE = "./measurements.txt";
|
||||
private static final Path MEASUREMENT_FILE = Path.of("./measurements.txt");
|
||||
|
||||
private record WeatherStation(String id, double meanTemperature) {
|
||||
double measurement() {
|
||||
@ -76,7 +74,7 @@ public class CreateMeasurements {
|
||||
// )
|
||||
// ) TO 'output.csv' (HEADER, DELIMITER ',');
|
||||
// @formatter:on
|
||||
List<WeatherStation> stations = Arrays.asList(
|
||||
List<WeatherStation> stations = List.of(
|
||||
new WeatherStation("Abha", 18.0),
|
||||
new WeatherStation("Abidjan", 26.0),
|
||||
new WeatherStation("Abéché", 29.4),
|
||||
@ -491,20 +489,17 @@ public class CreateMeasurements {
|
||||
new WeatherStation("Zanzibar City", 26.0),
|
||||
new WeatherStation("Zürich", 9.3));
|
||||
|
||||
File measurements = new File(FILE);
|
||||
try (FileOutputStream fos = new FileOutputStream(measurements); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));) {
|
||||
try (BufferedWriter bw = Files.newBufferedWriter(MEASUREMENT_FILE)) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
if (i > 0 && i % 50_000_000 == 0) {
|
||||
System.out.println("Wrote %,d measurements in %s ms".formatted(i, System.currentTimeMillis() - start));
|
||||
System.out.printf("Wrote %,d measurements in %s ms%n", i, System.currentTimeMillis() - start);
|
||||
}
|
||||
WeatherStation station = stations.get(ThreadLocalRandom.current().nextInt(stations.size()));
|
||||
bw.write(station.id());
|
||||
bw.write(";" + station.measurement());
|
||||
bw.newLine();
|
||||
}
|
||||
bw.flush();
|
||||
|
||||
System.out.println("Created file with %,d measurements in %s ms".formatted(size, System.currentTimeMillis() - start));
|
||||
}
|
||||
System.out.printf("Created file with %,d measurements in %s ms%n", size, System.currentTimeMillis() - start);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user