use of com.hedera.mirror.importer.exception.InvalidStreamFileException in project hedera-mirror-node by hashgraph.
the class SignatureFileReaderV5 method read.
@Override
public FileStreamSignature read(StreamFileData signatureFileData) {
String filename = signatureFileData.getFilename();
try (ValidatedDataInputStream vdis = new ValidatedDataInputStream(signatureFileData.getInputStream(), filename)) {
vdis.readByte(SIGNATURE_FILE_FORMAT_VERSION, "fileVersion");
// Read the objectStreamSignatureVersion, which is not used
vdis.readInt();
HashObject fileHashObject = new HashObject(vdis, "entireFile", SHA384);
SignatureObject fileHashSignatureObject = new SignatureObject(vdis, "entireFile");
HashObject metadataHashObject = new HashObject(vdis, "metadata", SHA384);
SignatureObject metadataHashSignatureObject = new SignatureObject(vdis, "metadata");
if (vdis.available() != 0) {
throw new SignatureFileParsingException("Extra data discovered in signature file " + filename);
}
FileStreamSignature fileStreamSignature = new FileStreamSignature();
fileStreamSignature.setBytes(signatureFileData.getBytes());
fileStreamSignature.setFileHash(fileHashObject.getHash());
fileStreamSignature.setFileHashSignature(fileHashSignatureObject.getSignature());
fileStreamSignature.setFilename(filename);
fileStreamSignature.setMetadataHash(metadataHashObject.getHash());
fileStreamSignature.setMetadataHashSignature(metadataHashSignatureObject.getSignature());
fileStreamSignature.setSignatureType(fileHashSignatureObject.getSignatureType());
return fileStreamSignature;
} catch (InvalidStreamFileException | IOException e) {
throw new SignatureFileParsingException(e);
}
}
use of com.hedera.mirror.importer.exception.InvalidStreamFileException in project hedera-mirror-node by hashgraph.
the class StreamFilename method extractInstant.
private static Instant extractInstant(String filename, String fullExtension, String suffix) {
try {
String fullSuffix = StringUtils.join(suffix, "." + fullExtension);
String dateTime = StringUtils.removeEnd(filename, fullSuffix);
dateTime = dateTime.replace(COMPATIBLE_TIME_SEPARATOR, STANDARD_TIME_SEPARATOR);
return Instant.parse(dateTime);
} catch (DateTimeParseException ex) {
throw new InvalidStreamFileException("Invalid datetime string in filename " + filename, ex);
}
}
use of com.hedera.mirror.importer.exception.InvalidStreamFileException in project hedera-mirror-node by hashgraph.
the class CompositeRecordFileReader method read.
@Override
public RecordFile read(@NonNull StreamFileData streamFileData) {
long count = 0;
Stopwatch stopwatch = Stopwatch.createStarted();
String filename = streamFileData.getFilename();
int version = 0;
try (DataInputStream dis = new DataInputStream(streamFileData.getInputStream())) {
RecordFileReader reader;
version = dis.readInt();
switch(version) {
case 1:
reader = version1Reader;
break;
case 2:
reader = version2Reader;
break;
case 5:
reader = version5Reader;
break;
default:
throw new InvalidStreamFileException(String.format("Unsupported record file version %d in file %s", version, filename));
}
RecordFile recordFile = reader.read(streamFileData);
count = recordFile.getCount();
return recordFile;
} catch (IOException e) {
throw new StreamFileReaderException("Error reading record file " + filename, e);
} finally {
log.info("Read {} items {}successfully from v{} record file {} in {}", count, count != 0 ? "" : "un", version, filename, stopwatch);
}
}
Aggregations