Package com.h2tcoin.takamakachain.utils
Class FileHelper
- java.lang.Object
-
- com.h2tcoin.takamakachain.utils.FileHelper
-
public class FileHelper extends Object
- Author:
- giovanni.antino@h2tcoin.com
-
-
Constructor Summary
Constructors Constructor Description FileHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
addressBookDirExists()
static boolean
blockExists(int epochNumber, int slotNumber, String blockHashNumber)
static boolean
blockExists(StatePointerBean spb)
static boolean
chainDirectoryExists()
Chain directorystatic void
copy(Path sources, Path destination)
OVERWRITEstatic void
createDir(Path directoryPathAndName)
create directory the path is built usingPaths.get()
static void
createFolderAtPathIfNoneExist(Path path)
Creates a directory at the indicated path if none exist alreadystatic Path
createIfNotExistQteslaReferenceFolder(String addr)
static Path
createSlotDirectory(int epochNumber, int slotNumber)
Create slot directory and return path, or return slot directory path if existsstatic boolean
defaultStatePathExists()
true if the application state file existsstatic boolean
defaultZeroBlockDirectoryExists()
First block directorystatic boolean
defaultZeroBlockFileExists()
First blockstatic String
deflateInflateAddress(String addr, boolean deflate)
static void
delete(File f)
delete passed file or the folder and all its content, recursively.static void
delete(Path file)
delete RECURSIVELY everithing in the pathstatic void
deleteFolderContent(File f)
recursively delete folder content TODO delete root folder?static void
deleteSettings(String option)
static void
deleteSingleFile(Path filePath)
static boolean
directoryExists(Path filePointer)
static boolean
epochDirectoryExists(int epochNumber)
Epoch directorystatic void
extractFromJar(String resourceName, Path destinationPath)
static boolean
fileExists(Path file)
static String
getBlockName(String blockUID)
convert uid into database namestatic Path
getBlockPath(int epochNumber, int slotNumber, String blockHashNumber)
return the path without extensionstatic Path
getBlockPathWithExension(int epochNumber, int slotNumber, String blockHashNumber)
return the path with extensionstatic Path
getChainDirectory()
return the path of default chain directorystatic Path
getChainLockFile()
default path for chain lock filestatic Path
getDefaultAddressBookDirectoryPath()
static Path
getDefaultApplicationDirectoryPath()
return the default path to application directorystatic Path
getDefaultLogsDirectoryPath()
static Path
getDefaultStatePath()
return the path of the application state filestatic Path
getDefaultWalletDirectoryPath()
static Path
getDefaultZeroBlockDirectory()
return the path to the zero block folderstatic Path
getDefaultZeroBlockFile()
return the path to the block required to initialize the chainstatic Path
getEphemeralWalletDirectoryPath()
static Path
getEpochDirectory(int epochNumber)
return the path to the epoch folderstatic ArrayList<String>
getFileList(Path folderPath, String filter)
return the list of wallets inside folder pathstatic File[]
getFolderContent(Path folderPath)
list file in the passed folderstatic Path
getHotmokaFilesDirectoryPath()
static Path
getHotmokaTestDirectoryPath()
static Path
getKeyWriterBucketDirectory(int epoch, int slot, String uid, FixedParameters.HexKeyWriter hkw)
return the bucket directorystatic ConcurrentSkipListMap<String,MainAliasBean>
getMainAliasList()
static Path
getNodeNetworkSettings()
static Path
getPublicKeyDirectoryPath()
static Path
getQteslaReferenceAddressFolder(String addr)
static Path
getQteslaReferenceFolder()
static String
getReferenceKeyStringNoSave(String qAddr)
static Path
getSettingsPathFolder()
static Path
getSimulationPathFolder()
static Path
getSlotDirectory(int epochNumber, int slotNumber)
return the path to the slot directorystatic Path
getStatePath(StatePointerBean spb)
return the state path pointed by spbstatic Path
getTransactionBoxDateFolder(Date input)
static Path
getTransactionBoxFolder(int epoch, int slot)
static Path
getTransactionsDirectoryPath()
static Path
getTransactionsDumpPathFolder()
static Path
getTransactionsDumpPathFolder(String pidName)
static Path
getUserWalletsDirectoryPath()
return the default user wallets directorystatic ArrayList<String>
getWalletList()
static boolean
homeDirExists()
static Path
initKeyHexWriterDirectoryTree(int epoch, int slot, String uid, FixedParameters.HexKeyWriter hkw)
static void
initProjectFiles()
create project directory and folder structure using default parametersstatic Path
logFile(String pattern)
convert pattern fromLog.getLogFilePattern()
to pathstatic boolean
logsDirectoryExists()
Log directorystatic void
moveToSlot(int sourceEpoch, int sourceSlot, String sourceFile, int targetEpoch, int targetSlot, String targetFile)
Moves and renames any existing file or folder within the source epoch and slot to the target epoch and slot, overwrites if file/folder already existsstatic boolean
publicKeyDirExists()
static Object
readObjectFromFile(String filepath)
static Object
readObjectFromFile(Path filePath)
static String
readStringFromFile(Path file)
reads a string from the file indicated in the path if it existsstatic void
rename(Object sourcePath, Object targetPath, Boolean overwrite)
moves the target file/folder to the new destination and can overwrite the existing file/folder if it existsstatic String
retriveQaddrByReference(String refAddr)
static String
saveQteslaAddress(String qAddr)
static boolean
slotDirectoryExists(int epochNumber, int slotNumber)
Slot directorystatic boolean
testMandatoryStatusBean(int epoch, int slot, String uid)
static boolean
transactionsDirExists()
static boolean
walletDirExists()
static boolean
walletEphemeralDirExists()
static void
writeFavouriteToBookmarkList(ConcurrentSkipListMap<String,FavouriteToBookmark> getListMapFavouriteToBookmark)
static void
writeObjectToFile(Path path, String sithNumber, Object input)
static boolean
writeStringToFile(Path directory, String fileName, String content, boolean overwrite)
Write a string to file
If file does not exist the string will be written to file and the function return true.static void
writeTransactionBoxToFile(Path path, Object input)
-
-
-
Field Detail
-
KEYLOCK
public static final Object KEYLOCK
-
-
Method Detail
-
getDefaultApplicationDirectoryPath
public static Path getDefaultApplicationDirectoryPath()
return the default path to application directory- Returns:
-
getHotmokaTestDirectoryPath
public static Path getHotmokaTestDirectoryPath()
-
getHotmokaFilesDirectoryPath
public static Path getHotmokaFilesDirectoryPath()
-
getUserWalletsDirectoryPath
public static Path getUserWalletsDirectoryPath()
return the default user wallets directory- Returns:
-
getDefaultStatePath
public static Path getDefaultStatePath()
return the path of the application state file- Returns:
-
getStatePath
public static Path getStatePath(StatePointerBean spb) throws IOException
return the state path pointed by spb- Parameters:
spb
-- Returns:
- Throws:
IOException
-
defaultStatePathExists
public static boolean defaultStatePathExists()
true if the application state file exists- Returns:
-
homeDirExists
public static boolean homeDirExists()
- Returns:
- true if the default project home dir exist
-
getDefaultWalletDirectoryPath
public static Path getDefaultWalletDirectoryPath()
- Returns:
- default wallet directory path
-
getPublicKeyDirectoryPath
public static Path getPublicKeyDirectoryPath()
- Returns:
- default public keys directory path
-
getTransactionsDirectoryPath
public static Path getTransactionsDirectoryPath()
- Returns:
- default transactions directory path
-
getEphemeralWalletDirectoryPath
public static Path getEphemeralWalletDirectoryPath()
- Returns:
- ephemeral wallet directory path
-
getDefaultAddressBookDirectoryPath
public static Path getDefaultAddressBookDirectoryPath()
- Returns:
- default address book directory path
-
getDefaultLogsDirectoryPath
public static Path getDefaultLogsDirectoryPath()
- Returns:
- default logs directory path
-
logFile
public static Path logFile(String pattern)
convert pattern fromLog.getLogFilePattern()
to path- Parameters:
pattern
-- Returns:
-
getChainDirectory
public static Path getChainDirectory()
return the path of default chain directory- Returns:
-
getChainLockFile
public static Path getChainLockFile()
default path for chain lock file- Returns:
-
getEpochDirectory
public static Path getEpochDirectory(int epochNumber)
return the path to the epoch folder- Parameters:
epochNumber
-- Returns:
-
getSlotDirectory
public static Path getSlotDirectory(int epochNumber, int slotNumber)
return the path to the slot directory- Parameters:
epochNumber
-slotNumber
-- Returns:
-
getDefaultZeroBlockDirectory
public static Path getDefaultZeroBlockDirectory()
return the path to the zero block folder- Returns:
-
getDefaultZeroBlockFile
public static Path getDefaultZeroBlockFile()
return the path to the block required to initialize the chain- Returns:
-
getKeyWriterBucketDirectory
public static Path getKeyWriterBucketDirectory(int epoch, int slot, String uid, FixedParameters.HexKeyWriter hkw)
return the bucket directory- Parameters:
epoch
-slot
-uid
-hkw
-- Returns:
-
initKeyHexWriterDirectoryTree
public static Path initKeyHexWriterDirectoryTree(int epoch, int slot, String uid, FixedParameters.HexKeyWriter hkw)
-
defaultZeroBlockDirectoryExists
public static boolean defaultZeroBlockDirectoryExists()
First block directory- Returns:
- true if exists and is a directory
-
defaultZeroBlockFileExists
public static boolean defaultZeroBlockFileExists()
First block- Returns:
- true if is file and exixsts
-
slotDirectoryExists
public static boolean slotDirectoryExists(int epochNumber, int slotNumber)
Slot directory- Parameters:
epochNumber
-slotNumber
-- Returns:
- true if exists and is a directory
-
epochDirectoryExists
public static boolean epochDirectoryExists(int epochNumber)
Epoch directory- Parameters:
epochNumber
-- Returns:
- true if exists and is a directory
-
getNodeNetworkSettings
public static Path getNodeNetworkSettings()
-
chainDirectoryExists
public static boolean chainDirectoryExists()
Chain directory- Returns:
- true if exists and is a directory
-
logsDirectoryExists
public static boolean logsDirectoryExists()
Log directory- Returns:
- true if exists and is a directory
-
createSlotDirectory
public static Path createSlotDirectory(int epochNumber, int slotNumber) throws IOException
Create slot directory and return path, or return slot directory path if exists- Parameters:
epochNumber
-slotNumber
-- Returns:
- slot directory path
- Throws:
IOException
-
createFolderAtPathIfNoneExist
public static void createFolderAtPathIfNoneExist(Path path) throws IOException
Creates a directory at the indicated path if none exist already- Parameters:
path
-- Throws:
IOException
-
getTransactionBoxFolder
public static Path getTransactionBoxFolder(int epoch, int slot)
- Returns:
-
getBlockName
public static String getBlockName(String blockUID)
convert uid into database name- Parameters:
blockUID
-- Returns:
-
getBlockPath
public static Path getBlockPath(int epochNumber, int slotNumber, String blockHashNumber)
return the path without extension- Parameters:
epochNumber
-slotNumber
-blockHashNumber
-StringUtils.getBlockHashNumber(blockHash)
- Returns:
- return the path for the requested block
-
getBlockPathWithExension
public static Path getBlockPathWithExension(int epochNumber, int slotNumber, String blockHashNumber)
return the path with extension- Parameters:
epochNumber
-slotNumber
-blockHashNumber
-StringUtils.getBlockHashNumber(blockHash)
- Returns:
- return the path for the requested block
-
blockExists
public static boolean blockExists(int epochNumber, int slotNumber, String blockHashNumber)
- Parameters:
epochNumber
-slotNumber
-blockHashNumber
-- Returns:
- true if file exists and is file
-
walletDirExists
public static boolean walletDirExists()
- Returns:
- true if the directory exist
-
publicKeyDirExists
public static boolean publicKeyDirExists()
- Returns:
- true if the directory exist
-
transactionsDirExists
public static boolean transactionsDirExists()
- Returns:
- true if the directory exist
-
walletEphemeralDirExists
public static boolean walletEphemeralDirExists()
- Returns:
- true if the directory exist
-
addressBookDirExists
public static boolean addressBookDirExists()
- Returns:
- true if the address book exist
-
createDir
public static void createDir(Path directoryPathAndName) throws IOException
create directory the path is built usingPaths.get()
- Parameters:
directoryPathAndName
-- Throws:
IOException
-
getSettingsPathFolder
public static Path getSettingsPathFolder()
-
getTransactionsDumpPathFolder
public static Path getTransactionsDumpPathFolder()
-
getSimulationPathFolder
public static Path getSimulationPathFolder()
-
extractFromJar
public static void extractFromJar(String resourceName, Path destinationPath)
- Parameters:
resourceName
- resource namedestinationPath
- destination folder path
-
initProjectFiles
public static void initProjectFiles() throws IOException
create project directory and folder structure using default parameters- Throws:
IOException
-
getQteslaReferenceFolder
public static Path getQteslaReferenceFolder()
-
createIfNotExistQteslaReferenceFolder
public static Path createIfNotExistQteslaReferenceFolder(String addr)
-
getMainAliasList
public static ConcurrentSkipListMap<String,MainAliasBean> getMainAliasList()
-
writeFavouriteToBookmarkList
public static void writeFavouriteToBookmarkList(ConcurrentSkipListMap<String,FavouriteToBookmark> getListMapFavouriteToBookmark)
-
fileExists
public static boolean fileExists(Path file)
- Parameters:
file
-- Returns:
- true if exists and is a file
-
directoryExists
public static boolean directoryExists(Path filePointer)
- Parameters:
filePointer
-- Returns:
- true if exists and is a directory
-
writeStringToFile
public static boolean writeStringToFile(Path directory, String fileName, String content, boolean overwrite) throws IOException
Write a string to file
If file does not exist the string will be written to file and the function return true.
FileHelper.writeStringToFile( FileHelper.getDefaultApplicationDirectoryPath(), "TestFile.txt", "Only create, no overwrite", false)
If file exists and overwite is specified the original file is deleted, new one is created, the string is written in it and the function return true.
FileHelper.writeStringToFile( FileHelper.getDefaultApplicationDirectoryPath(), "TestFile.txt", "Create or Overwrite", true)
If file exists, overvrite is denied function terminate and return false- Parameters:
directory
- destination directoryfileName
- file namecontent
- string to be writed to fileoverwrite
- true for overwriting content if file exists, ignored otherwise- Returns:
- true if succesfully written
- Throws:
IOException
-
getFileList
public static ArrayList<String> getFileList(Path folderPath, String filter)
return the list of wallets inside folder path- Parameters:
folderPath
-filter
-- Returns:
-
getFolderContent
public static File[] getFolderContent(Path folderPath)
list file in the passed folder- Parameters:
folderPath
-- Returns:
-
delete
public static void delete(File f) throws IOException
delete passed file or the folder and all its content, recursively. If f is dir f is deleted- Parameters:
f
-- Throws:
IOException
-
deleteSingleFile
public static void deleteSingleFile(Path filePath)
- Parameters:
filePath
-
-
delete
public static void delete(Path file) throws IOException
delete RECURSIVELY everithing in the path- Parameters:
file
-- Throws:
IOException
-
deleteFolderContent
public static void deleteFolderContent(File f) throws IOException
recursively delete folder content TODO delete root folder?- Parameters:
f
-- Throws:
IOException
-
readStringFromFile
public static String readStringFromFile(Path file) throws FileNotFoundException
reads a string from the file indicated in the path if it exists- Parameters:
file
-Path
- Returns:
- Throws:
FileNotFoundException
-
rename
public static void rename(Object sourcePath, Object targetPath, Boolean overwrite) throws IOException
moves the target file/folder to the new destination and can overwrite the existing file/folder if it exists- Parameters:
sourcePath
- can be of type String/File/PathtargetPath
- can be of type String/File/Pathoverwrite
- indicated whether to overwrite existing files/folders- Throws:
IOException
-
copy
public static void copy(Path sources, Path destination) throws IOException
OVERWRITE- Parameters:
sources
-destination
-- Throws:
IOException
-
moveToSlot
public static void moveToSlot(int sourceEpoch, int sourceSlot, String sourceFile, int targetEpoch, int targetSlot, String targetFile) throws Exception
Moves and renames any existing file or folder within the source epoch and slot to the target epoch and slot, overwrites if file/folder already exists- Parameters:
sourceEpoch
-sourceSlot
-sourceFile
-targetEpoch
-targetSlot
-targetFile
-- Throws:
Exception
-
deleteSettings
public static void deleteSettings(String option)
-
blockExists
public static boolean blockExists(StatePointerBean spb)
- Parameters:
spb
-- Returns:
- true if file exists and is file
-
writeTransactionBoxToFile
public static void writeTransactionBoxToFile(Path path, Object input)
- Parameters:
path
-input
-
-
writeObjectToFile
public static void writeObjectToFile(Path path, String sithNumber, Object input)
- Parameters:
path
-sithNumber
-input
-
-
readObjectFromFile
public static Object readObjectFromFile(Path filePath)
- Parameters:
filePath
-- Returns:
-
readObjectFromFile
public static Object readObjectFromFile(String filepath)
- Parameters:
filepath
-- Returns:
-
testMandatoryStatusBean
public static boolean testMandatoryStatusBean(int epoch, int slot, String uid)
- Parameters:
epoch
-slot
-uid
-- Returns:
- false if cs is not consistent
-
-