Skip to content

Commit

Permalink
Merge pull request #84 from NASA-PDS/pds-validate-519
Browse files Browse the repository at this point in the history
changes needed to support validate 519
  • Loading branch information
nutjob4life authored Jan 26, 2023
2 parents 5e11371 + c2dc52a commit 6b4cee9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/main/java/gov/nasa/pds/label/object/TableRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ public interface TableRecord {
*/
void clear();

/**
* @returns Length of the record in bytes.
*/
int length();

/**
*
* @return Gets the record location.
Expand Down
17 changes: 14 additions & 3 deletions src/main/java/gov/nasa/pds/objectAccess/ByteWiseFileAccessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,21 @@ private void initializeAccessor(URL url, long offset, int length, long records,
// if for whatever reason we don't read in sufficient bytes
if (this.totalBytesRead < expectedBytesToRead) {
if (expectedBytesToRead > fileSizeMinusOffset) {
if ((fileSizeMinusOffset / length) * length == fileSizeMinusOffset)
throw new InvalidTableException(
"Data object is truncated. Expected bytes as defined by label: " + expectedBytesToRead
+ " (" + records + " records times " + length + " bytes per record)" + ", Actual bytes in file: "
+ fileSizeMinusOffset + " (" + (fileSizeMinusOffset / length) + " records times " + length + " bytes per record)");
if ((fileSizeMinusOffset / records) * records == fileSizeMinusOffset)
throw new InvalidTableException(
"Data object is truncated. Expected bytes as defined by label: " + expectedBytesToRead
+ " (" + records + " records times " + length + " bytes per record)" + ", Actual bytes in file: "
+ fileSizeMinusOffset + " (" + records + " records times " + (fileSizeMinusOffset/records) + " bytes per record)");
throw new InvalidTableException(
"Data object is truncated. Expected bytes as defined by label: " + expectedBytesToRead
+ " (" + records + " records)" + ", Actual bytes remaining in file: "
+ fileSizeMinusOffset + " (" + (fileSizeMinusOffset / length) + " records)");
"Data object is truncated. Expected bytes as defined by label: " + expectedBytesToRead
+ " (" + records + " records times " + length + " bytes per record)" + ", Actual bytes in file: "
+ fileSizeMinusOffset + " (" + ((float)(fileSizeMinusOffset) / (float)length) + " records times " + length + " bytes per record)"
+ " OR (" + records + " records times " + ((float)fileSizeMinusOffset / (float)records) + " bytes per record)");
} else {
throw new InvalidTableException("Expected to read in " + expectedBytesToRead
+ " bytes but only " + totalBytesRead + " bytes were read for " + url.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public class DelimitedTableRecord implements TableRecord {
setRecordValue(value);
}

@Override
public int length() {
int len = 0;
for (String rv : this.recordValue) len += rv.length();
return len;
}
@Override
public int findColumn(String name) {
checkFieldName(name);
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/gov/nasa/pds/objectAccess/FixedTableRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public FixedTableRecord(byte[] value, Map<String, Integer> map, FieldDescription
setRecordValue(value);
}

@Override
public int length() { return this.recordBytes.length; }

@Override
public int findColumn(String name) {
checkFieldName(name);
Expand Down

0 comments on commit 6b4cee9

Please sign in to comment.