Class Util
- java.lang.Object
- 
- org.apache.zookeeper.server.persistence.Util
 
- 
 public class Util extends Object A collection of utility methods for dealing with file name parsing, low level I/O file operations and marshalling/unmarshalling.
- 
- 
Constructor SummaryConstructors Constructor Description Util()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static StringgetFormatConversionPolicy(Properties props)Extracts the value of the dbFormatConversion attribute.static FilegetLogDir(Properties props)Extracts transaction log directory property value from the container.static FilegetSnapDir(Properties props)Extracts snapshot directory property value from the container.static longgetZxidFromName(String name, String prefix)Extracts zxid from the file name.static booleanisLogFileName(String fileName)Returns true if fileName is a log file name.static booleanisSnapshotFileName(String fileName)Returns true if fileName is a snapshot file name.static URImakeFileLoggerURL(File dataDir, File dataLogDir)Given two directory files the method returns a well-formed logfile provider URI.static URImakeFileLoggerURL(File dataDir, File dataLogDir, String convPolicy)static StringmakeLogName(long zxid)Creates a valid transaction log file name.static StringmakeSnapshotName(long zxid)Creates a snapshot file name.static StringmakeURIString(String dataDir, String dataLogDir, String convPolicy)static byte[]marshallTxnEntry(TxnHeader hdr, Record txn)Serializes transaction header and transaction data into a byte buffer.static byte[]marshallTxnEntry(TxnHeader hdr, Record txn, TxnDigest digest)static byte[]readTxnBytes(InputArchive ia)Reads a transaction entry from the input archive.static List<File>sortDataDir(File[] files, String prefix, boolean ascending)Sort the list of files.static voidwriteTxnBytes(OutputArchive oa, byte[] bytes)Write the serialized transaction record to the output archive.
 
- 
- 
- 
Method Detail- 
makeURIStringpublic static String makeURIString(String dataDir, String dataLogDir, String convPolicy) 
 - 
makeFileLoggerURLpublic static URI makeFileLoggerURL(File dataDir, File dataLogDir) Given two directory files the method returns a well-formed logfile provider URI. This method is for backward compatibility with the existing code that only supports logfile persistence and expects these two parameters passed either on the command-line or in the configuration file.- Parameters:
- dataDir- snapshot directory
- dataLogDir- transaction log directory
- Returns:
- logfile provider URI
 
 - 
makeFileLoggerURLpublic static URI makeFileLoggerURL(File dataDir, File dataLogDir, String convPolicy) 
 - 
makeLogNamepublic static String makeLogName(long zxid) Creates a valid transaction log file name.- Parameters:
- zxid- used as a file name suffix (extension)
- Returns:
- file name
 
 - 
makeSnapshotNamepublic static String makeSnapshotName(long zxid) Creates a snapshot file name.- Parameters:
- zxid- used as a suffix
- Returns:
- file name
 
 - 
getSnapDirpublic static File getSnapDir(Properties props) Extracts snapshot directory property value from the container.- Parameters:
- props- properties container
- Returns:
- file representing the snapshot directory
 
 - 
getLogDirpublic static File getLogDir(Properties props) Extracts transaction log directory property value from the container.- Parameters:
- props- properties container
- Returns:
- file representing the txn log directory
 
 - 
getFormatConversionPolicypublic static String getFormatConversionPolicy(Properties props) Extracts the value of the dbFormatConversion attribute.- Parameters:
- props- properties container
- Returns:
- value of the dbFormatConversion attribute
 
 - 
getZxidFromNamepublic static long getZxidFromName(String name, String prefix) Extracts zxid from the file name. The file name should have been created using one of themakeLogName(long)ormakeSnapshotName(long).- Parameters:
- name- the file name to parse
- prefix- the file name prefix (snapshot or log)
- Returns:
- zxid
 
 - 
readTxnBytespublic static byte[] readTxnBytes(InputArchive ia) throws IOException Reads a transaction entry from the input archive.- Parameters:
- ia- archive to read from
- Returns:
- null if the entry is corrupted or EOF has been reached; a buffer (possible empty) containing serialized transaction record.
- Throws:
- IOException
 
 - 
marshallTxnEntrypublic static byte[] marshallTxnEntry(TxnHeader hdr, Record txn) throws IOException Serializes transaction header and transaction data into a byte buffer.- Parameters:
- hdr- transaction header
- txn- transaction data
- Returns:
- serialized transaction record
- Throws:
- IOException
 
 - 
marshallTxnEntrypublic static byte[] marshallTxnEntry(TxnHeader hdr, Record txn, TxnDigest digest) throws IOException - Throws:
- IOException
 
 - 
writeTxnBytespublic static void writeTxnBytes(OutputArchive oa, byte[] bytes) throws IOException Write the serialized transaction record to the output archive.- Parameters:
- oa- output archive
- bytes- serialized transaction record
- Throws:
- IOException
 
 - 
sortDataDirpublic static List<File> sortDataDir(File[] files, String prefix, boolean ascending) Sort the list of files. Recency as determined by the version component of the file name.- Parameters:
- files- array of files
- prefix- files not matching this prefix are assumed to have a version = -1)
- ascending- true sorted in ascending order, false results in descending order
- Returns:
- sorted input files
 
 - 
isLogFileNamepublic static boolean isLogFileName(String fileName) Returns true if fileName is a log file name.- Parameters:
- fileName-
 
 - 
isSnapshotFileNamepublic static boolean isSnapshotFileName(String fileName) Returns true if fileName is a snapshot file name.- Parameters:
- fileName-
 
 
- 
 
-