Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validate 593: allow a fixed length line read #86

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/gov/nasa/pds/objectAccess/RawTableReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.URL;
import java.nio.charset.StandardCharsets;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.opencsv.exceptions.CsvValidationException;
Expand Down Expand Up @@ -171,6 +173,25 @@ public String readNextLine() throws IOException {
return line;
}

/**
* Previews the next fixed length line in the data file.
*
* @return the next line, or null if no further lines.
*
* @throws IOException
*/
public String readNextFixedLine() throws IOException {
byte[] line = null;
int recordLength = this.getAdapter().getRecordLength();
long next_row = this.getCurrentRow() + 1;

if (0 <= this.accessor.getTotalFileContentSize() - (next_row * recordLength)) {
line = this.accessor.readRecordBytes(next_row, 0, recordLength);
this.setCurrentRow(next_row);
}
return line == null ? null : new String(line, StandardCharsets.UTF_8);
}

/**
* Converts the given line to a record.
*
Expand Down