Class SnapStream
- java.lang.Object
-
- org.apache.zookeeper.server.persistence.SnapStream
-
public class SnapStream extends 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
-
Field Summary
Fields Modifier and Type Field Description static String
ZOOKEEPER_SHAPSHOT_STREAM_MODE
-
Constructor Summary
Constructors Constructor Description SnapStream()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkSealIntegrity(CheckedInputStream is, InputArchive ia)
Verify the integrity of the seal, only CheckedInputStream will verify the checkSum of the content.static CheckedInputStream
getInputStream(File file)
Return the CheckedInputStream based on the extension of the fileName.static CheckedOutputStream
getOutputStream(File file, boolean fsync)
Return the OutputStream based on predefined stream mode.static SnapStream.StreamMode
getStreamMode()
static SnapStream.StreamMode
getStreamMode(String fileName)
Detect the stream mode from file name extensionstatic boolean
isValidSnapshot(File file)
Verifies that the file is a valid snapshot.static void
sealStream(CheckedOutputStream os, OutputArchive oa)
Write specific seal to the OutputArchive and close the OutputStream.static void
setStreamMode(SnapStream.StreamMode mode)
-
-
-
Field Detail
-
ZOOKEEPER_SHAPSHOT_STREAM_MODE
public static final String ZOOKEEPER_SHAPSHOT_STREAM_MODE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getInputStream
public static CheckedInputStream getInputStream(File file) throws IOException
Return the CheckedInputStream based on the extension of the fileName.- Parameters:
file
- the file the InputStream read from- Returns:
- the specific InputStream
- Throws:
IOException
-
getOutputStream
public static CheckedOutputStream getOutputStream(File file, boolean fsync) throws IOException
Return the OutputStream based on predefined stream mode.- Parameters:
file
- the file the OutputStream writes tofsync
- sync the file immediately after write- Returns:
- the specific OutputStream
- Throws:
IOException
-
sealStream
public static void sealStream(CheckedOutputStream os, OutputArchive oa) throws 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:
IOException
-
checkSealIntegrity
public static void checkSealIntegrity(CheckedInputStream is, InputArchive ia) throws IOException
Verify the integrity of the seal, only CheckedInputStream will verify the checkSum of the content.- Throws:
IOException
-
isValidSnapshot
public static boolean isValidSnapshot(File file) throws 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:
IOException
-
setStreamMode
public static void setStreamMode(SnapStream.StreamMode mode)
-
getStreamMode
public static SnapStream.StreamMode getStreamMode()
-
getStreamMode
public static SnapStream.StreamMode getStreamMode(String fileName)
Detect the stream mode from file name extension- Parameters:
fileName
-- Returns:
- the stream mode detected
-
-