proost commented on code in PR #727:
URL: https://github.com/apache/datasketches-java/pull/727#discussion_r2958089714


##########
src/test/java/org/apache/datasketches/common/TestUtil.java:
##########
@@ -19,248 +19,122 @@
 
 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.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
 import java.util.Objects;
 
 /**
  * Utilities common to testing
  */
 public final class TestUtil  {
 
-  private static final String userDir = System.getProperty("user.dir");

Review Comment:
   When run some test cases in the IDE(In my case, IntelliJ), because of this 
change, failed. 
   
   This change is good but but I think just mentioning about this in thre 
README.md or somewhere is enough for local development.



##########
src/test/java/org/apache/datasketches/common/TestUtil.java:
##########
@@ -19,248 +19,122 @@
 
 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.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
 import java.util.Objects;
 
 /**
  * Utilities common to testing
  */
 public final class TestUtil  {
 
-  private static final String userDir = System.getProperty("user.dir");
-
   /**
    * TestNG group constants
    */
   public static final String GENERATE_JAVA_FILES = "generate_java_files";
   public static final String CHECK_CPP_FILES = "check_cpp_files";
   public static final String CHECK_GO_FILES = "check_go_files";
+  public static final String CHECK_RUST_FILES = "check_rust_files";
   public static final String CHECK_CPP_HISTORICAL_FILES = 
"check_cpp_historical_files";
 
   /**
-   * The full target Path for Java serialized sketches to be tested by other 
languages.
+   * The project relative Path for Java serialized sketches to be tested by 
other languages.
    */
-  public static final Path javaPath = 
createPath("serialization_test_data/java_generated_files");
+  public static final Path javaPath = Path.of(".", "serialization_test_data", 
"java_generated_files");
 
   /**
-   * The full target Path for C++ serialized sketches to be tested by Java.
+   * The project relative Path for C++ serialized sketches to be tested by 
Java.
    */
-  public static final Path cppPath = 
createPath("serialization_test_data/cpp_generated_files");
+  public static final Path cppPath = Path.of(".", "serialization_test_data", 
"cpp_generated_files");
 
   /**
-   * The full target Path for Go serialized sketches to be tested by Java.
+   * The project relative Path for Go serialized sketches to be tested by Java.
    */
-  public static final Path goPath = 
createPath("serialization_test_data/go_generated_files");
-
-  private static Path createPath(final String projectLocalDir) {
-    try {
-      return Files.createDirectories(Paths.get(userDir, projectLocalDir));
-    } catch (IOException e) { throw new 
SketchesArgumentException(e.getCause().toString()); }
-  }
-
-  //Get Resources
-
-  private static final int BUF_SIZE = 1 << 13;
+  public static final Path goPath = Path.of(".", "serialization_test_data", 
"go_generated_files");
 
   /**
-   * Gets the file defined by the given resource file's shortFileName.
-   * @param shortFileName the last name in the pathname's name sequence.
-   * @return the file defined by the given resource file's shortFileName.
+   * The project relative Path for Rust serialized sketches to be tested by 
Java.
    */
-  public static File getResourceFile(final String shortFileName) {
-    Objects.requireNonNull(shortFileName, "input parameter 'String 
shortFileName' cannot be null.");
-    final String slashName = (shortFileName.charAt(0) == '/') ? shortFileName 
: '/' + shortFileName;
-    final URL url = TestUtil.class.getResource(slashName);
-    Objects.requireNonNull(url, "resource " + slashName + " returns null 
URL.");
-    File file;
-    file = createTempFile(slashName);
-    if (url.getProtocol().equals("jar")) { //definitely a jar
-      try (final InputStream input = 
TestUtil.class.getResourceAsStream(slashName);
-        final OutputStream out = new FileOutputStream(file)) {
-        Objects.requireNonNull(input, "InputStream  is null.");
-        int numRead = 0;
-        final byte[] buf = new byte[1024];
-        while ((numRead = input.read(buf)) != -1) { out.write(buf, 0, 
numRead); }
-      } catch (final IOException e ) { throw new RuntimeException(e); }
-    } else { //protocol says resource is not a jar, must be a file
-      file = new File(getResourcePath(url));
-    }
-    if (!file.setReadable(false, true)) {
-      throw new IllegalStateException("Failed to set owner only 'Readable' on 
file");
-    }
-    if (!file.setWritable(false, false)) {
-      throw new IllegalStateException("Failed to set everyone 'Not Writable' 
on file");
-    }
-    return file;
-  }
+  public static final Path rustPath = Path.of(".", "serialization_test_data", 
"rust_generated_files");
 
   /**
-   * Returns a byte array of the contents of the file defined by the given 
resource file's shortFileName.
-   * @param shortFileName the last name in the pathname's name sequence.
-   * @return a byte array of the contents of the file defined by the given 
resource file's shortFileName.
-   * @throws IllegalArgumentException if resource cannot be read.
+   * The project relative Path for /src/test/resources
    */
-  public static byte[] getResourceBytes(final String shortFileName) {
-    Objects.requireNonNull(shortFileName, "input parameter 'String 
shortFileName' cannot be null.");
-    final String slashName = (shortFileName.charAt(0) == '/') ? shortFileName 
: '/' + shortFileName;
-    final URL url = TestUtil.class.getResource(slashName);
-    Objects.requireNonNull(url, "resource " + slashName + " returns null 
URL.");
-    final byte[] out;
-    if (url.getProtocol().equals("jar")) { //definitely a jar
-      try (final InputStream input = 
TestUtil.class.getResourceAsStream(slashName)) {
-        out = readAllBytesFromInputStream(input);
-      } catch (final IOException e) { throw new RuntimeException(e); }
-    } else { //protocol says resource is not a jar, must be a file
-      try {
-        out = Files.readAllBytes(Paths.get(getResourcePath(url)));
-      } catch (final IOException e) { throw new RuntimeException(e); }
-    }
-    return out;
-  }
+  public static final Path resPath = Path.of(".","src","test","resources");
 
-  /**
-   * Note: This is only needed in Java 8 as it is part of Java 9+.
-   * Read all bytes from the given <i>InputStream</i>.
-   * This is limited to streams that are no longer than the maximum 
allocatable byte array determined by the VM.
-   * This may be a little smaller than <i>Integer.MAX_VALUE</i>.
-   * @param in the Input Stream
-   * @return byte array
-   */
-  public static byte[] readAllBytesFromInputStream(final InputStream in) {
-    return readBytesFromInputStream(Integer.MAX_VALUE, in);
-  }
+  public enum Existence { MUST_EXIST, WARNING }
 
   /**
-   * Note: This is only needed in Java 8 as is part of Java 9+.
-   * Read <i>numBytesToRead</i> bytes from an input stream into a single byte 
array.
-   * This is limited to streams that are no longer than the maximum 
allocatable byte array determined by the VM.
-   * This may be a little smaller than <i>Integer.MAX_VALUE</i>.
-   * @param numBytesToRead number of bytes to read
-   * @param in the InputStream
-   * @return the filled byte array from the input stream
-   * @throws IllegalArgumentException if array size grows larger than what can 
be safely allocated by some VMs.
-
+   * Gets all the bytes of a file as a byte array.
+   * If the file is missing, this either throws an exception or writes a 
warning message to the console
+   * based on the state of the optional {@link #Existence Existence}.
+   * @param basePath the base directory path where the file is located
+   * @param fileName the simple file name of the file
+   * @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}.

Review Comment:
   typo? System.err System.out



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to