Coverage Summary for Class: FileUtil (org.ethereum.util)

Class Class, % Method, % Line, %
FileUtil 0% (0/1) 0% (0/5) 0% (0/17)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package org.ethereum.util; 21  22 import org.slf4j.Logger; 23 import org.slf4j.LoggerFactory; 24  25 import java.io.File; 26 import java.nio.file.Path; 27 import java.nio.file.Paths; 28  29 import static java.lang.System.getProperty; 30  31 public class FileUtil { 32  private static final Logger LOGGER = LoggerFactory.getLogger("file"); 33  34  private FileUtil() { 35  36  } 37  38  public static Path getDatabaseDirectoryPath(String databaseDirectory, String name) { 39  if (Paths.get(databaseDirectory).isAbsolute()) { 40  return Paths.get(databaseDirectory, name); 41  } else { 42  return Paths.get(getProperty("user.dir"), databaseDirectory, name); 43  } 44  } 45  46  public static boolean fileRename(String originalName, String newName) { 47  File file = new File(originalName); 48  return file.renameTo(new File(newName)); 49  } 50  51  public static boolean recursiveDelete(String fileName) { 52  File file = new File(fileName); 53  if (file.exists()) { 54  //check if the file is a directory 55  if (file.isDirectory() && (file.list()).length > 0) { 56  for(String s:file.list()){ 57  //call deletion of file individually 58  recursiveDelete(fileName + System.getProperty("file.separator") + s); 59  } 60  } 61  62  if (!file.setWritable(true)) { 63  LOGGER.error("File {} is not writable", file); 64  } 65  66  boolean result = file.delete(); 67  return result; 68  } else { 69  return false; 70  } 71  } 72  73 }