Class SnapStream


  • public class SnapStream
    extends java.lang.Object
    Represent the Stream used in serialize and deserialize the Snapshot.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  SnapStream.StreamMode  
    • Constructor Summary

      Constructors 
      Constructor Description
      SnapStream()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.zip.CheckedInputStream getInputStream​(java.io.File file)
      Return the CheckedInputStream based on the extension of the fileName.
      static java.util.zip.CheckedOutputStream getOutputStream​(java.io.File file, boolean fsync)
      Return the OutputStream based on predefined stream mode.
      static SnapStream.StreamMode getStreamMode()  
      static SnapStream.StreamMode getStreamMode​(java.lang.String fileName)
      Detect the stream mode from file name extension
      static boolean isValidSnapshot​(java.io.File file)
      Verifies that the file is a valid snapshot.
      static void sealStream​(java.util.zip.CheckedOutputStream os, OutputArchive oa)
      Write specific seal to the OutputArchive and close the OutputStream.
      static void setStreamMode​(SnapStream.StreamMode mode)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ZOOKEEPER_SHAPSHOT_STREAM_MODE

        public static final java.lang.String ZOOKEEPER_SHAPSHOT_STREAM_MODE
        See Also:
        Constant Field Values
    • Constructor Detail

      • SnapStream

        public SnapStream()
    • Method Detail

      • getInputStream

        public static java.util.zip.CheckedInputStream getInputStream​(java.io.File file)
                                                               throws java.io.IOException
        Return the CheckedInputStream based on the extension of the fileName.
        Parameters:
        file - the file the InputStream read from
        Returns:
        the specific InputStream
        Throws:
        java.io.IOException
      • getOutputStream

        public static java.util.zip.CheckedOutputStream getOutputStream​(java.io.File file,
                                                                        boolean fsync)
                                                                 throws java.io.IOException
        Return the OutputStream based on predefined stream mode.
        Parameters:
        file - the file the OutputStream writes to
        fsync - sync the file immediately after write
        Returns:
        the specific OutputStream
        Throws:
        java.io.IOException
      • sealStream

        public static void sealStream​(java.util.zip.CheckedOutputStream os,
                                      OutputArchive oa)
                               throws java.io.IOException
        Write specific seal to the OutputArchive and close the OutputStream. Currently, only CheckedOutputStream will write it's checkSum to the end of the stream.
        Throws:
        java.io.IOException
      • isValidSnapshot

        public static boolean isValidSnapshot​(java.io.File file)
                                       throws java.io.IOException
        Verifies that the file is a valid snapshot. Snapshot may be invalid if it's incomplete as in a situation when the server dies while in the process of storing a snapshot. Any files that are improperly formated or corrupted are invalid. Any file that is not a snapshot is also an invalid snapshot.
        Parameters:
        file - file to verify
        Returns:
        true if the snapshot is valid
        Throws:
        java.io.IOException
      • getStreamMode

        public static SnapStream.StreamMode getStreamMode​(java.lang.String fileName)
        Detect the stream mode from file name extension
        Parameters:
        fileName -
        Returns:
        the stream mode detected