Skip to content

Commit

Permalink
Merge pull request #86 from NASA-PDS/validaate_593
Browse files Browse the repository at this point in the history
validate 593: allow a fixed length line read
  • Loading branch information
jordanpadams authored Feb 9, 2023
2 parents a6be54b + bdc2b12 commit 5159efc
Showing 1 changed file with 21 additions and 0 deletions.
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

0 comments on commit 5159efc

Please sign in to comment.