You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sh...@apache.org on 2024/02/12 18:15:12 UTC

(daffodil-extra) branch main updated (3eb1acc -> cc7f52e)

This is an automated email from the ASF dual-hosted git repository.

shanedell pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-extra.git


    from 3eb1acc  First version (0.1.0) of lsbfdump tool
     new 6154804  Add lsbfdump example using Scala and Rust
     new 1730581  remove Cargo.lock from git, add to gitignore
     new 6237b5f  remove CustomSeek code, rename read_seek.rs to stdin_seek.rs
     new cc7f52e  remove StdinSeek and instead loop over reading of stdin

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitignore                                         |   7 ++
 {lsbfdump => lsbfdump-jni-rs}/LICENSE              |   0
 lsbfdump-jni-rs/README.md                          |  76 +++++++++++++++
 lsbfdump-jni-rs/build.sbt                          |  35 +++++++
 lsbfdump-jni-rs/native/Cargo.toml                  |  11 +++
 lsbfdump-jni-rs/native/src/helper_functions.rs     |  69 ++++++++++++++
 lsbfdump-jni-rs/native/src/lib.rs                  |  97 +++++++++++++++++++
 .../project/build.properties                       |   0
 lsbfdump-jni-rs/project/plugins.sbt                |   2 +
 .../scala/org/apache/daffodil/lsbfDump/FFI.scala   |  13 ++-
 .../org/apache/daffodil/lsbfDump/LSBFDump.scala    | 105 +--------------------
 .../org/apache/daffodil/lsbfDump/FFITest.scala     |  22 ++++-
 lsbfdump/build.sbt                                 |   2 +
 13 files changed, 334 insertions(+), 105 deletions(-)
 copy {lsbfdump => lsbfdump-jni-rs}/LICENSE (100%)
 create mode 100644 lsbfdump-jni-rs/README.md
 create mode 100644 lsbfdump-jni-rs/build.sbt
 create mode 100644 lsbfdump-jni-rs/native/Cargo.toml
 create mode 100644 lsbfdump-jni-rs/native/src/helper_functions.rs
 create mode 100644 lsbfdump-jni-rs/native/src/lib.rs
 copy {lsbfdump => lsbfdump-jni-rs}/project/build.properties (100%)
 create mode 100644 lsbfdump-jni-rs/project/plugins.sbt
 copy lsbfdump/project/plugins.sbt => lsbfdump-jni-rs/src/main/scala/org/apache/daffodil/lsbfDump/FFI.scala (73%)
 copy {lsbfdump => lsbfdump-jni-rs}/src/main/scala/org/apache/daffodil/lsbfDump/LSBFDump.scala (55%)
 copy lsbfdump/project/plugins.sbt => lsbfdump-jni-rs/src/test/scala/org/apache/daffodil/lsbfDump/FFITest.scala (62%)


(daffodil-extra) 04/04: remove StdinSeek and instead loop over reading of stdin

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shanedell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-extra.git

commit cc7f52e5806d2f064729837e0279bfa73c5e9470
Author: Shane Dell <sh...@gmail.com>
AuthorDate: Wed Feb 7 22:29:07 2024 -0500

    remove StdinSeek and instead loop over reading of stdin
---
 lsbfdump-jni-rs/native/src/helper_functions.rs | 19 +++++++++-----
 lsbfdump-jni-rs/native/src/lib.rs              |  1 -
 lsbfdump-jni-rs/native/src/stdin_seek.rs       | 34 --------------------------
 3 files changed, 13 insertions(+), 41 deletions(-)

diff --git a/lsbfdump-jni-rs/native/src/helper_functions.rs b/lsbfdump-jni-rs/native/src/helper_functions.rs
index c9f0f65..7cd45a6 100644
--- a/lsbfdump-jni-rs/native/src/helper_functions.rs
+++ b/lsbfdump-jni-rs/native/src/helper_functions.rs
@@ -17,12 +17,9 @@
 
 // View https://rust-lang.github.io/api-guidelines/naming.html for naming conventions for functions
 
-use crate::stdin_seek::StdinWithSeek;
-
 use std::fs::File;
 use std::io::{self, Read, Seek, SeekFrom};
 
