List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:com.arcusys.liferay.vaadinplugin.util.ControlPanelPortletUtil.java
/** * Extracts the jarEntry from the jarFile to the target directory. * * @param jarFile/* ww w . j a va2 s .c o m*/ * @param jarEntry * @param targetDir * @return true if extraction was successful, false otherwise */ public static boolean extractJarEntry(JarFile jarFile, JarEntry jarEntry, String targetDir) { boolean extractSuccessful = false; File file = new File(targetDir); if (!file.exists()) { file.mkdir(); } if (jarEntry != null) { InputStream inputStream = null; try { inputStream = jarFile.getInputStream(jarEntry); file = new File(targetDir + jarEntry.getName()); if (jarEntry.isDirectory()) { file.mkdir(); } else { int size; byte[] buffer = new byte[2048]; FileOutputStream fileOutputStream = new FileOutputStream(file); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream, buffer.length); try { while ((size = inputStream.read(buffer, 0, buffer.length)) != -1) { bufferedOutputStream.write(buffer, 0, size); } bufferedOutputStream.flush(); } finally { bufferedOutputStream.close(); } } extractSuccessful = true; } catch (Exception e) { log.warn(e); } finally { close(inputStream); } } return extractSuccessful; }
From source file:com.wavemaker.StudioInstallService.java
public static File unzipFile(File zipfile) { int BUFFER = 2048; String zipname = zipfile.getName(); int extindex = zipname.lastIndexOf("."); try {/* w w w.ja va 2 s . c o m*/ File zipFolder = new File(zipfile.getParentFile(), zipname.substring(0, extindex)); if (zipFolder.exists()) org.apache.commons.io.FileUtils.deleteDirectory(zipFolder); zipFolder.mkdir(); File currentDir = zipFolder; //File currentDir = zipfile.getParentFile(); BufferedOutputStream dest = null; FileInputStream fis = new FileInputStream(zipfile.toString()); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { System.out.println("Extracting: " + entry); if (entry.isDirectory()) { File f = new File(currentDir, entry.getName()); if (f.exists()) f.delete(); // relevant if this is the top level folder f.mkdir(); } else { int count; byte data[] = new byte[BUFFER]; //needed for non-dir file ace/ace.js created by 7zip File destFile = new File(currentDir, entry.getName()); // write the files to the disk FileOutputStream fos = new FileOutputStream(currentDir.toString() + "/" + entry.getName()); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); } } zis.close(); return currentDir; } catch (Exception e) { e.printStackTrace(); } return (File) null; }
From source file:com.centeractive.ws.builder.DefinitionSaveTest.java
public static File createTempFolder(String name) throws IOException { File tempFolder = File.createTempFile(name, Long.toString(System.nanoTime())); if (!tempFolder.delete()) { throw new RuntimeException("cannot delete tmp file"); }//from w ww . j a v a2 s . c om if (!tempFolder.mkdir()) { throw new RuntimeException("cannot create tmp folder"); } return tempFolder; }
From source file:com.dnielfe.manager.utils.SimpleUtils.java
public static boolean createDir(String path, String name) { File folder = new File(path, name); if (folder.exists()) return false; if (folder.mkdir()) return true; else {/*from ww w .j a v a 2s.c o m*/ try { RootCommands.createRootdir(folder, path); return true; } catch (Exception e) { e.printStackTrace(); } } return false; }
From source file:com.kylinolap.metadata.tool.HiveSourceTableMgmt.java
/** * @param hiveCommd/*from ww w . j a va 2 s.c o m*/ */ private static String callGenerateCommand(String hiveCommd) throws IOException { // Get out put path String tempDir = System.getProperty("java.io.tmpdir"); logger.info("OS current temporary directory is " + tempDir); if (StringUtils.isEmpty(tempDir)) { tempDir = "/tmp"; } String[] cmd = new String[2]; String osName = System.getProperty("os.name"); if (osName.startsWith("Windows")) { cmd[0] = "cmd.exe"; cmd[1] = "/C"; } else { cmd[0] = "/bin/bash"; cmd[1] = "-c"; } // hive command output // String hiveOutputPath = tempDir + File.separator + // "tmp_kylin_output"; String hiveOutputPath = File.createTempFile("HiveOutput", null).getAbsolutePath(); // Metadata output File dir = File.createTempFile("meta", null); dir.delete(); dir.mkdir(); String tableMetaOutcomeDir = dir.getAbsolutePath(); ProcessBuilder pb = null; if (osName.startsWith("Windows")) { pb = new ProcessBuilder(cmd[0], cmd[1], "ssh root@sandbox 'hive -e \"" + hiveCommd + "\"' > " + hiveOutputPath); } else { pb = new ProcessBuilder(cmd[0], cmd[1], "hive -e \"" + hiveCommd + "\" > " + hiveOutputPath); } // Run hive pb.directory(new File(tempDir)); pb.redirectErrorStream(true); Process p = pb.start(); InputStream is = p.getInputStream(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = null; try { br = new BufferedReader(isr); String line = null; logger.info("Execute : " + pb.command().get(0)); while ((line = br.readLine()) != null) { logger.info(line); } } finally { if (null != br) { br.close(); } } logger.info("Hive execution completed!"); HiveSourceTableMgmt rssMgmt = new HiveSourceTableMgmt(); rssMgmt.extractTableDescFromFile(hiveOutputPath, tableMetaOutcomeDir); return tableMetaOutcomeDir; }
From source file:net.mindengine.blogix.BlogixMain.java
@SuppressWarnings("unused") private static void cmd_export(String[] args) throws IOException, URISyntaxException { String dest = "export"; if (args.length > 0) { dest = args[0];/*from www . j a v a 2 s .com*/ } File destinationDir = new File(dest); if (!destinationDir.exists()) { destinationDir.mkdirs(); } BlogixExporter exporter = new BlogixExporter(destinationDir); info("Exporting all routes to \"" + dest + "\""); File publicDir = new File("public"); if (publicDir.exists()) { File publicExportDir = new File(destinationDir.getAbsolutePath() + File.separator + "public"); publicExportDir.mkdir(); FileUtils.copyDirectory(publicDir, publicExportDir); } exporter.exportAll(); }
From source file:com.app.intuit.util.WebUtils.java
/** * @param tenantId//from w w w . j a v a 2 s. com */ public static boolean ensureTenantFolderExists(Long tenantId) { File baseFolder = new File(WebUtils.REPOSITORY_BASE); File tenantFolder = new File(WebUtils.REPOSITORY_BASE + "/tenant_" + tenantId); if (!baseFolder.exists()) { boolean created = baseFolder.mkdir(); if (!created) { LOG.error("Could not create Base folder at : " + baseFolder.getAbsolutePath()); return false; } else { LOG.info("Successfully created Base folder at : " + baseFolder.getAbsolutePath()); } } if (!tenantFolder.exists()) { boolean created = tenantFolder.mkdir(); if (!created) { LOG.error("Could not create Tenant folder at : " + tenantFolder.getAbsolutePath()); return false; } else { LOG.info("Successfully created Tenant folder at : " + tenantFolder.getAbsolutePath()); } } return true; }
From source file:net.przemkovv.sphinx.Utils.java
public static File createRandomTempDirectory(String prefix, String tmp_dir) throws IOException { final File temp; File tmp_dir_file = null;//w w w .jav a2 s. c o m if (tmp_dir != null && !tmp_dir.isEmpty()) { tmp_dir_file = new File(tmp_dir); } temp = File.createTempFile(prefix, null, tmp_dir_file); if (!(temp.delete())) { throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); } if (!(temp.mkdir())) { throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); } return (temp); }
From source file:com.sitewhere.configuration.ConfigurationMigrationSupport.java
/** * Detects whether using old configuration model and upgrades if necessary. * // w w w. j a v a 2s .c o m * @param global * @throws SiteWhereException */ public static void migrateProjectStructureIfNecessary(IGlobalConfigurationResolver global) throws SiteWhereException { File root = new File(global.getConfigurationRoot()); if (!root.exists()) { throw new SiteWhereException("Configuration root does not exist."); } File templateFolder = new File(root, FileSystemTenantConfigurationResolver.DEFAULT_TENANT_TEMPLATE_FOLDER); if (!templateFolder.exists()) { if (!templateFolder.mkdir()) { throw new SiteWhereException("Unable to create template folder."); } for (String filename : OLD_TEMPLATE_FILENAMES) { File templateFile = new File(root, filename); if (templateFile.exists()) { migrateTemplateFile(root, templateFolder, filename); migrateResources(root, templateFolder); break; } } } // Migrate tenant configuration files to separate directories. File tenants = new File(root, FileSystemTenantConfigurationResolver.TENANTS_FOLDER); if (!tenants.exists()) { if (!tenants.mkdir()) { throw new SiteWhereException("Unable to create tenant resources folder."); } } Collection<File> oldConfigs = FileUtils.listFiles(root, FileFilterUtils.suffixFileFilter("-tenant.xml"), null); for (File oldConfig : oldConfigs) { int dash = oldConfig.getName().lastIndexOf('-'); String tenantName = oldConfig.getName().substring(0, dash); File tenantFolder = new File(tenants, tenantName); try { FileUtils.copyDirectory(templateFolder, tenantFolder); File tenantConfig = new File(tenantFolder, FileSystemTenantConfigurationResolver.DEFAULT_TENANT_CONFIGURATION_FILE + "." + FileSystemTenantConfigurationResolver.TENANT_SUFFIX_ACTIVE); if (tenantConfig.exists()) { tenantConfig.delete(); } FileUtils.moveFile(oldConfig, tenantConfig); oldConfig.delete(); } catch (IOException e) { throw new SiteWhereException("Unable to copy template folder for tenant."); } } }
From source file:org.glowroot.tests.WebDriverSetup.java
private static File downloadGeckoDriverIfNeeded() throws IOException { MyDetector detector = new MyDetector(); Properties props = detector.detect(); String osDetectedName = props.getProperty("os.detected.name"); String osDetectedArch = props.getProperty("os.detected.arch"); int bits;/* ww w . j a v a 2 s. c o m*/ if (osDetectedArch.endsWith("_64")) { bits = 64; } else if (osDetectedArch.endsWith("_32")) { bits = 32; } else { throw new IllegalStateException("Unexpected os.detected.arch: " + osDetectedArch); } String optionalExt; String downloadFilenameSuffix; String downloadFilenameExt; Archiver archiver; if (osDetectedName.equals("linux")) { optionalExt = ""; downloadFilenameSuffix = "linux" + bits; downloadFilenameExt = "tar.gz"; archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP); } else if (osDetectedName.equals("osx")) { optionalExt = ""; downloadFilenameSuffix = "macos"; downloadFilenameExt = "tar.gz"; archiver = ArchiverFactory.createArchiver(ArchiveFormat.TAR, CompressionType.GZIP); } else if (osDetectedName.equals("windows")) { optionalExt = ".exe"; downloadFilenameSuffix = "win" + bits; downloadFilenameExt = "zip"; archiver = ArchiverFactory.createArchiver(ArchiveFormat.ZIP); } else { throw new IllegalStateException("Unsupported OS for running geckodriver: " + osDetectedName); } File targetDir = new File("target"); targetDir.mkdir(); File geckoDriverExecutable = new File(targetDir, "geckodriver-" + GECKO_DRIVER_VERSION + optionalExt); if (!geckoDriverExecutable.exists()) { try { downloadAndExtractGeckoDriver(targetDir, downloadFilenameSuffix, downloadFilenameExt, optionalExt, archiver); } catch (EOFException e) { // partial download, try again System.out.println("Retrying..."); downloadAndExtractGeckoDriver(targetDir, downloadFilenameSuffix, downloadFilenameExt, optionalExt, archiver); } } return geckoDriverExecutable; }