Mercurial > hg > ThermostatQA
view src/org/thermostat/qa2/framework/utils/FileUtilities.java @ 170:0d34a379de82
- Added new framework (package org.thermosta.qa2.framework)
- Removed hardcoded display in org.thermostat.qa.framework.GuiRobot class
author | Zdenek Zambersky <zzambers@redhat.com> |
---|---|
date | Tue, 10 Mar 2015 13:38:36 +0100 |
parents | |
children | 6b6ac47a811f |
line wrap: on
line source
/* ThermostatQA - test framework for Thermostat Monitoring Tool Copyright 2015 Red Hat, Inc. This file is part of ThermostatQA ThermostatQA is distributed under the GNU General Public License, version 2 or any later version (with a special exception described below, commonly known as the "Classpath Exception"). A copy of GNU General Public License (GPL) is included in this distribution, in the file COPYING. Linking ThermostatQA code with other modules is making a combined work based on ThermostatQA. Thus, the terms and conditions of the GPL cover the whole combination. As a special exception, the copyright holders of ThermostatQA give you permission to link this code with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on ThermostatQA code. If you modify ThermostatQA, you may extend this exception to your version of the software, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ package org.thermostat.qa2.framework.utils; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Zdeněk Žamberský */ public class FileUtilities { public static String getFileName(String s) { int i = s.lastIndexOf(File.separator); return i >= 0 ? s.substring(i + 1) : s; } public static String getUniqueFile(String file) { String name = file; int counter = 1; while (new File(name).exists()) { name = file + counter++; } return name; } public static void copyFile(String src, String dest) throws Exception { ProcessUtilities.run("cp", "--", src, dest); } public static List<String> getLineListFromFile(String file) throws FileNotFoundException, IOException { ArrayList<String> list = new ArrayList(); return addLinesFromFileToList(list, file); } public static List<String> addLinesFromFileToList(List<String> list, String file) throws FileNotFoundException, IOException { FileReader fis = null; BufferedReader br = null; try { fis = new FileReader(file); br = new BufferedReader(fis); return CommonUtilities.addLinesToList(list, br); } finally { if (br != null) { try { br.close(); } catch (IOException ex) { Logger.getLogger(FileUtilities.class.getName()).log(Level.SEVERE, null, ex); } } if (fis != null) { try { fis.close(); } catch (IOException ex) { Logger.getLogger(FileUtilities.class.getName()).log(Level.SEVERE, null, ex); } } } } }