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

changes needed to support validate #519 #84

Merged
merged 1 commit into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
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
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
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)
nutjob4life marked this conversation as resolved.
Show resolved Hide resolved
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)
nutjob4life marked this conversation as resolved.
Show resolved Hide resolved
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
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