Skip to content

Commit

Permalink
Update error message for truncated file
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanpadams committed Dec 2, 2022
1 parent 0249237 commit 455354f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
12 changes: 3 additions & 9 deletions src/main/java/gov/nasa/pds/label/object/ArrayObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ public ArrayObject(URL parent, gov.nasa.arc.pds.xml.generated.File fileObject, A
setSize(findSize(elementType.getSize()));

adapter = new ArrayAdapter(dimensions, elementType);

this.name = array.getName();
this.localIdentifier = array.getLocalIdentifier();
}

/**
Expand Down Expand Up @@ -130,15 +133,6 @@ public int[] getDimensions() {
return dimensions;
}

/**
* return the name of this array.
*
* @return the name of this array.
*/
public String getName() {
return array.getName();
}

private long findSize(int elementSize) {
long count = 1;
for (int dimension : dimensions) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/gov/nasa/pds/label/object/DataObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public abstract class DataObject {
protected long offset;
protected long size;
protected String name;
protected String localIdentifier;
protected SeekableByteChannel channel;
protected DataObjectLocation dataObjectLocation;

Expand Down Expand Up @@ -278,4 +279,12 @@ public DataObjectLocation getDataObjectLocation() {
public void setDataObjectLocation(DataObjectLocation dataObjectLocation) {
this.dataObjectLocation = dataObjectLocation;
}

public String getLocalIdentifier() {
return localIdentifier;
}

public void setLocalIdentifier(String localIdentifier) {
this.localIdentifier = localIdentifier;
}
}
1 change: 1 addition & 0 deletions src/main/java/gov/nasa/pds/label/object/TableObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public TableObject(URL parentDir, gov.nasa.arc.pds.xml.generated.File fileObject
this.tableReader = null;

this.name = ((ByteStream) tableObject).getName();
this.localIdentifier = ((ByteStream) tableObject).getLocalIdentifier();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ private void initializeAccessor(URL url, long offset, int length, long records,
if (this.totalBytesRead < expectedBytesToRead) {
if (expectedBytesToRead > fileSizeMinusOffset) {
throw new InvalidTableException(
"Cannot read object. Remaining file size: " + fileSizeMinusOffset
+ ", Expected bytes remaining for object: " + expectedBytesToRead);
"Data object is truncated. Expected bytes as defined by label: " + expectedBytesToRead
+ " (" + records + " records)" + ", Actual bytes remaining in file: "
+ fileSizeMinusOffset + " (" + (fileSizeMinusOffset / length) + " records)");
} else {
throw new InvalidTableException("Expected to read in " + expectedBytesToRead
+ " bytes but only " + totalBytesRead + " bytes were read for " + url.toString());
Expand Down

0 comments on commit 455354f

Please sign in to comment.