Search in sources :

Example 6 with InvalidStreamFileException

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);
    }
}
Also used : SignatureFileParsingException(com.hedera.mirror.importer.exception.SignatureFileParsingException) InvalidStreamFileException(com.hedera.mirror.importer.exception.InvalidStreamFileException) ValidatedDataInputStream(com.hedera.mirror.importer.reader.ValidatedDataInputStream) HashObject(com.hedera.mirror.importer.reader.HashObject) IOException(java.io.IOException) FileStreamSignature(com.hedera.mirror.importer.domain.FileStreamSignature)

Example 7 with InvalidStreamFileException

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);
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) InvalidStreamFileException(com.hedera.mirror.importer.exception.InvalidStreamFileException)

Example 8 with InvalidStreamFileException

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);
    }
}
Also used : InvalidStreamFileException(com.hedera.mirror.importer.exception.InvalidStreamFileException) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Stopwatch(com.google.common.base.Stopwatch) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Aggregations

InvalidStreamFileException (com.hedera.mirror.importer.exception.InvalidStreamFileException)8 IOException (java.io.IOException)4 FileStreamSignature (com.hedera.mirror.importer.domain.FileStreamSignature)2 SignatureFileParsingException (com.hedera.mirror.importer.exception.SignatureFileParsingException)2 StreamFileReaderException (com.hedera.mirror.importer.exception.StreamFileReaderException)2 HashObject (com.hedera.mirror.importer.reader.HashObject)2 ValidatedDataInputStream (com.hedera.mirror.importer.reader.ValidatedDataInputStream)2 InputStream (java.io.InputStream)2 Stopwatch (com.google.common.base.Stopwatch)1 CodedInputStream (com.google.protobuf.CodedInputStream)1 ExtensionRegistryLite (com.google.protobuf.ExtensionRegistryLite)1 UnknownFieldSet (com.google.protobuf.UnknownFieldSet)1 StreamType (com.hedera.mirror.common.domain.StreamType)1 AccountBalance (com.hedera.mirror.common.domain.balance.AccountBalance)1 AccountBalanceFile (com.hedera.mirror.common.domain.balance.AccountBalanceFile)1 TokenBalance (com.hedera.mirror.common.domain.balance.TokenBalance)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)1 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)1 DomainUtils (com.hedera.mirror.common.util.DomainUtils)1