-
 pub fn lsbf_dump(reader: &mut dyn Read, offset: u64, length: u64, show_address: bool) -> io::Result<Vec<String>> {
   let mut lines = Vec::new();
   let mut count = 0;
@@ -46,9 +43,19 @@ pub fn lsbf_dump(reader: &mut dyn Read, offset: u64, length: u64, show_address:
 
 pub fn open_and_seek_input_stream(filename: &str, offset: u64) -> io::Result<Box<dyn Read>> {
   if filename == "-" {
-    let mut stdin_with_seek = StdinWithSeek;
-    stdin_with_seek.seek(SeekFrom::Start(offset))?;
-    Ok(Box::new(stdin_with_seek) as Box<dyn Read>)
+    let stdin = io::stdin();
+    let mut reader = stdin.lock();
+    let mut remaining_bytes_to_seek = offset;
+
+    while remaining_bytes_to_seek > 0 {
+      let mut temp_buffer = [0; 1];
+      match reader.read_exact(&mut temp_buffer) {
+        Ok(_) => remaining_bytes_to_seek -= 1,
+        Err(e) => return Err(e),
+      }
+    }
+
+    Ok(Box::new(reader) as Box<dyn Read>)
   } else {
     let file = File::open(filename)?;
     let mut file_seek = io::BufReader::new(file);
diff --git a/lsbfdump-jni-rs/native/src/lib.rs b/lsbfdump-jni-rs/native/src/lib.rs
index 80889d4..2638024 100644
--- a/lsbfdump-jni-rs/native/src/lib.rs
+++ b/lsbfdump-jni-rs/native/src/lib.rs
@@ -16,7 +16,6 @@
  */
 
 mod helper_functions;
-mod stdin_seek;
 
 use helper_functions::{lsbf_dump, open_and_seek_input_stream};
 
diff --git a/lsbfdump-jni-rs/native/src/stdin_seek.rs b/lsbfdump-jni-rs/native/src/stdin_seek.rs
deleted file mode 100644
index d9e95cd..0000000
--- a/lsbfdump-jni-rs/native/src/stdin_seek.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * 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.
- */
-
-// View https://rust-lang.github.io/api-guidelines/naming.html for naming conventions for traits and structs
-use std::io::{self, Cursor, Read, Seek, SeekFrom};
-
-pub struct StdinWithSeek;
-
-impl Read for StdinWithSeek {
-  fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
-    io::stdin().read(buf)
-  }
-}
-
-impl Seek for StdinWithSeek {
-  fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
-    let mut cursor = Cursor::new(Vec::new());
-    cursor.seek(pos)
-  }
-}


(daffodil-extra) 02/04: remove Cargo.lock from git, add to gitignore

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shanedell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-extra.git

commit 17305812c3353fdae2300499d6eced6af2bee65d
Author: Shane Dell <sh...@gmail.com>
AuthorDate: Tue Feb 6 20:59:19 2024 -0500

    remove Cargo.lock from git, add to gitignore
---
 .gitignore                        |   2 +
 lsbfdump-jni-rs/build.sbt         |   2 +-
 lsbfdump-jni-rs/native/Cargo.lock | 243 --------------------------------------
 lsbfdump/build.sbt                |   2 +-
 4 files changed, 4 insertions(+), 245 deletions(-)

diff --git a/.gitignore b/.gitignore
index aeb8e77..18ed0e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,3 +46,5 @@ lib_managed
 .vscode
 .metals
 .bloop
+
+Cargo.lock
diff --git a/lsbfdump-jni-rs/build.sbt b/lsbfdump-jni-rs/build.sbt
index f13ea45..b095e0d 100644
--- a/lsbfdump-jni-rs/build.sbt
+++ b/lsbfdump-jni-rs/build.sbt
@@ -20,7 +20,7 @@ lazy val root = project
     libraryDependencies ++= List(
       "junit" % "junit" % "4.13.2" % Test,
       // needed below package to successfully run junit tests
-      "com.novocode" % "junit-interface" % "0.11" % Test exclude("junit", "junit-dep")
+      "com.github.sbt" % "junit-interface" % "0.13.3" % Test exclude("junit", "junit-dep"),
     ),
     sbtJniCoreScope := Compile, // because we use `NativeLoader`, not the `@nativeLoader` macro
   )
diff --git a/lsbfdump-jni-rs/native/Cargo.lock b/lsbfdump-jni-rs/native/Cargo.lock
deleted file mode 100644
index dacbda7..0000000
--- a/lsbfdump-jni-rs/native/Cargo.lock
+++ /dev/null
@@ -1,243 +0,0 @@
-# This file is automatically @generated by Cargo.
-# It is not intended for manual editing.
-version = 3
-
-[[package]]
-name = "bytes"
-version = "1.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
-
-[[package]]
-name = "cesu8"
-version = "1.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
-
-[[package]]
-name = "cfg-if"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
-
-[[package]]
-name = "combine"
-version = "4.6.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4"
-dependencies = [
- "bytes",
- "memchr",
-]
-
-[[package]]
-name = "jni"
-version = "0.21.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97"
-dependencies = [
- "cesu8",
- "cfg-if",
- "combine",
- "jni-sys",
- "log",
- "thiserror",
- "walkdir",
- "windows-sys",
-]
-
-[[package]]
-name = "jni-sys"
-version = "0.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
-
-[[package]]
-name = "log"
-version = "0.4.20"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
-
-[[package]]
-name = "lsbfdump"
-version = "0.1.0"
-dependencies = [
- "jni",
-]
-
-[[package]]
-name = "memchr"
-version = "2.7.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
-
-[[package]]
-name = "proc-macro2"
-version = "1.0.76"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
-dependencies = [
- "unicode-ident",
-]
-
-[[package]]
-name = "quote"
-version = "1.0.35"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
-dependencies = [
- "proc-macro2",
-]
-
-[[package]]
-name = "same-file"
-version = "1.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
-dependencies = [
- "winapi-util",
-]
-
-[[package]]
-name = "syn"
-version = "2.0.48"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
-dependencies = [
- "proc-macro2",
- "quote",
- "unicode-ident",
-]
-
-[[package]]
-name = "thiserror"
-version = "1.0.56"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
-dependencies = [
- "thiserror-impl",
-]
-
-[[package]]
-name = "thiserror-impl"
-version = "1.0.56"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
-name = "unicode-ident"
-version = "1.0.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
-
-[[package]]
-name = "walkdir"
-version = "2.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
-dependencies = [
- "same-file",
- "winapi-util",
-]
-
-[[package]]
-name = "winapi"
-version = "0.3.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
-dependencies = [
- "winapi-i686-pc-windows-gnu",
- "winapi-x86_64-pc-windows-gnu",
-]
-
-[[package]]
-name = "winapi-i686-pc-windows-gnu"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
-
-[[package]]
-name = "winapi-util"
-version = "0.1.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
-dependencies = [
- "winapi",
-]
-
-[[package]]
-name = "winapi-x86_64-pc-windows-gnu"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
-
-[[package]]
-name = "windows-sys"
-version = "0.45.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
-dependencies = [
- "windows-targets",
-]
-
-[[package]]
-name = "windows-targets"
-version = "0.42.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
-dependencies = [
- "windows_aarch64_gnullvm",
- "windows_aarch64_msvc",
- "windows_i686_gnu",
- "windows_i686_msvc",
- "windows_x86_64_gnu",
- "windows_x86_64_gnullvm",
- "windows_x86_64_msvc",
-]
-
-[[package]]
-name = "windows_aarch64_gnullvm"
-version = "0.42.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
-
-[[package]]
-name = "windows_aarch64_msvc"
-version = "0.42.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
-
-[[package]]
-name = "windows_i686_gnu"
-version = "0.42.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
-
-[[package]]
-name = "windows_i686_msvc"
-version = "0.42.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
-
-[[package]]
-name = "windows_x86_64_gnu"
-version = "0.42.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
-
-[[package]]
-name = "windows_x86_64_gnullvm"
-version = "0.42.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
-
-[[package]]
-name = "windows_x86_64_msvc"
-version = "0.42.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
diff --git a/lsbfdump/build.sbt b/lsbfdump/build.sbt
index e9dfc13..fd739c5 100644
--- a/lsbfdump/build.sbt
+++ b/lsbfdump/build.sbt
@@ -17,6 +17,6 @@ nativeImageOptions ++= Seq(
 // Library dependencies
 libraryDependencies ++= Seq(
   // needed below package to successfully run junit tests
-  "com.novocode" % "junit-interface" % "0.11" % Test exclude("junit", "junit-dep"),
+  "com.github.sbt" % "junit-interface" % "0.13.3" % Test exclude("junit", "junit-dep"),
   "junit" % "junit" % "4.13.2" % Test,
 )


(daffodil-extra) 01/04: Add lsbfdump example using Scala and Rust

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shanedell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-extra.git

commit 61548040b7f9f78230f1119f21464855eca01e42
Author: Shane Dell <sh...@gmail.com>
AuthorDate: Mon Jan 29 12:24:03 2024 -0500

    Add lsbfdump example using Scala and Rust
---
 .gitignore                                         |   5 +
 lsbfdump-jni-rs/LICENSE                            | 202 +++++++++++++++++
 lsbfdump-jni-rs/README.md                          |  76 +++++++
 lsbfdump-jni-rs/build.sbt                          |  35 +++
 lsbfdump-jni-rs/native/Cargo.lock                  | 243 +++++++++++++++++++++
 lsbfdump-jni-rs/native/Cargo.toml                  |  11 +
 lsbfdump-jni-rs/native/src/helper_functions.rs     |  62 ++++++
 lsbfdump-jni-rs/native/src/lib.rs                  |  98 +++++++++
 lsbfdump-jni-rs/native/src/read_seek.rs            |  40 ++++
 lsbfdump-jni-rs/project/build.properties           |   1 +
 lsbfdump-jni-rs/project/plugins.sbt                |   2 +
 .../scala/org/apache/daffodil/lsbfDump/FFI.scala   |  29 +++
 .../org/apache/daffodil/lsbfDump/LSBFDump.scala    | 102 +++++++++
 .../org/apache/daffodil/lsbfDump/FFITest.scala     |  38 ++++
 lsbfdump/build.sbt                                 |   2 +
 15 files changed, 946 insertions(+)

diff --git a/.gitignore b/.gitignore
index df70556..aeb8e77 100644
--- a/.gitignore
+++ b/.gitignore
@@ -41,3 +41,8 @@ resource_managed
 
 # Project local cache of managed dependencies
 lib_managed
+
+# vscode/metals generated files
+.vscode
+.metals
+.bloop
diff --git a/lsbfdump-jni-rs/LICENSE b/lsbfdump-jni-rs/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/lsbfdump-jni-rs/LICENSE
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.
diff --git a/lsbfdump-jni-rs/README.md b/lsbfdump-jni-rs/README.md
new file mode 100644
index 0000000..04064e3
--- /dev/null
+++ b/lsbfdump-jni-rs/README.md
@@ -0,0 +1,76 @@
+# Example Scala calling Rust using JNI
+
+## Rust naming conventions
+
+This url, https://rust-lang.github.io/api-guidelines/naming.html, provides helpful information on Rust naming conventions.
+
+## Reference
+
+This repos implementation is based on the library [jni-rs](https://github.com/jni-rs/jni-rs). The example provided is very helpful to understand how things work.
+
+## License
+
+This is open-source software under the Apache Software License (V2.0). See the [LICENSE](./LICENSE) file for the full text.
+
+## Testing
+
+No prior commands should need ran.
+
+The command:
+
+```bash
+sbt test
+```
+
+Should provide output similar to the below (note the `[...]` in the paths is so the full path wasn't shown):
+
+```bash
+[info] welcome to sbt 1.9.7 (Eclipse Adoptium Java 17.0.5)
+[info] loading settings for project lsbfdump-jni-rs-build from plugins.sbt ...
+[info] loading project definition from [...]/daffodil-extra/lsbfdump-jni-rs/project
+[info] loading settings for project root from build.sbt ...
+[info] set current project to lsbfdump-jni-rs (in build file:[...]/daffodil-extra/lsbfdump-jni-rs/)
+[info] Building library with native build tool Cargo
+[info] compiling 2 Scala sources to [...]/daffodil-extra/lsbfdump-jni-rs/target/scala-2.13/classes ...
+[warn]     Finished release [optimized] target(s) in 0.02s
+[warn] More than one file was created during compilation, only the first one ([...]/daffodil-extra/lsbfdump-jni-rs/native/target/native/arm64-darwin/bin/release/liblsbfdump.dylib) will be used.
+[success] Library built in [...]/daffodil-extra/lsbfdump-jni-rs/native/target/native/arm64-darwin/bin/release/liblsbfdump.dylib
+[info] compiling 1 Scala source to [...]/daffodil-extra/lsbfdump-jni-rs/target/scala-2.13/test-classes ...
+01111000 01000101 00100000 00100011 | 0x00000000
+01101100 01110000 01101101 01100001 | 0x00000004
+01100011 01010011 00100000 01100101 | 0x00000008
+00100000 01100001 01101100 01100001 | 0x0000000C
+01101100 01101100 01100001 01100011 | 0x00000010
+00100000 01100111 01101110 01101001 | 0x00000014
+01110100 01110011 01110101 01010010 | 0x00000018
+01101001 01110011 01110101 00100000 | 0x0000001C
+01001010 00100000 01100111 01101110 | 0x00000020
+00001010 00001010 01001001 01001110 | 0x00000024
+01010010 00100000 00100011 00100011 | 0x00000028
+00100000 01110100 01110011 01110101 | 0x0000002C
+01101001 01101101 01100001 01101110 | 0x00000030
+01100011 00100000 01100111 01101110 | 0x00000034
+01100101 01110110 01101110 01101111 | 0x00000038
+01101111 01101001 01110100 01101110 | 0x0000003C
+00001010 00001010 01110011 01101110 | 0x00000040
+01110011 01101001 01101000 01010100 | 0x00000044
+01101100 01110010 01110101 00100000 | 0x00000048
+01110100 01101000 00100000 00101100 | 0x0000004C
+00111010 01110011 01110000 01110100 | 0x00000050
+01110101 01110010 00101111 00101111 | 0x00000054
+01101100 00101101 01110100 01110011 | 0x00000058
+00101110 01100111 01101110 01100001 | 0x0000005C
+01101000 01110100 01101001 01100111 | 0x00000060
+01101001 00101110 01100010 01110101 | 0x00000064
+01110000 01100001 00101111 01101111 | 0x00000068
+01110101 01100111 00101101 01101001 | 0x0000006C
+01101100 01100101 01100100 01101001 | 0x00000070
+01110011 01100101 01101110 01101001 | 0x00000074
+01101101 01100001 01101110 00101111 | 0x00000078
+00101110 01100111 01101110 01101001 | 0x0000007C
+lsbfdump: An I/O error occurred - No such file or directory (os error 2)
+[info] Passed: Total 2, Failed 0, Errors 0, Passed 2
+...
+```
+
+Don't worry about the output that comes out as it comes from the Rust code. The Rust code then also returns either true or false based on if everything ran okay.
diff --git a/lsbfdump-jni-rs/build.sbt b/lsbfdump-jni-rs/build.sbt
new file mode 100644
index 0000000..f13ea45
--- /dev/null
+++ b/lsbfdump-jni-rs/build.sbt
@@ -0,0 +1,35 @@
+lazy val commonSettings = Seq(
+  scalaVersion := "2.13.12"
+)
+
+lazy val native = project
+  .in(file("native"))
+  .settings(commonSettings)
+  .settings(
+    name := "lsbfdump-jni-rs-native",
+    nativeCompile / sourceDirectory := baseDirectory.value,
+  )
+  .enablePlugins(JniNative)
+
+lazy val root = project
+  .in(file("."))
+  .settings(commonSettings)
+  .settings(
+    name := "lsbfdump-jni-rs",
+    Compile / mainClass := Some("org.apache.daffodil.lsbfDump.LSBFDump"),
+    libraryDependencies ++= List(
+      "junit" % "junit" % "4.13.2" % Test,
+      // needed below package to successfully run junit tests
+      "com.novocode" % "junit-interface" % "0.11" % Test exclude("junit", "junit-dep")
+    ),
+    sbtJniCoreScope := Compile, // because we use `NativeLoader`, not the `@nativeLoader` macro
+  )
+  .dependsOn(native % Runtime)
+
+// enablePlugins(NativeImagePlugin)
+// // Settings for the native image
+// nativeImageOptions ++= Seq(
+//   "--no-fallback", // does not create nativeImage if it will require a JVM.
+// //  "--enable-all-security-services"
+// // Add other native-image options as needed
+// )
diff --git a/lsbfdump-jni-rs/native/Cargo.lock b/lsbfdump-jni-rs/native/Cargo.lock
new file mode 100644
index 0000000..dacbda7
--- /dev/null
+++ b/lsbfdump-jni-rs/native/Cargo.lock
@@ -0,0 +1,243 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 3
+
+[[package]]
+name = "bytes"
+version = "1.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223"
+
+[[package]]
+name = "cesu8"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
+
+[[package]]
+name = "cfg-if"
+version = "1.0.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
+
+[[package]]
+name = "combine"
+version = "4.6.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4"
+dependencies = [
+ "bytes",
+ "memchr",
+]
+
+[[package]]
+name = "jni"
+version = "0.21.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97"
+dependencies = [
+ "cesu8",
+ "cfg-if",
+ "combine",
+ "jni-sys",
+ "log",
+ "thiserror",
+ "walkdir",
+ "windows-sys",
+]
+
+[[package]]
+name = "jni-sys"
+version = "0.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8eaf4bc02d17cbdd7ff4c7438cafcdf7fb9a4613313ad11b4f8fefe7d3fa0130"
+
+[[package]]
+name = "log"
+version = "0.4.20"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
+
+[[package]]
+name = "lsbfdump"
+version = "0.1.0"
+dependencies = [
+ "jni",
+]
+
+[[package]]
+name = "memchr"
+version = "2.7.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.76"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.35"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "same-file"
+version = "1.0.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
+dependencies = [
+ "winapi-util",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.48"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "thiserror"
+version = "1.0.56"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d54378c645627613241d077a3a79db965db602882668f9136ac42af9ecb730ad"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "1.0.56"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
+
+[[package]]
+name = "walkdir"
+version = "2.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
+dependencies = [
+ "same-file",
+ "winapi-util",
+]
+
+[[package]]
+name = "winapi"
+version = "0.3.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
+dependencies = [
+ "winapi-i686-pc-windows-gnu",
+ "winapi-x86_64-pc-windows-gnu",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+
+[[package]]
+name = "winapi-util"
+version = "0.1.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
+
+[[package]]
+name = "windows-sys"
+version = "0.45.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071"
+dependencies = [
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.42.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
diff --git a/lsbfdump-jni-rs/native/Cargo.toml b/lsbfdump-jni-rs/native/Cargo.toml
new file mode 100644
index 0000000..464a9b1
--- /dev/null
+++ b/lsbfdump-jni-rs/native/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "lsbfdump"
+version = "0.1.0"
+authors = ["Shane Dell <sh...@gmail.com>"]
+edition = "2021"
+
+[dependencies]
+jni = "0.21.1"
+
+[lib]
+crate_type = ["cdylib"]
diff --git a/lsbfdump-jni-rs/native/src/helper_functions.rs b/lsbfdump-jni-rs/native/src/helper_functions.rs
new file mode 100644
index 0000000..bc96990
--- /dev/null
+++ b/lsbfdump-jni-rs/native/src/helper_functions.rs
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+// View https://rust-lang.github.io/api-guidelines/naming.html for naming conventions for functions
+
+use crate::read_seek::{CustomReadSeek, StdinWithSeek};
+
+use std::fs::File;
+use std::io::{self, Read, Seek, SeekFrom};
+
+
+pub fn lsbf_dump(reader: &mut Box<dyn CustomReadSeek>, offset: u64, length: u64, show_address: bool) -> io::Result<Vec<String>> {
+  let mut lines = Vec::new();
+  let mut count = 0;
+  let mut buffer = [0; 4];
+
+  while count < length {
+    match reader.read_exact(&mut buffer) {
+      Ok(_) => {
+        let byte_strings = buffer.iter().copied().rev().map(byte_to_binary_string).collect::<Vec<String>>().join(" ");
+        let extra_spaces = if buffer.len() == 4 { "".to_string() } else { "         ".repeat(4 - buffer.len()) };
+        let address_string = if show_address { format!(" | 0x{:08X}", count + offset) } else { "".to_string() };
+        lines.push(format!("{}{}{}", extra_spaces, byte_strings, address_string));
+        count += 4;
+      }
+      Err(_) => break,
+    }
+  }
+
+  Ok(lines)
+}
+
+pub fn open_and_seek_input_stream(filename: &str, offset: u64) -> io::Result<Box<dyn CustomReadSeek>> {
+  if filename == "-" {
+    let mut stdin_with_seek = StdinWithSeek;
+    stdin_with_seek.seek(SeekFrom::Start(offset))?;
+    Ok(Box::new(stdin_with_seek) as Box<dyn CustomReadSeek>)
+  } else {
+    let file = File::open(filename)?;
+    let mut file_seek = io::BufReader::new(file);
+    file_seek.seek(SeekFrom::Start(offset))?;
+    Ok(Box::new(file_seek) as Box<dyn CustomReadSeek>)
+  }
+}
+
+fn byte_to_binary_string(b: u8) -> String {
+  format!("{:08b}", b)
+}
diff --git a/lsbfdump-jni-rs/native/src/lib.rs b/lsbfdump-jni-rs/native/src/lib.rs
new file mode 100644
index 0000000..f7bc844
--- /dev/null
+++ b/lsbfdump-jni-rs/native/src/lib.rs
@@ -0,0 +1,98 @@
+/*
+ * 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.
+ */
+
+mod helper_functions;
+mod read_seek;
+
+use helper_functions::{lsbf_dump, open_and_seek_input_stream};
+
+use jni::JNIEnv;
+use jni::objects::{JClass, JString};
+use jni::sys::{jboolean,jlong};
+
+/**
+ * For naming conventions for functions being exported to be callable from Scala
+ * see https://github.com/jni-rs/jni-rs. But it basically is this pattern:
+ * 
+ *  1. Java_
+ *  2. Organization folder structure, after src/main/scala, or package name by 
+ * replacing "." or "/" with "_" folowed by a trailing "_"
+ *    eg:
+ *      package name: org.apache.daffodil.lsbfDump
+ *      rust function part: org_apache_daffodil_lsbfDump
+ *  3. Scala class name followed by "_" 
+ *    eg:
+ *      scala class: class FFI() extends NativeLoader("lsbfdump")
+ *      rust function part: FFI_
+ *  4. Scala @native function name.
+ *    eg:
+ *      scala class @native function: @native def lsbfDumpFile
+ *      rust function part: lsbfDumpFile
+ * 
+ * If you follow these numbered items for this example you should get:
+ * 
+ *  1. Java_
+ *  2. org_apache_daffodil_lsbfDump (package_name = org.apache.daffodil.lsbfDump)
+ *  3. FFI_ (scala_class_name = FFI)
+ *  4. lsbfDumpFile (scala_class_function_name = lsbfDumpFile)
+ * 
+ * Adding all four parts together gives us our function name:
+ *  Java_org_apache_daffodil_lsbfDump_FFI_lsbfDumpFile
+ *
+ */
+
+#[no_mangle]
+pub extern "system" fn Java_org_apache_daffodil_lsbfDump_FFI_lsbfDumpFile(
+  mut env: JNIEnv,
+  _class: JClass,
+  filename_in: JString,
+  offset_in: jlong,
+  length_in: jlong,
+  show_address_in: jboolean,
+) -> jboolean {
+  let filename: String = env
+    .get_string(&filename_in)
+    .expect("Couldn't get scala string")
+    .into();
+
+  let offset: u64 = offset_in as u64;
+  let length: u64 = length_in as u64;
+  let show_address: bool = show_address_in != 0;
+
+  match crate::open_and_seek_input_stream(&filename, offset) {
+    Ok(mut reader) => {
+      match crate::lsbf_dump(&mut reader, offset, length, show_address) {
+        Ok(lines) => {
+          for line in &lines {
+              println!("{}", line);
+          }
+          return true as jboolean
+        }
+        Err(err) => {
+          eprintln!("lsbfdump: An I/O error occurred - {}", err);
+          // std::process::exit(1);
+          return false as jboolean
+        }
+      }
+    }
+    Err(err) => {
+      eprintln!("lsbfdump: An I/O error occurred - {}", err);
+      // std::process::exit(1);
+      return false as jboolean
+    }
+  }
+}
diff --git a/lsbfdump-jni-rs/native/src/read_seek.rs b/lsbfdump-jni-rs/native/src/read_seek.rs
new file mode 100644
index 0000000..5612d8f
--- /dev/null
+++ b/lsbfdump-jni-rs/native/src/read_seek.rs
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+// View https://rust-lang.github.io/api-guidelines/naming.html for naming conventions for traits and structs
+use std::io::{self, Cursor, Read, Seek, SeekFrom};
+
+// Need custom trait so we can do Box<dyn CustomReadSeek>
+// as Box<dyn Read + Seek> can't be done since both Read
+// and Seek are non-auto traits
+pub trait CustomReadSeek: Read + Seek {}
+impl<T: Read + Seek> CustomReadSeek for T {}
+
+pub struct StdinWithSeek;
+
+impl Read for StdinWithSeek {
+  fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
+    io::stdin().read(buf)
+  }
+}
+
+impl Seek for StdinWithSeek {
+  fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
+    let mut cursor = Cursor::new(Vec::new());
+    cursor.seek(pos)
+  }
+}
diff --git a/lsbfdump-jni-rs/project/build.properties b/lsbfdump-jni-rs/project/build.properties
new file mode 100644
index 0000000..b19d4e1
--- /dev/null
+++ b/lsbfdump-jni-rs/project/build.properties
@@ -0,0 +1 @@
+sbt.version = 1.9.7
diff --git a/lsbfdump-jni-rs/project/plugins.sbt b/lsbfdump-jni-rs/project/plugins.sbt
new file mode 100644
index 0000000..a39c9a2
--- /dev/null
+++ b/lsbfdump-jni-rs/project/plugins.sbt
@@ -0,0 +1,2 @@
+addSbtPlugin("com.github.sbt" % "sbt-jni" % "1.5.3")
+// addSbtPlugin("org.scalameta" % "sbt-native-image" % "0.3.4")
diff --git a/lsbfdump-jni-rs/src/main/scala/org/apache/daffodil/lsbfDump/FFI.scala b/lsbfdump-jni-rs/src/main/scala/org/apache/daffodil/lsbfDump/FFI.scala
new file mode 100644
index 0000000..306ca72
--- /dev/null
+++ b/lsbfdump-jni-rs/src/main/scala/org/apache/daffodil/lsbfDump/FFI.scala
@@ -0,0 +1,29 @@
+/*
+ * 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.daffodil.lsbfDump
+
+import com.github.sbt.jni.syntax.NativeLoader
+
+class FFI() extends NativeLoader("lsbfdump") {
+  @native def lsbfDumpFile(
+    filename: String,
+    offset: Long,
+    length: Long,
+    showAddress: Boolean,
+  ): Boolean // implemented in liblsbfdump.so
+}
diff --git a/lsbfdump-jni-rs/src/main/scala/org/apache/daffodil/lsbfDump/LSBFDump.scala b/lsbfdump-jni-rs/src/main/scala/org/apache/daffodil/lsbfDump/LSBFDump.scala
new file mode 100644
index 0000000..0860a99
--- /dev/null
+++ b/lsbfdump-jni-rs/src/main/scala/org/apache/daffodil/lsbfDump/LSBFDump.scala
@@ -0,0 +1,102 @@
+/*
+ * 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.daffodil.lsbfDump
+
+object LSBFDump {
+  private val helpText: String =
+    """Usage: lsbfdump [--file <filename>] [--offset <offset>] [--length <numBytes>] [--noAddress] [--help]
+      |
+      |<filename>   : The file to read bytes from or '-' for standard input or if not provided standard input is used.
+      |[offset]     : The starting offset in the file (default is 0). If the offset is past the length of the data, no output is produced.
+      |[length]     : The number of bytes to display (default is entire file). If 0 no output is produced.
+      |--noAddress  : Do not display the address of each byte line.
+      |--help       : Display this help information.
+      |
+      |Examples:
+      | Default usage (128 bytes from standard input, starting at offset 0, with addresses):
+      |   lsbfdump --file - --length 128
+      |
+      | With specific file, offset and byte count:
+      |   lsbfdump --file filename --offset 10 --length 64
+      |
+      | With --noAddress to hide addresses:
+      |   lsbfdump --file filename --offset 10 --length 64 --noAddress
+      |""".stripMargin
+
+  private def usageError(): Unit = {
+    System.err.println("lsbfdump: Invalid arguments provided.")
+    System.err.println(helpText)
+    sys.exit(1)
+  }
+
+  def main(args: Array[String]): Unit = {
+    val parsedArgs = parseArgs(args)
+
+    if (parsedArgs.contains("help")) {
+      println(helpText)
+      sys.exit(0)
+    }
+
+    if (parsedArgs.contains("invalid")) usageError()
+
+    val filename =
+      parsedArgs.getOrElse("file", "-") // if not provided at all, also uses std-in.
+    val offset = parsedArgs.get("offset").map(_.toLong).getOrElse(0L)
+    val length = parsedArgs.get("length").map(_.toLong).getOrElse(Long.MaxValue)
+    val showAddress = !parsedArgs.contains("noAddress")
+
+    assert(offset >= 0)
+    assert(length >= 0)
+
+    new FFI().lsbfDumpFile(filename, offset, length, showAddress)
+  }
+
+  def parseArgs(args: Array[String]): Map[String, String] = {
+    var argMap = Map[String, String]()
+    var i = 0
+    while (i < args.length) {
+      args(i) match {
+        case "--file" if i + 1 < args.length =>
+          argMap += ("file" -> args(i + 1))
+          i += 2
+        case "--offset" if i + 1 < args.length =>
+          argMap += ("offset" -> args(i + 1))
+          if (!isNonNegativeInteger(args(i + 1))) usageError()
+          i += 2
+        case "--length" if i + 1 < args.length =>
+          argMap += ("length" -> args(i + 1))
+          if (!isNonNegativeInteger(args(i + 1))) usageError()
+          i += 2
+        case "--noAddress" =>
+          argMap += ("noAddress" -> "")
+          i += 1
+        case "--help" =>
+          argMap += ("help" -> "")
+          i = args.length // Break the loop
+        case _ =>
+          argMap += ("invalid" -> "")
+          i = args.length // Break the loop
+      }
+    }
+    argMap
+  }
+
+  private def isNonNegativeInteger(s: String): Boolean =
+    try { s.toLong >= 0 }
+    catch { case _: NumberFormatException => false }
+}
diff --git a/lsbfdump-jni-rs/src/test/scala/org/apache/daffodil/lsbfDump/FFITest.scala b/lsbfdump-jni-rs/src/test/scala/org/apache/daffodil/lsbfDump/FFITest.scala
new file mode 100644
index 0000000..bb3f551
--- /dev/null
+++ b/lsbfdump-jni-rs/src/test/scala/org/apache/daffodil/lsbfDump/FFITest.scala
@@ -0,0 +1,38 @@
+/*
+ * 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.daffodil.lsbfDump
+
+import java.io.File
+import java.nio.file.Paths
+
+import org.junit.Assert._
+import org.junit.Test
+
+class FFITest {
+  @Test
+  def testBadFile(): Unit = {
+    val actual = new FFI().lsbfDumpFile("no_such/file", 0, 0, false)
+    assertEquals(actual, false)
+  }
+
+  @Test
+  def testGoodFile(): Unit = {
+    val actual = new FFI().lsbfDumpFile(s"${System.getProperty("user.dir")}/README.md", 0, 128, true)
+    assertEquals(actual, true)
+  }
+}
diff --git a/lsbfdump/build.sbt b/lsbfdump/build.sbt
index 2699d1a..e9dfc13 100644
--- a/lsbfdump/build.sbt
+++ b/lsbfdump/build.sbt
@@ -16,5 +16,7 @@ nativeImageOptions ++= Seq(
 
 // Library dependencies
 libraryDependencies ++= Seq(
+  // needed below package to successfully run junit tests
+  "com.novocode" % "junit-interface" % "0.11" % Test exclude("junit", "junit-dep"),
   "junit" % "junit" % "4.13.2" % Test,
 )


(daffodil-extra) 03/04: remove CustomSeek code, rename read_seek.rs to stdin_seek.rs

Posted by sh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

shanedell pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil-extra.git

commit 6237b5f497dbab507b45c408fdc671367593c626
Author: Shane Dell <sh...@gmail.com>
AuthorDate: Tue Feb 6 21:16:05 2024 -0500

    remove CustomSeek code, rename read_seek.rs to stdin_seek.rs
---
 lsbfdump-jni-rs/native/src/helper_functions.rs             | 10 +++++-----
 lsbfdump-jni-rs/native/src/lib.rs                          |  2 +-
 lsbfdump-jni-rs/native/src/{read_seek.rs => stdin_seek.rs} |  6 ------
 3 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/lsbfdump-jni-rs/native/src/helper_functions.rs b/lsbfdump-jni-rs/native/src/helper_functions.rs
index bc96990..c9f0f65 100644
--- a/lsbfdump-jni-rs/native/src/helper_functions.rs
+++ b/lsbfdump-jni-rs/native/src/helper_functions.rs
@@ -17,13 +17,13 @@
 
 // View https://rust-lang.github.io/api-guidelines/naming.html for naming conventions for functions
 
-use crate::read_seek::{CustomReadSeek, StdinWithSeek};
+use crate::stdin_seek::StdinWithSeek;
 
 use std::fs::File;
 use std::io::{self, Read, Seek, SeekFrom};
 
 
-pub fn lsbf_dump(reader: &mut Box<dyn CustomReadSeek>, offset: u64, length: u64, show_address: bool) -> io::Result<Vec<String>> {
+pub fn lsbf_dump(reader: &mut dyn Read, offset: u64, length: u64, show_address: bool) -> io::Result<Vec<String>> {
   let mut lines = Vec::new();
   let mut count = 0;
   let mut buffer = [0; 4];
@@ -44,16 +44,16 @@ pub fn lsbf_dump(reader: &mut Box<dyn CustomReadSeek>, offset: u64, length: u64,
   Ok(lines)
 }
 
-pub fn open_and_seek_input_stream(filename: &str, offset: u64) -> io::Result<Box<dyn CustomReadSeek>> {
+pub fn open_and_seek_input_stream(filename: &str, offset: u64) -> io::Result<Box<dyn Read>> {
   if filename == "-" {
     let mut stdin_with_seek = StdinWithSeek;
     stdin_with_seek.seek(SeekFrom::Start(offset))?;
-    Ok(Box::new(stdin_with_seek) as Box<dyn CustomReadSeek>)
+    Ok(Box::new(stdin_with_seek) as Box<dyn Read>)
   } else {
     let file = File::open(filename)?;
     let mut file_seek = io::BufReader::new(file);
     file_seek.seek(SeekFrom::Start(offset))?;
-    Ok(Box::new(file_seek) as Box<dyn CustomReadSeek>)
+    Ok(Box::new(file_seek) as Box<dyn Read>)
   }
 }
 
diff --git a/lsbfdump-jni-rs/native/src/lib.rs b/lsbfdump-jni-rs/native/src/lib.rs
index f7bc844..80889d4 100644
--- a/lsbfdump-jni-rs/native/src/lib.rs
+++ b/lsbfdump-jni-rs/native/src/lib.rs
@@ -16,7 +16,7 @@
  */
 
 mod helper_functions;
-mod read_seek;
+mod stdin_seek;
 
 use helper_functions::{lsbf_dump, open_and_seek_input_stream};
 
diff --git a/lsbfdump-jni-rs/native/src/read_seek.rs b/lsbfdump-jni-rs/native/src/stdin_seek.rs
similarity index 84%
rename from lsbfdump-jni-rs/native/src/read_seek.rs
rename to lsbfdump-jni-rs/native/src/stdin_seek.rs
index 5612d8f..d9e95cd 100644
--- a/lsbfdump-jni-rs/native/src/read_seek.rs
+++ b/lsbfdump-jni-rs/native/src/stdin_seek.rs
@@ -18,12 +18,6 @@
 // View https://rust-lang.github.io/api-guidelines/naming.html for naming conventions for traits and structs
 use std::io::{self, Cursor, Read, Seek, SeekFrom};
 
-// Need custom trait so we can do Box<dyn CustomReadSeek>
-// as Box<dyn Read + Seek> can't be done since both Read
-// and Seek are non-auto traits
-pub trait CustomReadSeek: Read + Seek {}
-impl<T: Read + Seek> CustomReadSeek for T {}
-
 pub struct StdinWithSeek;
 
 impl Read for StdinWithSeek {