List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:com.nridge.ds.neo4j.ds_neo4j.Neo4jGDB.java
public static GraphDatabaseService getInstance(final AppMgr anAppMgr, DataBag aSchemaBag) throws DSException { if (mGraphDBService == null) { Label graphDBLabel = null; if (aSchemaBag != null) { String labelName = aSchemaBag.getFeature("labelName"); if (StringUtils.isNotEmpty(labelName)) graphDBLabel = Label.label(labelName); }/*from w w w.j av a2 s . co m*/ String graphDBPathName = anAppMgr.getString(anAppMgr.APP_PROPERTY_GDB_PATH); String graphDBSchemaPathFileName = String.format("%s%cschema", graphDBPathName, File.separatorChar); File graphDBSchemaFile = new File(graphDBSchemaPathFileName); boolean gdbSchemaExists = graphDBSchemaFile.exists(); // Ensure we have a graph database folder for data storage. File graphDBPathFile = new File(graphDBPathName); if (!graphDBPathFile.exists()) graphDBPathFile.mkdir(); if (!graphDBPathFile.exists()) { String msgStr = String.format("%s: Does not exist.", graphDBPathName); throw new DSException(msgStr); } // Prevent a large number of log messages from being generated. LogProvider logProvider = new Slf4jLogProvider(); // Enter the critical section to create the service handle. synchronized (Neo4jGDB.class) { if (mGraphDBService == null) { mGraphDBService = new GraphDatabaseFactory().setUserLogProvider(logProvider) .newEmbeddedDatabaseBuilder(new File(graphDBPathName)).newGraphDatabase(); if ((aSchemaBag != null) && (!gdbSchemaExists)) { DataField pkField = aSchemaBag.getPrimaryKeyField(); if (pkField != null) { Schema gdbSchema; IndexDefinition indexDefinition = null; try (Transaction gdbTransaction = mGraphDBService.beginTx()) { gdbSchema = mGraphDBService.schema(); for (DataField dataField : aSchemaBag.getFields()) { if (dataField != pkField) { if (dataField.isFeatureTrue("isIndexed")) gdbSchema.indexFor(graphDBLabel).on(dataField.getName()).create(); } } indexDefinition = gdbSchema.indexFor(graphDBLabel).on(pkField.getName()).create(); gdbTransaction.success(); } if (indexDefinition != null) { try (Transaction gdbTransaction = mGraphDBService.beginTx()) { gdbSchema.awaitIndexOnline(indexDefinition, 10, TimeUnit.SECONDS); gdbTransaction.success(); } } } } } } } return mGraphDBService; }
From source file:com.pieframework.runtime.utils.Zipper.java
public static void unzip(String zipFile, String toDir) throws ZipException, IOException { int BUFFER = 2048; File file = new File(zipFile); ZipFile zip = new ZipFile(file); String newPath = toDir;//from w ww . j av a 2s . co m File toDirectory = new File(newPath); if (!toDirectory.exists()) { toDirectory.mkdir(); } Enumeration zipFileEntries = zip.entries(); // Process each entry while (zipFileEntries.hasMoreElements()) { // grab a zip file entry ZipEntry entry = (ZipEntry) zipFileEntries.nextElement(); String currentEntry = entry.getName(); File destFile = new File(newPath, FilenameUtils.separatorsToSystem(currentEntry)); //System.out.println(currentEntry); File destinationParent = destFile.getParentFile(); // create the parent directory structure if needed destinationParent.mkdirs(); if (!entry.isDirectory()) { BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry)); int currentByte; // establish buffer for writing file byte data[] = new byte[BUFFER]; // write the current file to disk FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); // read and write until last byte is encountered while ((currentByte = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, currentByte); } dest.flush(); dest.close(); is.close(); } } zip.close(); }
From source file:de.flapdoodle.embedmongo.Files.java
public static File createOrCheckUserDir(String prefix) throws IOException { File tempDir = new File(System.getProperty("user.home")); File tempFile = new File(tempDir, prefix); if ((tempFile.exists()) && (tempFile.isDirectory())) return tempFile; if (!tempFile.mkdir()) throw new IOException("Could not create Tempdir: " + tempFile); return tempFile; }
From source file:Main.java
static boolean copyFiles(File sourceLocation, File targetLocation) throws IOException { if (sourceLocation.equals(targetLocation)) return false; if (sourceLocation.isDirectory()) { if (!targetLocation.exists()) { targetLocation.mkdir(); }//w w w. j a v a 2 s . c o m String[] children = sourceLocation.list(); for (int i = 0; i < children.length; i++) { copyFiles(new File(sourceLocation, children[i]), new File(targetLocation, children[i])); } } else if (sourceLocation.exists()) { InputStream in = new FileInputStream(sourceLocation); OutputStream out = new FileOutputStream(targetLocation); // Copy the bits from instream to outstream byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } return true; }
From source file:com.openkm.applet.Util.java
/** * Creates a temporal and unique directory * /* w w w.j a va 2 s. c o m*/ * @throws IOException If something fails. */ public static File createTempDir() throws IOException { File tmpFile = File.createTempFile("okm", null); if (!tmpFile.delete()) throw new IOException(); if (!tmpFile.mkdir()) throw new IOException(); return tmpFile; }
From source file:org.mythtv.client.MainApplication.java
private static void initImageLoader(Context context) { File cacheDir = new File(context.getCacheDir(), "images"); if (!cacheDir.exists()) { cacheDir.mkdir(); }/*from w w w . j av a 2s . c o m*/ // This configuration tuning is custom. You can tune every option, you may tune some of them, // or you can create default configuration by // ImageLoaderConfiguration.createDefault(this); // method. ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context).threadPoolSize(5) .threadPriority(Thread.MIN_PRIORITY + 3).denyCacheImageMultipleSizesInMemory() .memoryCache(new WeakMemoryCache()).discCache(new UnlimitedDiscCache(cacheDir)).build(); // Initialize ImageLoader with configuration. ImageLoader.getInstance().init(config); L.disableLogging(); }
From source file:com.mbrlabs.mundus.utils.Log.java
private static void prepareLogFile() { File logDirectory = new File(Registry.LOGS_DIR); logDirectory.mkdir(); SimpleDateFormat fileDateFormat = new SimpleDateFormat("yy-MM-dd"); String fileName = fileDateFormat.format(new Date()); fileName = "mundus " + fileName + ".log"; try {//w w w. j av a 2s. c o m logFile = new File(logDirectory, fileName); logFile.createNewFile(); logFileWriter = new PrintWriter(new FileWriter(logFile, true)); } catch (IOException e) { exception(TAG, e); } logFileWriter.println(); info(TAG, "Logging activated. Log file [{}] created. ", fileName); }
From source file:com.rukiasoft.androidapps.comunioelpuntal.crashlogs.ExceptionHandler.java
public static String[] searchForStackTraces() { if (stackTraceFileList != null) { return stackTraceFileList; }//ww w .jav a2 s.c o m File dir = new File(G.FILES_PATH + "/"); // Try to create the files folder if it doesn't exist dir.mkdir(); // Filter for ".stacktrace" files FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".stacktrace"); } }; return (stackTraceFileList = dir.list(filter)); }
From source file:net.fabricmc.installer.installer.MultiMCInstaller.java
public static void install(File mcDir, String version, IInstallerProgress progress) throws Exception { File instancesDir = new File(mcDir, "instances"); if (!instancesDir.exists()) { throw new FileNotFoundException(Translator.getString("install.multimc.notFound")); }/*from www . j av a 2 s. co m*/ progress.updateProgress(Translator.getString("install.multimc.findInstances"), 10); String mcVer = version.split("-")[0]; List<File> validInstances = new ArrayList<>(); for (File instanceDir : instancesDir.listFiles()) { if (instanceDir.isDirectory()) { if (isValidInstance(instanceDir, mcVer)) { validInstances.add(instanceDir); } } } if (validInstances.isEmpty()) { throw new Exception(Translator.getString("install.multimc.noInstances").replace("[MCVER]", mcVer)); } List<String> instanceNames = new ArrayList<>(); for (File instance : validInstances) { instanceNames.add(instance.getName()); } String instanceName = (String) JOptionPane.showInputDialog(null, Translator.getString("install.multimc.selectInstance"), Translator.getString("install.multimc.selectInstance"), JOptionPane.QUESTION_MESSAGE, null, instanceNames.toArray(), instanceNames.get(0)); if (instanceName == null) { progress.updateProgress(Translator.getString("install.multimc.canceled"), 100); return; } progress.updateProgress( Translator.getString("install.multimc.installingInto").replace("[NAME]", instanceName), 25); File instnaceDir = null; for (File instance : validInstances) { if (instance.getName().equals(instanceName)) { instnaceDir = instance; } } if (instnaceDir == null) { throw new FileNotFoundException("Could not find " + instanceName); } File patchesDir = new File(instnaceDir, "patches"); if (!patchesDir.exists()) { patchesDir.mkdir(); } File fabricJar = new File(patchesDir, "Fabric-" + version + ".jar"); if (!fabricJar.exists()) { progress.updateProgress(Translator.getString("install.client.downloadFabric"), 30); FileUtils.copyURLToFile(new URL("http://maven.modmuss50.me/net/fabricmc/fabric-base/" + version + "/fabric-base-" + version + ".jar"), fabricJar); } progress.updateProgress(Translator.getString("install.multimc.createJson"), 70); File fabricJson = new File(patchesDir, "fabric.json"); if (fabricJson.exists()) { fabricJson.delete(); } String json = readBaseJson(); json = json.replaceAll("%VERSION%", version); ZipFile fabricZip = new ZipFile(fabricJar); ZipEntry dependenciesEntry = fabricZip.getEntry("dependencies.json"); String fabricDeps = IOUtils.toString(fabricZip.getInputStream(dependenciesEntry), Charset.defaultCharset()); json = json.replace("%DEPS%", stripDepsJson(fabricDeps.replace("\n", ""))); FileUtils.writeStringToFile(fabricJson, json, Charset.defaultCharset()); fabricZip.close(); progress.updateProgress(Translator.getString("install.success"), 100); }
From source file:it.geosolutions.geofence.gui.server.utility.IoUtility.java
/** * Creates the today directory./*w ww. j a v a 2 s .c o m*/ * * @param destDir * the dest dir * @param inputFileName * the input file name * @param withTime * the with time * @return the file */ public static final File createTodayDirectory(File destDir, String inputFileName, final boolean withTime) { final SimpleDateFormat SDF = withTime ? new SimpleDateFormat("yyyy_MM_dd_hhmmsss") : new SimpleDateFormat("yyyy_MM_dd"); final String newPath = (new StringBuffer(destDir.getAbsolutePath().trim()).append(File.separatorChar) .append(SDF.format(new Date())).append("_").append(inputFileName)).toString(); File dir = new File(newPath); if (!dir.exists()) { dir.mkdir(); } return dir; }