Handle empty RawCC files.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=143667717
This commit is contained in:
cdrolle 2017-01-05 08:15:29 -08:00 committed by Oliver Woodman
parent 8a0e76ba32
commit 01d22f8123

View File

@ -83,8 +83,11 @@ public final class RawCcExtractor implements Extractor {
while (true) {
switch (parserState) {
case STATE_READING_HEADER:
parseHeader(input);
parserState = STATE_READING_TIMESTAMP_AND_COUNT;
if (parseHeader(input)) {
parserState = STATE_READING_TIMESTAMP_AND_COUNT;
} else {
return RESULT_END_OF_INPUT;
}
break;
case STATE_READING_TIMESTAMP_AND_COUNT:
if (parseTimestampAndSampleCount(input)) {
@ -114,14 +117,18 @@ public final class RawCcExtractor implements Extractor {
// Do nothing
}
private void parseHeader(ExtractorInput input) throws IOException, InterruptedException {
private boolean parseHeader(ExtractorInput input) throws IOException, InterruptedException {
dataScratch.reset();
input.readFully(dataScratch.data, 0, HEADER_SIZE);
if (dataScratch.readInt() != HEADER_ID) {
throw new IOException("Input not RawCC");
if (input.readFully(dataScratch.data, 0, HEADER_SIZE, true)) {
if (dataScratch.readInt() != HEADER_ID) {
throw new IOException("Input not RawCC");
}
version = dataScratch.readUnsignedByte();
// no versions use the flag fields yet
return true;
} else {
return false;
}
version = dataScratch.readUnsignedByte();
// no versions use the flag fields yet
}
private boolean parseTimestampAndSampleCount(ExtractorInput input) throws IOException,