This is an automated email from the ASF dual-hosted git repository. leerho pushed a commit to branch improve_util_numdigits in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit 1734af9ad47b6f39d233adde31958d01d15aa35c Author: Lee Rhodes <[email protected]> AuthorDate: Sun Sep 13 12:21:38 2026 -0700 Revert to main --- .../java/org/apache/datasketches/common/Util.java | 48 +++++++++++----------- .../org/apache/datasketches/common/UtilTest.java | 2 + 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/apache/datasketches/common/Util.java b/src/main/java/org/apache/datasketches/common/Util.java index 8412fd24c..afb080501 100644 --- a/src/main/java/org/apache/datasketches/common/Util.java +++ b/src/main/java/org/apache/datasketches/common/Util.java @@ -620,7 +620,7 @@ public final class Util { } /** Logarithm related ************************/ - + /** * The log<sub>2</sub>(value) * @param value the given value @@ -719,7 +719,7 @@ public final class Util { } /** Checks that throw ************************/ - + /** * Check the requested offset and length against the allocated size. * The invariants equation is: {@code 0 <= reqOff <= reqLen <= reqOff + reqLen <= allocSize}. @@ -796,7 +796,7 @@ public final class Util { } /** Decimal Digits ***************************/ - + /** * Computes the number of decimal digits of the number n * @param n the given number @@ -808,7 +808,7 @@ public final class Util { } /** Generic relational tests *****************/ - + /** * Finds the minimum of two generic items * @param <T> the type @@ -971,7 +971,7 @@ public final class Util { } /** Seed Hashes ******************************/ - + /** * Computes and checks the 16-bit seed hash from the given long seed. * The seed hash may not be zero in order to maintain compatibility with older serialized @@ -1004,25 +1004,25 @@ public final class Util { } return seedHashA; } - + /** Files and File Bytes ******************************/ /** - * Windows, POSIX, and JAR friendly, returns a byte array of the contents of the file defined by the given + * Windows, POSIX, and JAR friendly, returns a byte array of the contents of the file defined by the given * resourceName. * If the resource is in a JAR it will be copied into the File System as a temporary file first. - * + * * @param resourceName the short name or the full path name. * @return a byte array of the contents of the file defined by the given resourceName. */ public static byte[] getResourceBytes(final String resourceName) { Objects.requireNonNull(resourceName, "Given resourceName must not be null"); - + String normalizedName = resourceName.replace('\\', '/'); if (normalizedName.startsWith("/")) { normalizedName = normalizedName.substring(1); } - + final ClassLoader loader = Util.class.getClassLoader(); try (InputStream in = loader.getResourceAsStream(normalizedName)) { if (in == null) { @@ -1037,10 +1037,10 @@ public final class Util { /** * Windows, POSIX, and JAR friendly get Resource File. * If the resource is in a JAR it will be copied into the File System as a temporary file first. - * - * <p>While tempFile.deleteOnExit() works, keep in mind that JVMs running long processes won't delete those files - * until the JVM completely terminates, which can lead to memory/disk leaks if this method is called frequently. - * If you're using this for memory-mapped files, consider explicitly deleting the file once the memory-mapped buffer + * + * <p>While tempFile.deleteOnExit() works, keep in mind that JVMs running long processes won't delete those files + * until the JVM completely terminates, which can lead to memory/disk leaks if this method is called frequently. + * If you're using this for memory-mapped files, consider explicitly deleting the file once the memory-mapped buffer * is no longer in use, or registering a custom shutdown hook if deleteOnExit() is insufficient.</p> * @param resourceName the simple file name or full path name. * Any back-slashes will be converted to forward slashes and a leading forward slash will be removed. @@ -1053,19 +1053,19 @@ public final class Util { // Normalize name: ClassLoaders MUST use forward slashes even on Windows String normalizedName = resourceName.replace('\\', '/'); if (normalizedName.startsWith("/")) { normalizedName = normalizedName.substring(1); } - + final ClassLoader loader = Util.class.getClassLoader(); final URL url = loader.getResource(normalizedName); if (url == null) { throw new IllegalArgumentException("Resource not found: " + normalizedName); } - + // If it's a real file, return it directly if ("file".equals(url.getProtocol())) { - try { + try { final URI uri = url.toURI(); - return new File(uri); } + return new File(uri); } catch (final URISyntaxException e) { return new File(url.getPath()); } } - + // If it's in a JAR, we must extract it for Memory.map() to work // We use a prefix that won't collide with Windows reserved names // We use NIO Files.createTempFile to ensure secure default permissions (0600) @@ -1073,17 +1073,17 @@ public final class Util { try { tempFile = Files.createTempFile("datasketches-", ".bin").toFile(); } catch (final IOException e1) { throw new IllegalArgumentException(e1); } tempFile.deleteOnExit(); - + try (InputStream in = loader.getResourceAsStream(normalizedName)) { if (in == null) { throw new IllegalArgumentException("Could not open stream for " + normalizedName); } - + // Use REPLACE_EXISTING to avoid "File Already Exists" errors on Windows retries Files.copy(in, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (final IOException e) { throw new IllegalArgumentException(e); } - + // Final Windows Fix: Ensure the file is actually writable if you need to setReadOnly later - //tempFile.setWritable(true); - + //tempFile.setWritable(true); + return tempFile; } diff --git a/src/test/java/org/apache/datasketches/common/UtilTest.java b/src/test/java/org/apache/datasketches/common/UtilTest.java index ca6445b3a..f9f0b09ae 100644 --- a/src/test/java/org/apache/datasketches/common/UtilTest.java +++ b/src/test/java/org/apache/datasketches/common/UtilTest.java @@ -433,6 +433,8 @@ public class UtilTest { assertEquals(v, v2); } + + @Test public void printlnTest() { println("PRINTING: " + this.getClass().getName()); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
