Search in sources :

Example 1 with SelfSerializable

use of com.swirlds.common.io.SelfSerializable in project hedera-services by hashgraph.

the class RecordStreamFileParsingTest method parseV5.

void parseV5(final String dir, final Hash expectedStartHash) throws Exception {
    final File out = new File(dir + "/out.log");
    // these files are generated with initial Hash be an empty Hash
    final File recordsDir = new File(dir);
    Iterator<SelfSerializable> iterator = LinkedObjectStreamUtilities.parseStreamDirOrFile(recordsDir, Release023xStreamType.RELEASE_023x_STREAM_TYPE);
    Hash startHash = null;
    int recordsCount = 0;
    Hash endHash = null;
    try (BufferedWriter writer = new BufferedWriter(new FileWriter(out))) {
        while (iterator.hasNext()) {
            SelfSerializable object = iterator.next();
            if (startHash == null) {
                startHash = (Hash) object;
                writer.write(startHash.toString());
                writer.write("\n");
            } else if (!iterator.hasNext()) {
                endHash = (Hash) object;
                writer.write(endHash.toString());
                writer.write("\n");
                break;
            } else {
                assertTrue(object instanceof RecordStreamObject);
                RecordStreamObject recordStreamObject = (RecordStreamObject) object;
                writer.write(recordStreamObject.toShortString());
                writer.write("\n");
                assertNotNull(recordStreamObject.getTimestamp());
                recordsCount++;
            }
        }
    }
    // the record streams are generated with an empty startHash
    assertEquals(expectedStartHash, startHash);
    assertNotEquals(0, recordsCount);
    assertNotEquals(startHash, endHash);
}
Also used : SelfSerializable(com.swirlds.common.io.SelfSerializable) FileWriter(java.io.FileWriter) ImmutableHash(com.swirlds.common.crypto.ImmutableHash) Hash(com.swirlds.common.crypto.Hash) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Aggregations

Hash (com.swirlds.common.crypto.Hash)1 ImmutableHash (com.swirlds.common.crypto.ImmutableHash)1 SelfSerializable (com.swirlds.common.io.SelfSerializable)1 BufferedWriter (java.io.BufferedWriter)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1