List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:dataflow.examples.DockerClientExample.java
public static void main(String[] args) throws IOException, DockerException, InterruptedException { String localTempDir = createLocalTempDir(); String dockerAddress = "unix:///var/run/docker.sock"; String dockerImage = "ubuntu:latest"; DockerClient dockerClient = new DefaultDockerClient(dockerAddress); String localInput = FilenameUtils.concat(localTempDir, "file_on_host.txt"); PrintStream stream = new PrintStream(localInput); stream.append("\nHello from the host machine.\n"); stream.close();//from w w w .j a v a 2 s . co m // Run a simple command in the container to demonstrate we can read the // file mounted from the host. ArrayList<String> command = new ArrayList<String>(); command.add("cat"); command.add("/mounted/file_on_host.txt"); DockerProcessBuilder builder = new DockerProcessBuilder(command, dockerClient); builder.addVolumeMapping(localTempDir, "/mounted"); builder.setImage(dockerImage); // Start and run the container. builder.start(); }
From source file:eu.mrbussy.pdfsplitter.Application.java
/** * Start the main program./*ww w .j ava2s .co m*/ * * @param args * - Arguments passed on to the program */ public static void main(String[] args) { // Read configurations try { String configDirname = FilenameUtils.concat(System.getProperty("user.home"), String.format(".%1$s%2$s", NAME, IOUtils.DIR_SEPARATOR)); String filename = FilenameUtils.concat(configDirname, CONFIGURATION_FILE); // Check to see if the directory exists and the file can be created/opened File configDir = new File(configDirname); if (!configDir.exists()) configDir.mkdir(); // Check to see if the file exists. If not create it File file = new File(filename); if (!file.exists()) { file.createNewFile(); } Configuration = new PropertiesConfiguration(file); // Automatically store the settings that change Configuration.setAutoSave(true); } catch (ConfigurationException | IOException ex) { // Unable to read the file. Probably because it does not exist --> create it. ex.printStackTrace(); } // Set locale to a configured language Locale.setDefault( new Locale(Configuration.getString("language", "nl"), Configuration.getString("country", "NL"))); // Start by parsing the command line ParseCommandline(args); // Display the help if required and leave the app if (arguments.hasOption("h")) { showHelp(); } // Display the app version and leave the app. if (arguments.hasOption("v")) { showVersion(); } // Not command line so start the app GUI if (!arguments.hasOption("c")) { try { // Change the look and feel UIManager.setLookAndFeel( Configuration.getString("LookAndFeel", "com.sun.java.swing.plaf.gtk.GTKLookAndFeel")); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { (new MainWindow()).setVisible(true); } }); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { // Something terrible happened so show the help showHelp(); } } }
From source file:avantssar.aslanpp.testing.Tester.java
public static void main(String[] args) { Debug.initLog(LogLevel.INFO);//from ww w .j a v a 2s. c o m TesterCommandLineOptions options = new TesterCommandLineOptions(); try { options.getParser().parseArgument(args); options.ckeckAtEnd(); } catch (CmdLineException ex) { reportException("Inconsistent options.", ex, System.err); options.showShortHelp(System.err); return; } if (options.isShowHelp()) { options.showLongHelp(System.out); return; } ASLanPPConnectorImpl translator = new ASLanPPConnectorImpl(); if (options.isShowVersion()) { System.out.println(translator.getFullTitleLine()); return; } ISpecificationBundleProvider sbp; File realInDir; if (options.isLibrary()) { if (options.getHornClausesLevel() != HornClausesLevel.ALL) { System.out.println("When checking the internal library we output all Horn clauses."); options.setHornClausesLevel(HornClausesLevel.ALL); } if (!options.isStripOutput()) { System.out.println( "When checking the internal library, the ouput is stripped of comments and line information."); options.setStripOutput(true); } File modelsDir = new File(FilenameUtils.concat(options.getOut().getAbsolutePath(), "_models")); try { FileUtils.forceMkdir(modelsDir); } catch (IOException e1) { System.out.println("Failed to create models folder: " + e1.getMessage()); Debug.logger.error("Failed to create models folder.", e1); } realInDir = modelsDir; sbp = new LibrarySpecificationsProvider(modelsDir.getAbsolutePath()); } else { realInDir = options.getIn(); sbp = new DiskSpecificationsProvider(options.getIn().getAbsolutePath()); } System.setProperty(EntityManager.ASLAN_ENVVAR, sbp.getASLanPath()); // try { // EntityManager.loadASLanPath(); // } // catch (IOException e) { // System.out.println("Exception while reloading ASLANPATH: " + // e.getMessage()); // Debug.logger.error("Exception while loading ASLANPATH.", e); // } try { bm = BackendsManager.instance(); if (bm != null) { for (IBackendRunner br : bm.getBackendRunners()) { System.out.println(br.getFullDescription()); if (br.getTimeout() > finalTimeout) { finalTimeout = br.getTimeout(); } } } } catch (IOException e) { System.out.println("Failed to load backends: " + e); } int threadsCount = 50; if (options.getThreads() > 0) { threadsCount = options.getThreads(); } System.out.println("Will launch " + threadsCount + " threads in parallel (+ will show that a thread starts, - that a thread ends)."); TranslationReport rep = new TranslationReport( bm != null ? bm.getBackendRunners() : new ArrayList<IBackendRunner>(), options.getOut()); long startTime = System.currentTimeMillis(); int specsCount = 0; pool = Executors.newFixedThreadPool(threadsCount); for (ITestTask task : sbp) { doTest(rep, task, realInDir, options.getOut(), translator, options, System.err); specsCount++; } pool.shutdown(); String reportFile = FilenameUtils.concat(options.getOut().getAbsolutePath(), "index.html"); try { while (!pool.awaitTermination(finalTimeout, TimeUnit.SECONDS)) { } } catch (InterruptedException e) { Debug.logger.error("Interrupted while waiting for pool termination.", e); System.out.println("Interrupted while waiting for pool termination: " + e.getMessage()); System.out.println("The report may be incomplete."); } long endTime = System.currentTimeMillis(); long duration = (endTime - startTime) / 1000; System.out.println(); System.out.println(specsCount + " specifications checked in " + duration + " seconds."); rep.report(reportFile); System.out.println("You can find an overview report at '" + reportFile + "'."); }
From source file:cht.Parser.java
public static void main(String[] args) throws IOException { // TODO get from google drive boolean isUnicode = false; boolean isRemoveInputFileOnComplete = false; int rowNum;/*from ww w .ja va2 s . c o m*/ int colNum; Gson gson = new GsonBuilder().setPrettyPrinting().create(); Properties prop = new Properties(); try { prop.load(new FileInputStream("config.txt")); } catch (IOException ex) { ex.printStackTrace(); } String inputFilePath = prop.getProperty("inputFile"); String outputDirectory = prop.getProperty("outputDirectory"); System.out.println(outputDirectory); // optional String unicode = prop.getProperty("unicode"); String removeInputFileOnComplete = prop.getProperty("removeInputFileOnComplete"); inputFilePath = inputFilePath.trim(); outputDirectory = outputDirectory.trim(); if (unicode != null) { isUnicode = Boolean.parseBoolean(unicode.trim()); } if (removeInputFileOnComplete != null) { isRemoveInputFileOnComplete = Boolean.parseBoolean(removeInputFileOnComplete.trim()); } Writer out = null; FileInputStream in = null; final String newLine = System.getProperty("line.separator").toString(); final String separator = File.separator; try { in = new FileInputStream(inputFilePath); Workbook workbook = new XSSFWorkbook(in); Sheet sheet = workbook.getSheetAt(0); rowNum = sheet.getLastRowNum() + 1; colNum = sheet.getRow(0).getPhysicalNumberOfCells(); for (int j = 1; j < colNum; ++j) { String outputFilename = sheet.getRow(0).getCell(j).getStringCellValue(); // guess directory int slash = outputFilename.indexOf('/'); if (slash != -1) { // has directory outputFilename = outputFilename.substring(0, slash) + separator + outputFilename.substring(slash + 1); } String outputPath = FilenameUtils.concat(outputDirectory, outputFilename); System.out.println("--Writing " + outputPath); out = new OutputStreamWriter(new FileOutputStream(outputPath), "UTF-8"); TreeMap<String, Object> map = new TreeMap<String, Object>(); for (int i = 1; i < rowNum; i++) { try { String key = sheet.getRow(i).getCell(0).getStringCellValue(); //String value = ""; Cell tmp = sheet.getRow(i).getCell(j); if (tmp != null) { // not empty string! value = sheet.getRow(i).getCell(j).getStringCellValue(); } if (!key.equals("") && !key.startsWith("#") && !key.startsWith(".")) { value = isUnicode ? StringEscapeUtils.escapeJava(value) : value; int firstdot = key.indexOf("."); String keyName, keyAttribute; if (firstdot > 0) {// a.b.c.d keyName = key.substring(0, firstdot); // a keyAttribute = key.substring(firstdot + 1); // b.c.d TreeMap oldhash = null; Object old = null; if (map.get(keyName) != null) { old = map.get(keyName); if (old instanceof TreeMap == false) { System.out.println("different type of key:" + key); continue; } oldhash = (TreeMap) old; } else { oldhash = new TreeMap(); } int firstdot2 = keyAttribute.indexOf("."); String rootName, childName; if (firstdot2 > 0) {// c, d.f --> d, f rootName = keyAttribute.substring(0, firstdot2); childName = keyAttribute.substring(firstdot2 + 1); } else {// c, d -> d, null rootName = keyAttribute; childName = null; } TreeMap<String, Object> object = myPut(oldhash, rootName, childName); map.put(keyName, object); } else {// c, d -> d, null keyName = key; keyAttribute = null; // simple string mode map.put(key, value); } } } catch (Exception e) { // just ingore empty rows } } String json = gson.toJson(map); // output json out.write(json + newLine); out.close(); } in.close(); System.out.println("\n---Complete!---"); System.out.println("Read input file from " + inputFilePath); System.out.println(colNum - 1 + " output files ate generated at " + outputDirectory); System.out.println(rowNum + " records are generated for each output file."); System.out.println("output file is ecoded as unicode? " + (isUnicode ? "yes" : "no")); if (isRemoveInputFileOnComplete) { File input = new File(inputFilePath); input.deleteOnExit(); System.out.println("Deleted " + inputFilePath); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { in.close(); } } }
From source file:de.sub.goobi.config.DigitalCollections.java
/** * Get possible digital collections for process. * * @param process/*from w w w . j a v a 2s.c om*/ * object * @return list of Strings */ @SuppressWarnings("unchecked") public static List<String> possibleDigitalCollectionsForProcess(Process process) throws JDOMException, IOException { List<String> result = new ArrayList<>(); String filename = FilenameUtils.concat(ConfigCore.getKitodoConfigDirectory(), FileNames.DIGITAL_COLLECTIONS_FILE); if (!(new File(filename).exists())) { throw new FileNotFoundException("File not found: " + filename); } /* Datei einlesen und Root ermitteln */ SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(new File(filename)); Element root = doc.getRootElement(); /* alle Projekte durchlaufen */ List<Element> projekte = root.getChildren(); for (Element project : projekte) { List<Element> projektnamen = project.getChildren("name"); for (Element projectName : projektnamen) { /* * wenn der Projektname aufgefhrt wird, dann alle Digitalen * Collectionen in die Liste */ if (projectName.getText().equalsIgnoreCase(process.getProject().getTitle())) { List<Element> myCols = project.getChildren("DigitalCollection"); for (Element digitalCollection : myCols) { result.add(digitalCollection.getText()); } } } } // If result is empty, get default if (result.size() == 0) { List<Element> children = root.getChildren(); for (Element child : children) { if (child.getName().equals("default")) { List<Element> myCols = child.getChildren("DigitalCollection"); for (Element digitalCollection : myCols) { result.add(digitalCollection.getText()); } } } } return result; }
From source file:es.urjc.mctwp.bbeans.research.SessionUtils.java
public static File getOrCreateFile(String base, String fileName) { String aux = null;/*w w w . j a v a2 s. c o m*/ File auxDir = null; aux = FilenameUtils.concat(base, fileName); auxDir = new File(aux); try { if (!auxDir.exists()) FileUtils.forceMkdir(auxDir); } catch (Exception e) { logger.error("Could not make temp directory for thumbnails: " + e.getMessage()); } return auxDir; }
From source file:com.stratio.crossdata.connector.plugin.installer.InstallerGoalLauncher.java
public static void launchInstallerGoal(InstallerGoalConfig config, Log log) throws IOException { log.info("Create TARGET directory."); File targetDirectory = new File( FilenameUtils.concat(config.getOutputDirectory(), config.getConnectorName())); if (targetDirectory.exists()) { log.info("Remove previous TARGET directory"); FileUtils.forceDelete(targetDirectory); }/*from ww w . j a v a2 s . c o m*/ File includeConfigDirectory = new File(config.getIncludeDirectory()); FileUtils.copyDirectory(includeConfigDirectory, targetDirectory); log.info("Create LIB directory."); File libDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "lib")); FileUtils.copyFileToDirectory(config.getMainJarRepo(), libDirectory); for (File jarFile : config.getDependenciesJarRepo()) { FileUtils.copyFileToDirectory(jarFile, libDirectory); } log.info("Create CONF directory."); File confDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "conf")); File confConfigDirectory = new File(config.getConfigDirectory()); FileUtils.copyDirectory(confConfigDirectory, confDirectory); log.info("Create BIN Directory"); File binDirectory = new File(FilenameUtils.concat(targetDirectory.toString(), "bin")); FileUtils.forceMkdir(binDirectory); log.info("Launch template"); String outputString = (config.getUnixScriptTemplate()); outputString = outputString.replaceAll("<name>", config.getConnectorName()); outputString = outputString.replaceAll("<desc>", config.getDescription()); String user = config.getUserService(); if (config.isUseCallingUserAsService()) { user = System.getProperty("user.name"); } outputString = outputString.replaceAll("<user>", user); outputString = outputString.replaceAll("<mainClass>", config.getMainClass()); int index = config.getMainClass().lastIndexOf('.'); String className = config.getMainClass(); if (index != -1) { className = config.getMainClass().substring(index + 1); } outputString = outputString.replaceAll("<mainClassName>", className); outputString = outputString.replaceAll("<jmxPort>", config.getJmxPort()); String pidFileName = ""; if (config.getPidFileName() != null) { pidFileName = config.getPidFileName(); } outputString = outputString.replaceAll("<pidFileName>", pidFileName); File binFile = new File(FilenameUtils.concat(binDirectory.toString(), config.getConnectorName())); FileUtils.writeStringToFile(binFile, outputString); if (!binFile.setExecutable(true)) { throw new IOException("Can't change executable option."); } log.info("Process complete: " + targetDirectory); }
From source file:com.gigaspaces.httpsession.qa.utils.JettyControllerWithoutLicense.java
@Override public Runner createStarter() { Runner starter = new Runner(Config.getJettyHome(), 10000, Config.getEnvsWithJavaHome()); starter.setWaitForTermination(false); String path = FilenameUtils.concat(Config.getJettyHome(), BIN_START_JAR); List<String> commands = starter.getCommands(); commands.add(Config.getJava7Home() + "/bin/java"); commands.add("-jar"); commands.add(path);//from ww w .ja va2 s . c o m commands.add("-Dcom.gs.licensekey="); commands.add("--module=http"); commands.add("-Djetty.port=" + port); commands.add("-DSTOP.PORT=" + (port - 1)); commands.add("-DSTOP.KEY=secret"); commands.add("-Djetty.home=" + Config.getJettyHome()); starter.or(new StringPredicate( "com.gigaspaces.license.LicenseException: Invalid License [] - This license does not permit GigaSpaces HTTP_SESSION add-on. Please contact support for more details: http://www.gigaspaces.com/supportcenter") { @Override public boolean customTest(String input) { return input.contains(match); } }); return starter; }
From source file:com.redhat.victims.database.VictimsDB.java
/** * Get the default url for a preconfigured driver. * /*from w w w .java2 s . c o m*/ * @return */ public static String defaultURL(String driver) { assert Driver.exists(driver); String home = ""; try { home = VictimsConfig.home().toString(); } catch (VictimsException e) { // Ignore and use cwd } return Driver.url(driver, FilenameUtils.concat(home, "victims")); }
From source file:net.mitnet.tools.pdf.book.io.FileNameHelper.java
public static String rewriteFileNameSuffix(String sourceFileName, String newFileNameExtension) { String pathPath = FilenameUtils.getFullPath(sourceFileName); String baseFileName = FilenameUtils.getBaseName(sourceFileName); String newFileName = baseFileName + newFileNameExtension; String newFile = FilenameUtils.concat(pathPath, newFileName); return newFile; }