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 <[email protected]>
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)
-  }
-}

Reply via email to