Fix get_file_bytes and put_file_bytes.
diff --git a/pom.xml b/pom.xml
index a5ab622..2b9be8b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
- <version>35</version>
+ <version>37</version>
</parent>
<groupId>org.apache.datasketches</groupId>
@@ -82,7 +82,7 @@
<properties>
<!-- Test -->
- <testng.version>7.11.0</testng.version>
+ <testng.version>7.12.0</testng.version>
<!-- these are TestNG groups used for excluding / including groups of tests. See profiles section. -->
<testng.generate-java-files>generate_java_files</testng.generate-java-files>
<testng.check-cpp-files>check_cpp_files</testng.check-cpp-files>
@@ -90,30 +90,37 @@
<testng.check-cpp-historical-files>check_cpp_historical_files</testng.check-cpp-historical-files>
<!-- System-wide properties -->
- <maven.version>3.9.11</maven.version>
+ <maven.version>3.9.12</maven.version>
<java.version>25</java.version>
- <!-- removed: g -Duser.language=en -Duser.country=US -Dfile.encoding=UTF-8 -->
- <jvm.options>-Xmx4g</jvm.options> <!-- use space to separate args -->
+ <maven.compiler.release>${java.version}</maven.compiler.release>
+ <jvm.mem>-Xmx4g</jvm.mem>
+ <jvm.locale.language>-Duser.language=en</jvm.locale.language>
+ <jvm.locale.country>-Duser.country=US</jvm.locale.country>
+ <jvm.locale.encoding>-Dfile.encoding=UTF-8</jvm.locale.encoding>
+ <jvm.args>${jvm.mem} ${jvm.locale.language} ${jvm.locale.country} ${jvm.locale.encoding}</jvm.args>
<charset.encoding>UTF-8</charset.encoding>
<project.build.sourceEncoding>${charset.encoding}</project.build.sourceEncoding>
<project.build.resourceEncoding>${charset.encoding}</project.build.resourceEncoding>
<project.reporting.outputEncoding>${charset.encoding}</project.reporting.outputEncoding>
<maven.build.timestamp.format>yyyy-MM-dd'T'HH-mm-ss'Z'</maven.build.timestamp.format>
- <!-- org.apache.maven plugins -->
+ <!-- Covered by Apache Parent POM -->
+ <!-- org.apache.maven plugins -->
+ <maven-compiler-plugin.version>3.15.0</maven-compiler-plugin.version> <!-- parent 37: 3.14.1 -->
<maven-javadoc-plugin.version>3.12.0</maven-javadoc-plugin.version>
+ <!-- org.apache.creadur plugins -->
+ <apache-rat-plugin.version>0.17</apache-rat-plugin.version> <!-- parent 37: 0.16.1 -->
+
+ <!-- Not covered by Apache Parent POM-->
<maven-toolchains-plugin.version>3.2.0</maven-toolchains-plugin.version>
- <!-- com.github plugins -->
- <git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
- <!-- org.apache.creadur plugins -->
- <apache-rat-plugin.version>0.17</apache-rat-plugin.version>
+ <!-- io.github plugins -->
+ <git-commit-id-maven-plugin.version>9.0.2</git-commit-id-maven-plugin.version>
+
<!-- org.eluder maven plugins -->
<coveralls-repo-token></coveralls-repo-token>
- <coveralls-maven-plugin.version>4.3.0</coveralls-maven-plugin.version>
+ <coveralls-maven-plugin.version>5.0.0</coveralls-maven-plugin.version>
<!-- org.jacoco.maven plugins -->
<jacoco-maven-plugin.version>0.8.14</jacoco-maven-plugin.version>
- <!-- org.mojohaus plugins -->
- <versions-maven-plugin.version>2.19.1</versions-maven-plugin.version>
<!-- other -->
<lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
</properties>
@@ -129,22 +136,261 @@
</dependencies>
<build>
- <pluginManagement>
- <plugins>
- <plugin>
- <!-- Apache Parent pom, pluginManagement-->
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <!-- by default, exclude all snapshot targets -->
- <!-- this will be overridden on dedicated profile -->
- <excludedGroups>${testng.generate-java-files},${testng.check-cpp-files},${testng.check-go-files},${testng.check-cpp-historical-files}</excludedGroups>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
+ <pluginManagement>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <!-- version from Parent -->
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <!-- version from Parent -->
+ <configuration>
+ <fork>true</fork>
+ <release>${java.version}</release>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <!-- Apache Parent pom: apache-release profile -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <!-- version from Parent -->
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-enforcer-plugin</artifactId>
+ <!-- version from Parent -->
+ <executions>
+ <execution>
+ <id>enforce-banned-dependencies</id>
+ <goals>
+ <goal>enforce</goal>
+ </goals>
+ <configuration>
+ <rules>
+ <!-- The normal Java enforcer rule out of the box is toolchain unaware
+ and is really only usefull for checking what java version is available
+ via the users shell environment. It does not check that the java compiler
+ version is sane or matches the java command version.
+ In the context of toolchains this rule is useless.
+ See: https://github.com/paulmoloney/maven-enforcer-toolchain-rules
+ <requireJavaVersion> ... </requireJavaVersion>
+ -->
+ <requireMavenVersion>
+ <version>[${maven.version},4.0.0)</version>
+ </requireMavenVersion>
+ <bannedDependencies>
+ <excludes>
+ <!--LGPL licensed library-->
+ <exclude>com.google.code.findbugs:annotations</exclude>
+ </excludes>
+ </bannedDependencies>
+ </rules>
+ <fail>true</fail>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <!-- version from Parent -->
+ <executions>
+ <execution>
+ <id>default-jar</id>
+ <phase>package</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-test-jar</id>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <!-- version from Parent -->
+ <configuration>
+ <excludePackageNames>org.apache.datasketches.memory/internal</excludePackageNames>
+ <docfilessubdirs>true</docfilessubdirs>
+ <show>public</show>
+ <doclint>all,-missing</doclint>
+ <additionalJOptions>
+ <additionalJOption>${jvm.mem}</additionalJOption>
+ <additionalJOption>${jvm.locale.language}</additionalJOption>
+ <additionalJOption>${jvm.locale.country}</additionalJOption>
+ <additionalJOption>${jvm.locale.encoding}</additionalJOption>
+ </additionalJOptions>
+ </configuration>
+ <executions>
+ <execution>
+ <id>attach-javadocs</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-release-plugin</artifactId>
+ <!-- version from Parent -->
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <!-- version from Parent -->
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <phase>package</phase>
+ <goals>
+ <goal>jar-no-fork</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>attach-test-sources</id>
+ <phase>package</phase>
+ <goals>
+ <goal>test-jar-no-fork</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <!-- version from Parent -->
+ <configuration>
+ <argLine>@{jvm.args}</argLine>
+ <jdkToolchain>
+ <version>${java.version}</version>
+ </jdkToolchain>
+ <trimStackTrace>false</trimStackTrace>
+ <useManifestOnlyJar>false</useManifestOnlyJar>
+ <redirectTestOutputToFile>false</redirectTestOutputToFile>
+ <reportsDirectory>${project.build.directory}/test-output</reportsDirectory>
+ <suiteXmlFiles>
+ <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
+ </suiteXmlFiles>
+ <perCoreThreadCount>false</perCoreThreadCount>
+ <excludedGroups>${testng.generate-java-files},${testng.check-cpp-files},${testng.check-go-files},${testng.check-cpp-historical-files}</excludedGroups>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-toolchains-plugin</artifactId>
+ <version>${maven-toolchains-plugin.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>toolchain</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <toolchains>
+ <jdk>
+ <version>${java.version}</version>
+ </jdk>
+ </toolchains>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>${apache-rat-plugin.version}</version>
+ <executions>
+ <execution>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <outputDirectory>${project.basedir}/rat</outputDirectory>
+ <consoleOutput>true</consoleOutput>
+ <useDefaultExcludes>true</useDefaultExcludes>
+ <excludes>
+ <!-- rat uses .gitignore for excludes by default -->
+ <inputExcludeStd>StandardCollection</inputExcludeStd>
+ <inputExclude>**/*.yaml</inputExclude>
+ <inputExclude>**/*.yml</inputExclude>
+ <inputExclude>**/.*</inputExclude>
+ <inputExclude>**/test/resources/**/*.txt</inputExclude>
+ <inputExclude>**/git.properties</inputExclude>
+ <inputExclude>**/doc/**</inputExclude>
+ <inputExclude>**/*.sk</inputExclude>
+ <inputExclude>LICENSE</inputExclude>
+ <inputExclude>NOTICE</inputExclude>
+ <inputExclude>**/*.code-workspace</inputExclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <!-- Submit code coverage report to Coveralls.io. -->
+ <groupId>com.github.hazendaz.maven</groupId>
+ <artifactId>coveralls-maven-plugin</artifactId>
+ <version>${coveralls-maven-plugin.version}</version>
+ <configuration>
+ <repoToken>${coveralls-repo-token}</repoToken>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <!-- Generates code coverage report banner for website. -->
+ <groupId>org.jacoco</groupId>
+ <artifactId>jacoco-maven-plugin</artifactId>
+ <version>${jacoco-maven-plugin.version}</version>
+ <executions>
+ <execution>
+ <id>default-prepare-agent</id>
+ <goals>
+ <goal>prepare-agent</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>default-report</id>
+ <phase>test</phase>
+ <goals>
+ <goal>report</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <groupId>io.github.git-commit-id</groupId>
+ <artifactId>git-commit-id-maven-plugin</artifactId>
+ <version>${git-commit-id-maven-plugin.version}</version>
+ </plugin>
+
+ </plugins>
+ </pluginManagement>
+
+ <plugins>
+
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
@@ -153,102 +399,26 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <fork>true</fork>
- <release>${java.version}</release>
- <compilerArgs>
- <arg>-J${jvm.options}</arg> <!-- comma separated or separate args -->
- </compilerArgs>
- </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- </plugin>
-
- <plugin>
- <!-- We want to deploy the artifacts to a staging location for perusal -->
- <!-- Apache Parent pom: apache-release profile -->
- <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
- <executions>
- <execution>
- <id>enforce-banned-dependencies</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <requireJavaVersion>
- <version>[25,)</version>
- </requireJavaVersion>
- <requireMavenVersion>
- <version>[${maven.version},)</version>
- </requireMavenVersion>
- <!-- <dependencyConvergence /> -->
- <bannedDependencies>
- <excludes>
- <!--LGPL licensed library-->
- <exclude>com.google.code.findbugs:annotations</exclude>
- </excludes>
- </bannedDependencies>
- </rules>
- <fail>true</fail>
- </configuration>
- </execution>
- </executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <id>default-jar</id>
- <phase>package</phase>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- <execution>
- <id>default-test-jar</id>
- <phase>package</phase>
- <goals>
- <goal>test-jar</goal>
- </goals>
- </execution>
- </executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
- <version>${maven-javadoc-plugin.version}</version><!--$NO-MVN-MAN-VER$-->
- <configuration>
- <outputDirectory>${project.reporting.outputDirectory}</outputDirectory>
- <jarOutputDirectory>${project.reporting.outputDirectory}</jarOutputDirectory>
- <docfilessubdirs>true</docfilessubdirs>
- <show>public</show>
- <doclint>all,-missing</doclint>
- <release>${java.version}</release>
- <additionalJOptions> <!-- requires -J prefix -->
- <additionalJoption>-J${jvm.options}</additionalJoption>
- </additionalJOptions>
- </configuration>
- <executions>
- <execution>
- <id>attach-javadocs</id>
- <goals>
- <goal>jar</goal>
- </goals>
- </execution>
- </executions>
</plugin>
<plugin>
@@ -259,132 +429,36 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-sources</id>
- <phase>package</phase>
- <goals>
- <goal>jar-no-fork</goal>
- </goals>
- </execution>
- <execution>
- <id>attach-test-sources</id>
- <phase>package</phase>
- <goals>
- <goal>test-jar-no-fork</goal>
- </goals>
- </execution>
- </executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <forkCount>1</forkCount>
- <reuseForks>true</reuseForks>
- <argLine>${argLine} ${jvm.options}</argLine> <!-- use space to separate args -->
- <trimStackTrace>false</trimStackTrace>
- <useManifestOnlyJar>false</useManifestOnlyJar>
- <redirectTestOutputToFile>true</redirectTestOutputToFile>
- <reportsDirectory>${project.build.directory}/test-output/${maven.build.timestamp}</reportsDirectory>
- </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
- <version>${maven-toolchains-plugin.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>toolchain</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <toolchains>
- <jdk>
- <version>${java.version}</version>
- </jdk>
- </toolchains>
- </configuration>
</plugin>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
- <version>${apache-rat-plugin.version}</version><!--$NO-MVN-MAN-VER$-->
- <executions>
- <execution>
- <phase>verify</phase>
- <goals>
- <goal>check</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <outputDirectory>${project.basedir}/rat</outputDirectory>
- <consoleOutput>true</consoleOutput>
- <inputExcludes>
- <!-- I think rat uses .gitignore for excludes by default -->
- <inputExcludeStd>StandardCollection</inputExcludeStd>
- <inputExclude>**/*.yaml</inputExclude>
- <inputExclude>**/*.yml</inputExclude>
- <inputExclude>**/.*</inputExclude>
- <inputExclude>**/test/resources/**/*.txt</inputExclude>
- <inputExclude>**/git.properties</inputExclude>
- <inputExclude>**/doc/**</inputExclude>
- <inputExclude>**/*.sk</inputExclude>
- <inputExclude>LICENSE</inputExclude>
- <inputExclude>NOTICE</inputExclude>
- <inputExclude>**/*.code-workspace</inputExclude>
- </inputExcludes>
- </configuration>
</plugin>
<plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>versions-maven-plugin</artifactId>
- <version>${versions-maven-plugin.version}</version>
+ <groupId>com.github.hazendaz.maven</groupId>
+ <artifactId>coveralls-maven-plugin</artifactId>
</plugin>
<plugin>
- <!-- Submit code coverage report to Coveralls.io. -->
- <groupId>org.eluder.coveralls</groupId>
- <artifactId>coveralls-maven-plugin</artifactId>
- <version>${coveralls-maven-plugin.version}</version>
- <configuration>
- <repoToken>${coveralls-repo-token}</repoToken>
- </configuration>
- </plugin>
-
- <plugin>
- <!-- Generates code coverage report from website. -->
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
- <version>${jacoco-maven-plugin.version}</version>
- <executions>
- <execution>
- <id>default-prepare-agent</id>
- <goals>
- <goal>prepare-agent</goal>
- </goals>
- </execution>
- <execution>
- <id>default-report</id>
- <phase>test</phase>
- <goals>
- <goal>report</goal>
- </goals>
- </execution>
- </executions>
</plugin>
<plugin>
- <groupId>pl.project13.maven</groupId>
- <artifactId>git-commit-id-plugin</artifactId>
- <version>${git-commit-id-plugin.version}</version>
+ <groupId>io.github.git-commit-id</groupId>
+ <artifactId>git-commit-id-maven-plugin</artifactId>
</plugin>
</plugins>
@@ -408,8 +482,8 @@
<plugins>
<plugin>
<groupId>pl.project13.maven</groupId>
- <artifactId>git-commit-id-plugin</artifactId>
- <version>${git-commit-id-plugin.version}</version>
+ <artifactId>git-commit-id-maven-plugin</artifactId>
+ <version>${git-commit-id-maven-plugin.version}</version>
<executions>
<execution>
<goals>
@@ -433,7 +507,7 @@
<includeOnlyProperties>
<includeProperty>git.branch</includeProperty>
<includeProperty>git.commit.id.full</includeProperty>
- <!-- <includeProperty>git.commit.time</includeProperty> remove for reproducible builds-->
+ <includeProperty>git.commit.time</includeProperty>
<includeProperty>git.commit.user.email</includeProperty>
<includeProperty>git.tags</includeProperty>
</includeOnlyProperties>
@@ -452,7 +526,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <version>${maven-jar-plugin.version}</version>
+ <!-- version from Parent -->
<executions>
<execution>
<id>default-jar</id>
diff --git a/src/test/java/org/apache/datasketches/common/A_BeforeSuite.java b/src/test/java/org/apache/datasketches/common/A_BeforeSuite.java
new file mode 100644
index 0000000..a900046
--- /dev/null
+++ b/src/test/java/org/apache/datasketches/common/A_BeforeSuite.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.common;
+
+import org.testng.annotations.BeforeSuite;
+
+public class A_BeforeSuite {
+
+ @BeforeSuite
+ public void printTestEnvironment() {
+ System.out.println("====================================================");
+ System.out.println("TEST JDK: " + System.getProperty("java.version"));
+ System.out.println("TEST JDK HOME: " + System.getProperty("java.home"));
+ System.out.println("=====================================================");
+ }
+}
diff --git a/src/test/java/org/apache/datasketches/common/TestUtil.java b/src/test/java/org/apache/datasketches/common/TestUtil.java
index 3306790..e668ead 100644
--- a/src/test/java/org/apache/datasketches/common/TestUtil.java
+++ b/src/test/java/org/apache/datasketches/common/TestUtil.java
@@ -19,22 +19,9 @@
package org.apache.datasketches.common;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
import java.nio.file.Files;
-import java.nio.file.LinkOption;
-import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
import java.util.Objects;
/**
@@ -65,47 +52,59 @@
* The project relative Path for Go serialized sketches to be tested by Java.
*/
public static final Path goPath = Path.of(".", "serialization_test_data", "go_generated_files");
-
+
/**
* The project relative Path for Rust serialized sketches to be tested by Java.
*/
public static final Path rustPath = Path.of(".", "serialization_test_data", "rust_generated_files");
-
+
/**
* The project relative Path for /src/test/resources
*/
public static final Path resPath = Path.of(".","src","test","resources");
+ public enum Existence { MUST_EXIST, WARNING }
/**
* Gets all the bytes of a file as a byte array.
- * If the file is missing, this writes a warning message to the console.
+ * If the file is missing, this either throws an exception or writes a warning message to the console
+ * based on the state of {@link #Existence Existence}.
* @param basePath the base directory path where the file is located
* @param fileName the simple file name of the file
- * @return a byte array
- * @throws RuntimeException for IO errors, or if resolved path is not a file or not readable.
+ * @param option an optional parameter. If option == Existence.MUST_EXIST and the file does not exist an exception will be thrown.
+ * If option == Existence.WARNING, or not given, and the file does not exist, it writes a warning message
+ * to {@link System.err.out System.err.out}.
+ * If option has more than one argument an exception will be thrown.
+ * @return a byte array. It may be empty.
+ * @throws RuntimeException for IO errors, or if resolved path is not a file or not readable or optionally not found.
*/
- public static byte[] getFileBytes(final Path basePath, final String fileName) throws RuntimeException {
+ public static byte[] getFileBytes(final Path basePath, final String fileName, Existence... option) {
Objects.requireNonNull(basePath, "input parameter 'Path basePath' cannot be null.");
Objects.requireNonNull(fileName, "input parameter 'String fileName' cannot be null.");
+ if (option.length > 1) { throw new IllegalArgumentException("Existence option has a maximum of one argument"); }
+ Existence status = (option.length == 1) ? option[0] : Existence.WARNING;
+
Path path = Path.of(basePath.toString(), fileName);
Path absPath = path.toAbsolutePath(); //for error output
- byte[] bytes = new byte[0]; //or null
- if (Files.notExists(path)) { //In this specific case, just issue warning.
- System.err.println("File disappeared or not found: " + absPath);
- return bytes; //empty
+ if (Files.notExists(path)) {
+ if (status == Existence.MUST_EXIST) {
+ throw new RuntimeException("File disappeared or not found: " + absPath);
+ } else {
+ System.err.println("WARNING: File disappeared or not found: " + absPath);
+ return new byte[0];
+ }
}
if (!Files.isRegularFile(path) || !Files.isReadable(path)) {
throw new RuntimeException("Path is not a regular file or not readable: " + absPath);
}
try {
- bytes = Files.readAllBytes(path);
+ byte[] bytes = Files.readAllBytes(path);
return bytes;
} catch (IOException e) {
throw new RuntimeException("System IO Error reading file: " + absPath + " " + e);
}
}
-
+
/**
* Puts all the bytes of the given byte array to a file with the given fileName.
* This assumes that the base directory path is {@link #javaPath javaPath}.
@@ -113,17 +112,18 @@
* @param bytes the given byte array
*/
public static void putBytesToJavaPathFile(final String fileName, final byte[] bytes) {
- putBytesToFile(javaPath, fileName, bytes);
+ putFileBytes(javaPath, fileName, bytes);
}
-
+
/**
* Puts all the bytes of the given byte array to a basePath file with the given fileName.
+ * If the file exists it will be overwritten.
* @param basePath the directory path for the given fileName
* @param fileName the name of the target file
* @param bytes the given byte array
* @throws RuntimeException for IO errors,
*/
- public static void putBytesToFile(final Path basePath, final String fileName, final byte[] bytes) {
+ public static void putFileBytes(final Path basePath, final String fileName, final byte[] bytes) {
Objects.requireNonNull(basePath, "input parameter 'Path basePath' cannot be null.");
Objects.requireNonNull(fileName, "input parameter 'String fileName' cannot be null.");
Objects.requireNonNull(bytes, "input parameter 'byte[] bytes' cannot be null.");
diff --git a/src/test/java/org/apache/datasketches/common/TestUtilTest.java b/src/test/java/org/apache/datasketches/common/TestUtilTest.java
index 420b05c..60668c1 100644
--- a/src/test/java/org/apache/datasketches/common/TestUtilTest.java
+++ b/src/test/java/org/apache/datasketches/common/TestUtilTest.java
@@ -19,23 +19,19 @@
package org.apache.datasketches.common;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putFileBytes;
import static org.apache.datasketches.common.TestUtil.resPath;
-
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertTrue;
//import static org.testng.internal.EclipseInterface.ASSERT_LEFT; // Ignore, standard imports
import static org.testng.Assert.assertNotNull;
-
-import org.testng.annotations.AfterMethod;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
+import static org.testng.Assert.assertTrue;
import java.io.IOException;
-import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.Arrays;
-import static java.nio.charset.StandardCharsets.UTF_8;
+
+import org.testng.annotations.Test;
public class TestUtilTest {
@@ -49,7 +45,7 @@
@Test
public void testGetFileBytes_MissingFile() {
- byte[] resultBytes = getFileBytes(resPath, "NonExistentFile");
+ byte[] resultBytes = getFileBytes(resPath, "Test_NonExistentFile_OK");
assertNotNull(resultBytes);
assertEquals(resultBytes.length, 0, "Should return empty array for missing file.");
}
@@ -59,11 +55,18 @@
try {
getFileBytes(resPath, "");
} catch (RuntimeException e) {
- System.out.println(e.toString());
+ System.out.println("Test: Not regular file or not readable: OK\n" + " " + e.toString());
}
}
-
-
-
-
+
+ private static final Path testPath = Path.of(".", "target", "testDir");
+
+ @Test
+ public void testPutBytesToFile() {
+ byte[] gettysBytes = getFileBytes(resPath, "GettysburgAddress.txt");
+ putFileBytes(testPath, "GettysburgAddressCopy.txt", gettysBytes);
+ byte[] gettysBytes2 = getFileBytes(testPath, "GettysburgAddressCopy.txt");
+ assertEquals(gettysBytes, gettysBytes2);
+ }
+
}
diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml
new file mode 100644
index 0000000..d42c27e
--- /dev/null
+++ b/src/test/resources/testng.xml
@@ -0,0 +1,28 @@
+<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+<suite name="DSJavaSuite">
+ <test name="AllMemoryTests">
+ <packages>
+ <package name="org.apache.datasketches.java.*" />
+ </packages>
+ </test>
+</suite>