List of usage examples for java.io File setExecutable
public boolean setExecutable(boolean executable)
From source file:io.github.bonigarcia.wdm.Downloader.java
public static File unGzip(File archive) throws IOException { log.trace("UnGzip {}", archive); String fileName = archive.getName(); int iDash = fileName.indexOf("-"); if (iDash != -1) { fileName = fileName.substring(0, iDash); }/*from w w w .j ava2 s. c o m*/ int iDot = fileName.indexOf("."); if (iDot != -1) { fileName = fileName.substring(0, iDot); } File target = new File(archive.getParentFile() + File.separator + fileName); try (GZIPInputStream in = new GZIPInputStream(new FileInputStream(archive))) { try (FileOutputStream out = new FileOutputStream(target)) { for (int c = in.read(); c != -1; c = in.read()) { out.write(c); } } } if (!target.getName().toLowerCase().contains(".exe") && target.exists()) { target.setExecutable(true); } return target; }
From source file:edu.isi.wings.portal.classes.domains.Domain.java
public static Domain importLegacyDomain(String domName, Config config, String legacyDomDir) { // Get Legacy apis PropertiesHelper.resetProperties();// w ww.j a v a2s . c o m PropertiesHelper.loadWingsProperties(legacyDomDir + fsep + "wings.properties"); Properties legacyprops = TemplateFactory.createLegacyConfiguration(); legacyprops.putAll(DataFactory.createLegacyConfiguration()); legacyprops.putAll(ComponentFactory.createLegacyConfiguration()); DataCreationAPI ldc = DataFactory.getCreationAPI(legacyprops); ComponentCreationAPI lacc = ComponentFactory.getCreationAPI(legacyprops, false); ComponentCreationAPI lccc = ComponentFactory.getCreationAPI(legacyprops, true); TemplateCreationAPI ltc = TemplateFactory.getCreationAPI(legacyprops); // Get new apis Domain domain = Domain.createDefaultDomain(domName, config.getUserDir(), config.getExportUserUrl()); Properties props = config.getProperties(domain); DataCreationAPI dc = DataFactory.getCreationAPI(props); ComponentCreationAPI acc = ComponentFactory.getCreationAPI(props, false); ComponentCreationAPI ccc = ComponentFactory.getCreationAPI(props, true); TemplateCreationAPI tc = TemplateFactory.getCreationAPI(props); // Copy from legacy apis to new apis dc.copyFrom(ldc); acc.copyFrom(lacc); ccc.copyFrom(lccc); tc.copyFrom(ltc); // Copy legacy data/code directories to new data/code storage directory File srcDataDir = new File(PropertiesHelper.getDataDirectory()); File destDataDir = new File( domain.getDomainDirectory() + fsep + domain.getDataLibrary().getStorageDirectory()); File srcCodeDir = new File(PropertiesHelper.getCodeDirectory()); File destCodeDir = new File( domain.getDomainDirectory() + fsep + domain.getConcreteComponentLibrary().getStorageDirectory()); File srcBeamerDir = new File(PropertiesHelper.getOntologyDir() + fsep + "beamer"); File destBeamerDir = new File(domain.getDomainDirectory() + fsep + "beamer"); try { if (srcDataDir.isDirectory()) FileUtils.copyDirectory(srcDataDir, destDataDir); if (srcCodeDir.isDirectory()) { FileUtils.copyDirectory(srcCodeDir, destCodeDir); // FIXME: Setting executable permissions on all files for now for (File f : FileUtils.listFiles(destCodeDir, null, true)) { f.setExecutable(true); } } if (srcBeamerDir.isDirectory()) FileUtils.copyDirectory(srcBeamerDir, destBeamerDir); } catch (IOException e) { e.printStackTrace(); } return domain; }
From source file:edu.isi.wings.portal.classes.domains.Domain.java
public static Domain renameDomain(Domain domain, String newname, Config config) { Properties props = config.getProperties(domain); DataCreationAPI dc = DataFactory.getCreationAPI(props); ComponentCreationAPI acc = ComponentFactory.getCreationAPI(props, false); ComponentCreationAPI ccc = ComponentFactory.getCreationAPI(props, true); TemplateCreationAPI tc = TemplateFactory.getCreationAPI(props); File tempdir;//from w w w. ja v a2s . c om try { tempdir = File.createTempFile("domain-", "-temp"); if (!tempdir.delete() || !tempdir.mkdirs()) return null; } catch (IOException e1) { return null; } Domain todom = Domain.createDefaultDomain(newname, config.getUserDir(), config.getExportUserUrl()); todom.saveDomain(); props = config.getProperties(todom); DataCreationAPI todc = DataFactory.getCreationAPI(props); ComponentCreationAPI toacc = ComponentFactory.getCreationAPI(props, false); ComponentCreationAPI toccc = ComponentFactory.getCreationAPI(props, true); TemplateCreationAPI totc = TemplateFactory.getCreationAPI(props); // Copy into non-triple-store apis todc.copyFrom(dc); toacc.copyFrom(acc); toccc.copyFrom(ccc); totc.copyFrom(tc); // Copy legacy data/code directories to new data/code storage directory File srcDataDir = new File( domain.getDomainDirectory() + fsep + domain.getDataLibrary().getStorageDirectory()); File destDataDir = new File( todom.getDomainDirectory() + fsep + todom.getDataLibrary().getStorageDirectory()); File srcCodeDir = new File( domain.getDomainDirectory() + fsep + domain.getConcreteComponentLibrary().getStorageDirectory()); File destCodeDir = new File( todom.getDomainDirectory() + fsep + todom.getConcreteComponentLibrary().getStorageDirectory()); try { if (srcDataDir.isDirectory()) FileUtils.copyDirectory(srcDataDir, destDataDir); if (srcCodeDir.isDirectory()) { FileUtils.copyDirectory(srcCodeDir, destCodeDir); // FIXME: Setting executable permissions on all files for now for (File f : FileUtils.listFiles(destCodeDir, null, true)) { f.setExecutable(true); } } } catch (IOException e) { e.printStackTrace(); } deleteDomain(domain, config, true); return todom; }
From source file:edu.isi.wings.portal.classes.domains.Domain.java
public static Domain importDomain(String domName, Config config, String importDomDir) { String domurl;/*from w w w.j a v a 2 s . c o m*/ try { domurl = FileUtils.readFileToString(new File(importDomDir + File.separator + "domain.url")); domurl = domurl.trim(); } catch (IOException e1) { e1.printStackTrace(); return null; } Domain fromdom = new Domain(domName, importDomDir, domurl, false); Properties props = config.getProperties(fromdom); DataCreationAPI dc = DataFactory.getCreationAPI(props); ComponentCreationAPI acc = ComponentFactory.getCreationAPI(props, false); ComponentCreationAPI ccc = ComponentFactory.getCreationAPI(props, true); TemplateCreationAPI tc = TemplateFactory.getCreationAPI(props); ResourceAPI rc = ResourceFactory.getAPI(props); Domain todom = Domain.createDefaultDomain(domName, config.getUserDir(), config.getExportUserUrl()); props = config.getProperties(todom); DataCreationAPI todc = DataFactory.getCreationAPI(props); ComponentCreationAPI toacc = ComponentFactory.getCreationAPI(props, false); ComponentCreationAPI toccc = ComponentFactory.getCreationAPI(props, true); TemplateCreationAPI totc = TemplateFactory.getCreationAPI(props); ResourceAPI torc = ResourceFactory.getAPI(props); // Copy from file-based apis to triple-store apis todc.copyFrom(dc); toacc.copyFrom(acc); toccc.copyFrom(ccc); totc.copyFrom(tc); if (rc != null && torc != null) torc.copyFrom(rc, ccc); // Copy legacy data/code directories to new data/code storage directory File srcDataDir = new File( fromdom.getDomainDirectory() + fsep + fromdom.getDataLibrary().getStorageDirectory()); File destDataDir = new File( todom.getDomainDirectory() + fsep + todom.getDataLibrary().getStorageDirectory()); File srcCodeDir = new File( fromdom.getDomainDirectory() + fsep + fromdom.getConcreteComponentLibrary().getStorageDirectory()); File destCodeDir = new File( todom.getDomainDirectory() + fsep + todom.getConcreteComponentLibrary().getStorageDirectory()); File srcBeamerDir = new File(fromdom.getDomainDirectory() + fsep + "beamer"); File destBeamerDir = new File(todom.getDomainDirectory() + fsep + "beamer"); try { if (srcDataDir.isDirectory()) FileUtils.copyDirectory(srcDataDir, destDataDir); if (srcCodeDir.isDirectory()) { FileUtils.copyDirectory(srcCodeDir, destCodeDir); // FIXME: Setting executable permissions on all files for now for (File f : FileUtils.listFiles(destCodeDir, null, true)) { f.setExecutable(true); } } if (srcBeamerDir.isDirectory()) FileUtils.copyDirectory(srcBeamerDir, destBeamerDir); } catch (IOException e) { e.printStackTrace(); } return todom; }
From source file:edu.isi.wings.portal.classes.domains.Domain.java
public static File exportDomain(Domain fromdom, Config config) { Properties props = config.getProperties(fromdom); DataCreationAPI dc = DataFactory.getCreationAPI(props); ComponentCreationAPI acc = ComponentFactory.getCreationAPI(props, false); ComponentCreationAPI ccc = ComponentFactory.getCreationAPI(props, true); TemplateCreationAPI tc = TemplateFactory.getCreationAPI(props); ResourceAPI rc = ResourceFactory.getAPI(props); File tempdir;/*from ww w.j a v a2s . co m*/ try { tempdir = File.createTempFile("domain-", "-temp"); if (!tempdir.delete() || !tempdir.mkdirs()) return null; } catch (IOException e1) { return null; } Domain todom = Domain.createDefaultDomain(fromdom.getDomainName(), tempdir.getAbsolutePath(), config.getExportUserUrl()); todom.setUseSharedTripleStore(false); todom.saveDomain(); props = config.getProperties(todom); DataCreationAPI todc = DataFactory.getCreationAPI(props); ComponentCreationAPI toacc = ComponentFactory.getCreationAPI(props, false); ComponentCreationAPI toccc = ComponentFactory.getCreationAPI(props, true); TemplateCreationAPI totc = TemplateFactory.getCreationAPI(props); ResourceAPI torc = ResourceFactory.getAPI(props); // Copy into non-triple-store apis todc.copyFrom(dc); toacc.copyFrom(acc); toccc.copyFrom(ccc); totc.copyFrom(tc); if (rc != null && torc != null) torc.copyFrom(rc, ccc); // Copy legacy data/code directories to new data/code storage directory File srcDataDir = new File( fromdom.getDomainDirectory() + fsep + fromdom.getDataLibrary().getStorageDirectory()); File destDataDir = new File( todom.getDomainDirectory() + fsep + todom.getDataLibrary().getStorageDirectory()); File srcCodeDir = new File( fromdom.getDomainDirectory() + fsep + fromdom.getConcreteComponentLibrary().getStorageDirectory()); File destCodeDir = new File( todom.getDomainDirectory() + fsep + todom.getConcreteComponentLibrary().getStorageDirectory()); File srcBeamerDir = new File(fromdom.getDomainDirectory() + fsep + "beamer"); File destBeamerDir = new File(todom.getDomainDirectory() + fsep + "beamer"); try { if (srcDataDir.isDirectory()) FileUtils.copyDirectory(srcDataDir, destDataDir); if (srcCodeDir.isDirectory()) { FileUtils.copyDirectory(srcCodeDir, destCodeDir); // FIXME: Setting executable permissions on all files for now for (File f : FileUtils.listFiles(destCodeDir, null, true)) { f.setExecutable(true); } } if (srcBeamerDir.isDirectory()) FileUtils.copyDirectory(srcBeamerDir, destBeamerDir); } catch (IOException e) { e.printStackTrace(); } // Copy domain url File domUriFile = new File(todom.getDomainDirectory() + fsep + "domain.url"); try { FileUtils.write(domUriFile, todom.getDomainUrl()); } catch (IOException e) { e.printStackTrace(); } return tempdir; }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceUtils.java
/** * Make the given URL available as an executable file. A temporary file is created and deleted * upon a regular shutdown of the JVM. If the parameter {@code aCache} is {@code true}, the * temporary file is remembered in a cache and if a file is requested for the same URL at a * later time, the same file is returned again. If the previously created file has been deleted * meanwhile, it is recreated from the URL. * * @param aUrl/*from w w w. j av a 2 s .c o m*/ * the URL. * @param aCache * use the cache or not. * @return an executable file created from the given URL. * @throws IOException * if the file has permissions issues. */ public static synchronized File getUrlAsExecutable(URL aUrl, boolean aCache) throws IOException { File file; synchronized (urlFileCache) { file = urlFileCache.get(aUrl.toString()); if (!aCache || (file == null) || !file.exists()) { String name = FilenameUtils.getBaseName(aUrl.getPath()); file = File.createTempFile(name, ".temp"); file.setExecutable(true); if (!file.canExecute()) { StringBuilder errorMessage = new StringBuilder(128); errorMessage.append("Tried to use temporary folder, but seems it is not " + "executable. Please check the permissions rights from your " + "temporary folder.\n"); if (isEnvironmentVariableDefined(XDG_RUNTIME_DIR_ENV_VAR, errorMessage) && checkFolderPermissions(errorMessage, System.getenv(XDG_RUNTIME_DIR_ENV_VAR))) { file = getFileAsExecutable(aUrl, System.getenv(XDG_RUNTIME_DIR_ENV_VAR)); } else if (isEnvironmentVariableDefined(DKPRO_HOME_ENV_VAR, errorMessage) && checkFolderPermissions(errorMessage, System.getenv(DKPRO_HOME_ENV_VAR) + File.separator + "temp")) { file = getFileAsExecutable(aUrl, System.getenv(DKPRO_HOME_ENV_VAR) + File.separator + "temp"); } else { if (!isUserHomeDefined(errorMessage) || !checkFolderPermissions(errorMessage, System.getProperty("user.home") + File.separator + ".dkpro" + File.separator + "temp")) { throw new IOException(errorMessage.toString()); } file = getFileAsExecutable(aUrl, System.getProperty("user.home") + File.separator + ".dkpro" + File.separator + "temp"); } } file.deleteOnExit(); InputStream inputStream = null; OutputStream outputStream = null; try { inputStream = aUrl.openStream(); outputStream = new FileOutputStream(file); copy(inputStream, outputStream); } finally { closeQuietly(inputStream); closeQuietly(outputStream); } if (aCache) { urlFileCache.put(aUrl.toString(), file); } } } return file; }
From source file:io.vertx.config.vault.utils.VaultDownloader.java
public static File download() { File out = new File("target/vault/vault"); if (SystemUtils.IS_OS_WINDOWS) { out = new File("target/vault/vault.exe"); }//from w w w. j a va2s . co m if (out.isFile()) { return out; } File zip = new File("target/vault.zip"); try { FileUtils.copyURLToFile(getURL(VaultProcess.VAULT_VERSION), zip); } catch (Exception e) { throw new RuntimeException(e); } assert zip.isFile(); System.out.println(zip.getAbsolutePath() + " has been downloaded, unzipping"); try { unzip(zip, out.getParentFile()); } catch (IOException e) { throw new RuntimeException(e); } System.out.println("Vault: " + out.getAbsolutePath()); assert out.isFile(); out.setExecutable(true); assert out.canExecute(); return out; }
From source file:edu.stanford.epad.epadws.dcm4chee.Dcm4CheeOperations.java
public static boolean dcmsnd(File inputDirFile, boolean throwException) throws Exception { InputStream is = null;/*from ww w . j a v a 2s .co m*/ InputStreamReader isr = null; BufferedReader br = null; FileWriter tagFileWriter = null; boolean success = false; try { String aeTitle = EPADConfig.aeTitle; String dicomServerIP = EPADConfig.dicomServerIP; String dicomServerPort = EPADConfig.dicomServerPort; String dicomServerTitleAndPort = aeTitle + "@" + dicomServerIP + ":" + dicomServerPort; dicomServerTitleAndPort = dicomServerTitleAndPort.trim(); String dirPath = inputDirFile.getAbsolutePath(); if (pathContainsSpaces(dirPath)) dirPath = escapeSpacesInDirPath(dirPath); File dir = new File(dirPath); int nbFiles = -1; if (dir != null) { String[] filePaths = dir.list(); if (filePaths != null) nbFiles = filePaths.length; } log.info("./dcmsnd: sending " + nbFiles + " file(s) - command: ./dcmsnd " + dicomServerTitleAndPort + " " + dirPath); String[] command = { "./dcmsnd", dicomServerTitleAndPort, dirPath }; ProcessBuilder processBuilder = new ProcessBuilder(command); String dicomScriptsDir = EPADConfig.getEPADWebServerDICOMScriptsDir() + "bin/"; File script = new File(dicomScriptsDir, "dcmsnd"); if (!script.exists()) dicomScriptsDir = EPADConfig.getEPADWebServerDICOMBinDir(); script = new File(dicomScriptsDir, "dcmsnd"); if (!script.exists()) throw new Exception("No script found:" + script.getAbsolutePath()); // Java 6 - Runtime.getRuntime().exec("chmod u+x "+script.getAbsolutePath()); script.setExecutable(true); processBuilder.directory(new File(dicomScriptsDir)); processBuilder.redirectErrorStream(true); Process process = processBuilder.start(); is = process.getInputStream(); isr = new InputStreamReader(is); br = new BufferedReader(isr); String line; StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line).append("\n"); log.info("./dcmsend output: " + line); } try { int exitValue = process.waitFor(); log.info("DICOM send exit value is: " + exitValue); if (exitValue == 0) success = true; } catch (InterruptedException e) { log.warning("Didn't send DICOM files in: " + inputDirFile.getAbsolutePath(), e); } String cmdLineOutput = sb.toString(); if (cmdLineOutput.toLowerCase().contains("error")) throw new IllegalStateException("Failed for: " + parseError(cmdLineOutput)); return success; } catch (Exception e) { log.warning("DicomSendTask failed to send DICOM files", e); if (e instanceof IllegalStateException && throwException) { throw e; } if (throwException) { throw new IllegalStateException("DicomSendTask failed to send DICOM files", e); } return success; } catch (OutOfMemoryError oome) { log.warning("DicomSendTask out of memory: ", oome); if (throwException) { throw new IllegalStateException("DicomSendTask out of memory: ", oome); } return success; } finally { IOUtils.closeQuietly(tagFileWriter); IOUtils.closeQuietly(br); IOUtils.closeQuietly(isr); IOUtils.closeQuietly(is); } }
From source file:com.magnet.tools.tests.ScenarioUtils.java
private static void extractScripts() { String[] ALL_SCRIPTS = new String[] { INVOKE_MAVEN_SCRIPT, GENERATE_ARCHETYPE_SCRIPT, GENERATE_PROJECT_SCRIPT, GENERATE_PROJECT_DEBUG_SCRIPT, KILL_MAGNET_SCRIPT, KILL_WLS_SCRIPT, START_WLS_SERVER_SCRIPT, STOP_WLS_SERVER_SCRIPT, REDEPLOY_WLS_APP_SCRIPT, WLS_POM_XML_SCRIPT }; File scriptsDir = new File(SCRIPTS_DIR); if (!scriptsDir.mkdir()) { ScenarioUtils.log("Directory already created: " + scriptsDir); }/* w ww. ja va 2 s . c o m*/ for (String script : ALL_SCRIPTS) { String from = SCRIPTS_CLASSPATH + script; String to = SCRIPTS_DIR + File.separator + script; InputStream is = ScenarioUtils.class.getResourceAsStream(from); OutputStream os = null; File file = new File(to); try { if (!file.createNewFile()) { ScenarioUtils.log("File already created " + file); } if (!file.setExecutable(true)) { ScenarioUtils.log("File already executable: " + file); } os = new FileOutputStream(to); IOUtils.copy(is, os); } catch (Exception e) { throw new IllegalStateException("Couldn't copy classpath resource " + from + " to file " + to, e); } finally { try { if (null != is) { is.close(); } if (null != os) { os.close(); } } catch (IOException e) { // eat it } } } }
From source file:org.jboss.tools.openshift.reddeer.utils.FileHelper.java
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDirectory) { if (entry.isDirectory()) { createDirectory(new File(outputDirectory, entry.getName())); return;//www .j a v a2 s .c o m } File outputFile = new File(outputDirectory, entry.getName()); if (!outputFile.getParentFile().exists()) { createDirectory(outputFile.getParentFile()); } BufferedInputStream inputStream = null; BufferedOutputStream outputStream = null; try { inputStream = new BufferedInputStream(zipfile.getInputStream(entry)); outputStream = new BufferedOutputStream(new FileOutputStream(outputFile)); copy(inputStream, outputStream, 1024); } catch (IOException ex) { } finally { try { outputStream.close(); } catch (Exception ex) { } try { inputStream.close(); } catch (Exception ex) { } } outputFile.setExecutable(true); outputFile.setReadable(true); outputFile.setWritable(true); }