Skip to content
Open
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
4 changes: 4 additions & 0 deletions src/main/com/portalmedia/embarc/cli/JsonWriterDpx.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public static void writeJsonDPXFiles(String outputPath, TreeMap<String, DPXFileI
fileJson.put("General", fileValues);

DPXMetadata data = dpxFileInfo.getFileData();
if (data == null) {
System.out.println("No metadata was read from " + dpxFileInfo.getName() + ", skipping it");
continue;
}
LinkedHashMap<ColumnDef, MetadataColumn> metadata = data.getMetadataHashMap();

String currentSection = null;
Expand Down
18 changes: 15 additions & 3 deletions src/main/com/portalmedia/embarc/parser/BinaryFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private void Initialize(String inputFilePath) throws FileNotFoundException
public void skip(int position)
{
try {
inputStream.skip(position);
bytesRead += inputStream.skip(position);
} catch (IOException e) {
System.out.println("Error skipping to " + position);
}
Expand All @@ -66,7 +66,7 @@ public boolean hasMoreData() {
}

public boolean canRead(int length) {
return bytesRead + length < fileSizeBytes;
return length >= 0 && bytesRead + length <= fileSizeBytes;
}

public String readAscii(int length) {
Expand Down Expand Up @@ -168,10 +168,22 @@ public Date readDate(String format, int length) {

public byte[] readBytes(int length) throws IOException
{
// The length often comes from a header field, so it can ask for more
// than the file holds. Reading anyway filled the array with the -1
// returned at end of file, reported back as 0xFF bytes of content.
if (!canRead(length)) {
throw new IOException("Cannot read " + length + " bytes at offset "
+ bytesRead + ", the file is " + fileSizeBytes + " bytes");
}
byte [] bytes = new byte[length];
for(int bp =0; bp < length; bp++)
{
bytes[bp] = (byte) inputStream.read();
int value = inputStream.read();
if (value == -1) {
throw new IOException("Unexpected end of file after " + bp
+ " of " + length + " bytes");
}
bytes[bp] = (byte) value;
bytesRead++;
}
return bytes;
Expand Down