List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:com.googlesource.gerrit.plugins.findowners.OwnersValidatorTest.java
private static void addFiles(Git git, Map<File, byte[]> files) throws IOException, GitAPIException { AddCommand ac = git.add();/* w w w . j a va2 s . c o m*/ for (File f : files.keySet()) { if (!f.exists()) { FileUtils.touch(f); } if (files.get(f) != null) { FileUtils.writeByteArrayToFile(f, files.get(f)); } ac = ac.addFilepattern(generateFilePattern(f, git)); } ac.call(); }
From source file:ee.ria.xroad.asyncdb.messagequeue.MessageQueueImpl.java
/** * Creates queue branch with metainfo directory in the filesystem. *///from ww w . j a va2 s . co m private synchronized void createQueueBranch(final QueueInfo queueInfo) throws Exception { final File queueDir = new File(providerDirPath); File lockFile = new File(AsyncDBUtil.getGlobalLockFilePath()); LOG.info("Creating directory for provider {} ({})", queueInfo.getName(), providerDirPath); // Global lock file must be present in order to create queues safely // under the lock if (!lockFile.exists()) { FileUtils.touch(lockFile); } if (!queueDir.exists()) { Callable<Object> queueDirCreationTask = () -> { queueDir.mkdirs(); saveQueueInfo(queueInfo); // We use separate file for locking because // continuous overwriting of the metadata // file clears the locked file regions. FileUtils.touch(makeFile(providerDirPath, LOCK_FILE_NAME)); return null; }; AsyncDBUtil.performLocked(queueDirCreationTask, AsyncDBUtil.getGlobalLockFilePath(), this); } }
From source file:com.comcast.cats.service.util.VideoRecorderUtil.java
/** * Checks if the file can be opened in s write mode. * /*from w w w . ja v a2 s.c o m*/ * Tested on RHEL 6 and Windows. * * @param filePath * @return */ public static boolean isPlayable(String filePath) { boolean isPlayable = false; String os = System.getProperty("os.name").toLowerCase(); if ((os.indexOf("nix") >= 0) || (os.indexOf("nux") >= 0) || (os.indexOf("aix") > 0)) { isPlayable = isPlayableInLinux(filePath); } else // ( ( os.indexOf( "win" ) >= 0 ) || ( os.indexOf( "mac" ) >= 0 ) || ( // os.indexOf( "sunos" ) >= 0 ) ) { try { File file = new File(filePath); if (file.isFile()) { // Will always return true in Linux as Linux allows multiple // process to access file at the same time. FileUtils.touch(file); isPlayable = true; } } catch (IOException e) { isPlayable = false; } } return isPlayable; }
From source file:de.joinout.criztovyl.tools.file.Path.java
/** * Creates a file on this {@link Path} if it not exists. * @throws IOException If an I/O error occurs * @see FileUtils#touch(File)/*from ww w . ja v a 2s .c o m*/ * @see File#exists() */ public void touch() throws IOException { if (!getFile().exists()) FileUtils.touch(getFile()); }
From source file:com.tethrnet.manage.util.SSHUtil.java
public static String downloadFile(SchSession session, String fileName) throws Exception { HostSystem hostSystem = session.getHostSystem(); Channel channel = null;/*from w w w. jav a2 s.c o m*/ ChannelSftp c = null; String remote_dir = AppConfig.getProperty("remote_download_dir"); String local_dir = AppConfig.getProperty("local_download_dir"); safeMkdir(local_dir); String local_home_dir = local_dir + File.separator + hostSystem.getUser(); safeMkdir(local_home_dir); String local_cache_dir = local_home_dir + File.separator + RandomString(10); safeMkdir(local_cache_dir); String temp_file = local_cache_dir + hostSystem.getDisplayNm() + "_" + fileName; FileUtils.touch(new File(temp_file)); String remote_file = remote_dir + File.separator + fileName; try { OutputStream ouputstream = new FileOutputStream(new File(temp_file)); channel = session.getSession().openChannel("sftp"); channel.setInputStream(System.in); channel.setOutputStream(System.out); channel.connect(CHANNEL_TIMEOUT); c = (ChannelSftp) channel; c.cd(remote_dir); c.get(remote_file, ouputstream); ouputstream.close(); } catch (Exception e) { log.info(e.toString(), e); return null; } //exit if (c != null) { c.exit(); } //disconnect if (channel != null) { channel.disconnect(); } return temp_file; }
From source file:com.izforge.izpack.core.data.DefaultVariablesTest.java
/** * Tests for IZPACK-1260//from w w w .jav a 2 s . c o m */ @Test public void testDynamicVariablesIZPACK1260() { // set up conditions Map<String, Condition> conditions = new HashMap<String, Condition>(); conditions.put("haveInstallPath", new ExistsCondition(ExistsCondition.ContentType.VARIABLE, "INSTALL_PATH")); conditions.put("previous.wrapper.conf.exists", new ExistsCondition(ExistsCondition.ContentType.FILE, "${previous.wrapper.conf}")); // set up the rules AutomatedInstallData installData = new AutomatedInstallData(variables, Platforms.LINUX); RulesEngineImpl rules = new RulesEngineImpl(installData, new ConditionContainer(new DefaultContainer()), installData.getPlatform()); rules.readConditionMap(conditions); ((DefaultVariables) variables).setRules(rules); variables.add(createDynamicCheckonce("previous.wrapper.conf", "${INSTALL_PATH}/conf/wrapper.conf".replace("/", File.separator), "haveInstallPath")); variables.add(createDynamicCheckonce("previous.wrapper.conf", "${INSTALL_PATH}/wrapper.conf".replace("/", File.separator), "haveInstallPath+!previous.wrapper.conf.exists")); File installPath = null; File confFile = null; try { installPath = rootFolder.newFolder("myapp"); File confPath = new File(installPath, "conf"); confPath.mkdirs(); confFile = new File(confPath, "wrapper.conf"); FileUtils.touch(confFile); } catch (IOException e) { fail("File operation failed."); } variables.set("INSTALL_PATH", installPath.getAbsolutePath()); variables.refresh(); assertEquals(confFile.getAbsolutePath(), variables.get("previous.wrapper.conf")); }
From source file:ke.co.tawi.babblesms.server.utils.export.topups.AllTopupsExportUtil.java
public static boolean createExcelExport2(final List<OutgoingLog> topups, final HashMap<String, String> networkHash, final HashMap<String, String> statusHash, final String delimiter, final String excelFile) { boolean success = true; int rowCount = 0; // To keep track of the row that we are on Row row;//from ww w .j ava2s . com Map<String, CellStyle> styles; SXSSFWorkbook wb = new SXSSFWorkbook(5000); // keep 5000 rows in memory, exceeding rows will be flushed to disk // Each line of the file is approximated to be 200 bytes in size, // therefore 5000 lines are approximately 1 MB in memory // wb.setCompressTempFiles(true); // temporary files will be gzipped on disk Sheet sheet = wb.createSheet("Airtime Topup"); styles = createStyles(wb); PrintSetup printSetupTopup = sheet.getPrintSetup(); printSetupTopup.setLandscape(true); sheet.setFitToPage(true); // Set up the heading to be seen in the Excel sheet row = sheet.createRow(rowCount); Cell titleCell; row.setHeightInPoints(45); titleCell = row.createCell(0); titleCell.setCellValue("Airtime Topups"); sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$L$1")); titleCell.setCellStyle(styles.get("title")); rowCount++; row = sheet.createRow(rowCount); row.setHeightInPoints(12.75f); for (int i = 0; i < TOPUP_TITLES.length; i++) { Cell cell = row.createCell(i); cell.setCellValue(TOPUP_TITLES[i]); cell.setCellStyle(styles.get("header")); } rowCount++; FileUtils.deleteQuietly(new File(excelFile)); FileOutputStream out; try { FileUtils.touch(new File(excelFile)); Cell cell; for (OutgoingLog topup : topups) { row = sheet.createRow(rowCount); cell = row.createCell(0); cell.setCellValue(topup.getUuid()); //cell = row.createCell(1); //cell.setCellValue(topup.getMessageid()); cell = row.createCell(2); cell.setCellValue(topup.getDestination()); cell = row.createCell(3); cell.setCellValue(networkHash.get(topup.getOrigin())); cell = row.createCell(4); cell.setCellValue(statusHash.get(topup.getMessage())); cell = row.createCell(5); cell.setCellValue(topup.getLogTime().toString()); rowCount++; } out = new FileOutputStream(excelFile); wb.write(out); out.close(); } catch (IOException e) { logger.error("IOException while trying to create Excel file '" + excelFile + "' from list of topups."); logger.error(ExceptionUtils.getStackTrace(e)); success = false; } wb.dispose(); // dispose of temporary files backup of this workbook on disk return success; }
From source file:hudson.plugins.jobConfigHistory.FileHistoryDaoTest.java
/** * Test of renameItem method, of class FileHistoryDao. *//*from w w w . ja va 2s . c o m*/ @Test public void testRenameItem() throws IOException { String newName = "NewName"; File newJobDir = unpackResourceZip.getResource("jobs/" + newName); // Rename of Job is already done in Listener. FileUtils.touch(new File(newJobDir, "config.xml")); when(mockedItem.getRootDir()).thenReturn(newJobDir); sutWithUserAndNoDuplicateHistory.renameItem(mockedItem, "Test1", "NewName"); final File newHistoryDir = new File(historyRoot, "jobs/" + newName); assertTrue(newHistoryDir.exists()); assertEquals(6, newHistoryDir.list().length); }
From source file:com.websqrd.catbot.setting.CatbotSettings.java
public static int updateRepo(String id, String key, String value) throws SettingException { Element root = null;/*from w w w.java 2 s .co m*/ String repoFilename = "repository_" + id + ".xml"; String repoConfigFileDir = getKey(repoFilename); File frepo = new File(repoConfigFileDir); if (frepo.exists()) { root = getXml(repoFilename); } else { try { FileUtils.touch(frepo); } catch (IOException e) { throw new SettingException(e.getMessage()); } root = getXml(repoFilename); } if (root == null) return 3; return updateRepo0(id, root, key, value); }
From source file:gov.redhawk.sca.efs.server.tests.FileSystemImplTest.java
/** * Test method for//from w w w . j av a 2 s . co m * {@link gov.redhawk.efs.sca.server.internal.FileSystemImpl#remove(java.lang.String)} * . * * @throws IOException */ @Test public void testRemove() throws IOException { final File file = new File(FileSystemImplTest.root, FileSystemImplTest.TEMP_FILE_NAME); FileUtils.touch(file); Assert.assertTrue(file.exists()); try { this.fileSystem.remove(FileSystemImplTest.TEMP_FILE_NAME); Assert.assertFalse(file.exists()); } catch (final FileException e) { Assert.fail(e.getMessage() + ": " + e.msg); } catch (final InvalidFileName e) { Assert.fail(e.getMessage() + ": " + e.msg); } }