Class SfvChecksumImpl

java.lang.Object
io.camunda.zeebe.snapshots.impl.SfvChecksumImpl
All Implemented Interfaces:
ImmutableChecksumsSFV, MutableChecksumsSFV

public final class SfvChecksumImpl extends Object implements MutableChecksumsSFV
Supports building individual CRCs compatible with SFV file format and also supports backward compatibility with 'combinedChecksum' field. https://en.wikipedia.org/wiki/Simple_file_verification
  • Constructor Details

    • SfvChecksumImpl

      public SfvChecksumImpl()
  • Method Details

    • write

      public void write(OutputStream stream) throws IOException
      Description copied from interface: ImmutableChecksumsSFV
      Write the checksum collection in SFV format to the given output stream.
      Specified by:
      write in interface ImmutableChecksumsSFV
      Parameters:
      stream - in which the data will be written to
      Throws:
      IOException
    • getChecksums

      public SortedMap<String,Long> getChecksums()
      Specified by:
      getChecksums in interface ImmutableChecksumsSFV
      Returns:
      the map containing the individual file checksums
    • sameChecksums

      public boolean sameChecksums(ImmutableChecksumsSFV o)
      Description copied from interface: ImmutableChecksumsSFV
      Returns if all file checksums match exactly.
      Specified by:
      sameChecksums in interface ImmutableChecksumsSFV
      Parameters:
      o - The other checksum
      Returns:
      boolean denoting match
    • getCombinedChecksum

      public long getCombinedChecksum()
      Description copied from interface: ImmutableChecksumsSFV
      Returns some combined checksum over all the file checksums. If any of the individual checksums or file names change, the combined checksum will change as well.
      Specified by:
      getCombinedChecksum in interface ImmutableChecksumsSFV
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setSnapshotDirectoryComment

      public void setSnapshotDirectoryComment(String headerComment)
    • updateFromFile

      public void updateFromFile(Path filePath) throws IOException
      Description copied from interface: MutableChecksumsSFV
      Update the checksum collection, and add a new checksum from a given file path.
      Specified by:
      updateFromFile in interface MutableChecksumsSFV
      Parameters:
      filePath - the path to a file for which a checksum is created and added to the collection
      Throws:
      IOException - when reading of given file fails
    • updateFromBytes

      public void updateFromBytes(String fileName, byte[] bytes)
      Description copied from interface: MutableChecksumsSFV
      Update the checksum collection, and add a new checksum from given bytes, likely a read file or soon to be written file.

      Useful, if we want to avoid re-reading files etc.

      Specified by:
      updateFromBytes in interface MutableChecksumsSFV
      Parameters:
      fileName - the name of the file (which relates to the given bytes), that is used in the checksum collection in SFV file format
      bytes - the bytes for which the checksum should be created
    • updateFromSfvFile

      public void updateFromSfvFile(String... lines)
      Description copied from interface: MutableChecksumsSFV
      Build the checksum collection from a SFV format string array.
      Specified by:
      updateFromSfvFile in interface MutableChecksumsSFV
      Parameters:
      lines - the lines (in SFV) to build up the checksum collection
    • updateFromChecksum

      public void updateFromChecksum(Path filePath, long checksum)
      Description copied from interface: MutableChecksumsSFV
      Update the checksum map with the given checksum
      Specified by:
      updateFromChecksum in interface MutableChecksumsSFV
      Parameters:
      filePath - path to file
      checksum - check of file given