List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:edu.cuhk.hccl.IDConverter.java
public static void main(String[] args) { if (args.length < 2) { printUsage();// w ww . j a v a2 s . c o m } try { File inFile = new File(args[0]); File outFile = new File(args[1]); if (inFile.isDirectory()) { System.out.println("ID Converting begins..."); FileUtils.forceMkdir(outFile); for (File file : inFile.listFiles()) { if (!file.isHidden()) processFile(file, new File(outFile.getAbsolutePath() + "/" + FilenameUtils.removeExtension(file.getName()) + "-long.txt")); } } else if (inFile.isFile()) { System.out.println("ID Converting begins..."); processFile(inFile, outFile); } else { printUsage(); } System.out.println("ID Converting finished."); } catch (IOException e) { e.printStackTrace(); } }
From source file:edu.cornell.med.icb.goby.util.RenameWeights.java
public static void main(final String[] args) throws IOException { final File directory = new File("."); final String[] list = directory.list(new FilenameFilter() { public boolean accept(final File directory, final String filename) { final String extension = FilenameUtils.getExtension(filename); return (extension.equals("entries")); }/* w w w. j a va 2 s. c om*/ }); for (final String filename : args) { final String extension = FilenameUtils.getExtension(filename); final String basename = FilenameUtils.removeExtension(filename); for (final String alignFilename : list) { final String alignBasename = FilenameUtils.removeExtension(alignFilename); if (alignBasename.endsWith(basename)) { System.out.println("move " + filename + " to " + alignBasename + "." + extension); final File destination = new File(alignBasename + "." + extension); FileUtils.deleteQuietly(destination); FileUtils.moveFile(new File(filename), destination); } } } }
From source file:mjc.ARMMain.java
public static void main(String[] args) { for (String arg : args) { if (!arg.startsWith("-")) { // ignore flags try { File in = new File(arg); File out = new File(FilenameUtils.removeExtension(in.getName()) + ".s"); compile(new FileInputStream(in), new PrintStream(out)); } catch (FileNotFoundException e) { System.err.println("Error: " + e.getMessage()); System.exit(1);/*from ww w . j ava2s . c om*/ } catch (Throwable t) { System.err.println("Could not compile: " + t.getMessage()); System.exit(1); } } } // All went well, exit with status 0. System.exit(0); }
From source file:com.cohesionforce.AvroToParquet.java
public static void main(String[] args) { String inputFile = null;// ww w . j a v a 2 s .c om String outputFile = null; HelpFormatter formatter = new HelpFormatter(); // create Options object Options options = new Options(); // add t option options.addOption("i", true, "input avro file"); options.addOption("o", true, "ouptut Parquet file"); CommandLineParser parser = new DefaultParser(); CommandLine cmd; try { cmd = parser.parse(options, args); inputFile = cmd.getOptionValue("i"); if (inputFile == null) { formatter.printHelp("AvroToParquet", options); return; } outputFile = cmd.getOptionValue("o"); } catch (ParseException exc) { System.err.println("Problem with command line parameters: " + exc.getMessage()); return; } File avroFile = new File(inputFile); if (!avroFile.exists()) { System.err.println("Could not open file: " + inputFile); return; } try { DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>(); DataFileReader<GenericRecord> dataFileReader; dataFileReader = new DataFileReader<GenericRecord>(avroFile, datumReader); Schema avroSchema = dataFileReader.getSchema(); // choose compression scheme CompressionCodecName compressionCodecName = CompressionCodecName.SNAPPY; // set Parquet file block size and page size values int blockSize = 256 * 1024 * 1024; int pageSize = 64 * 1024; String base = FilenameUtils.removeExtension(avroFile.getAbsolutePath()) + ".parquet"; if (outputFile != null) { File file = new File(outputFile); base = file.getAbsolutePath(); } Path outputPath = new Path("file:///" + base); // the ParquetWriter object that will consume Avro GenericRecords ParquetWriter<GenericRecord> parquetWriter; parquetWriter = new AvroParquetWriter<GenericRecord>(outputPath, avroSchema, compressionCodecName, blockSize, pageSize); for (GenericRecord record : dataFileReader) { parquetWriter.write(record); } dataFileReader.close(); parquetWriter.close(); } catch (IOException e) { System.err.println("Caught exception: " + e.getMessage()); } }
From source file:marytts.signalproc.effects.VocalTractLinearScalerEffect.java
/** * Command line interface to the vocal tract linear scaler effect. * /*w w w . jav a2 s. c o m*/ * @param args the command line arguments. Exactly two arguments are expected: * (1) the factor by which to scale the vocal tract (between 0.25 = very long and 4.0 = very short vocal tract); * (2) the filename of the wav file to modify. * Will produce a file basename_factor.wav, where basename is the filename without the extension. * @throws Exception if processing fails for some reason. */ public static void main(String[] args) throws Exception { if (args.length != 2) { System.err.println( "Usage: java " + VocalTractLinearScalerEffect.class.getName() + " <factor> <filename>"); System.exit(1); } float factor = Float.parseFloat(args[0]); String filename = args[1]; AudioDoubleDataSource input = new AudioDoubleDataSource( AudioSystem.getAudioInputStream(new File(filename))); AudioFormat format = input.getAudioFormat(); VocalTractLinearScalerEffect effect = new VocalTractLinearScalerEffect((int) format.getSampleRate()); DoubleDataSource output = effect.apply(input, "amount:" + factor); DDSAudioInputStream audioOut = new DDSAudioInputStream(output, format); String outFilename = FilenameUtils.removeExtension(filename) + "_" + factor + ".wav"; AudioSystem.write(audioOut, AudioFileFormat.Type.WAVE, new File(outFilename)); System.out.println("Created file " + outFilename); }
From source file:net.openbyte.Launch.java
/** * This is the main method that allows Java to initiate the program. * * @param args the arguments to the Java program, which are ignored *//*from w w w. ja v a 2s .c o m*/ public static void main(String[] args) { logger.info("Checking for a new version..."); try { GitHub gitHub = new GitHubBuilder().withOAuthToken("e5b60cea047a3e44d4fc83adb86ea35bda131744 ").build(); GHRepository repository = gitHub.getUser("PizzaCrust").getRepository("OpenByte"); for (GHRelease release : repository.listReleases()) { double releaseTag = Double.parseDouble(release.getTagName()); if (CURRENT_VERSION < releaseTag) { logger.info("Version " + releaseTag + " has been released."); JOptionPane.showMessageDialog(null, "Please update OpenByte to " + releaseTag + " at https://github.com/PizzaCrust/OpenByte.", "Update", JOptionPane.WARNING_MESSAGE); } else { logger.info("OpenByte is at the latest version."); } } } catch (Exception e) { logger.error("Failed to connect to GitHub."); e.printStackTrace(); } logger.info("Checking for a workspace folder..."); if (!Files.WORKSPACE_DIRECTORY.exists()) { logger.info("Workspace directory not found, creating one."); Files.WORKSPACE_DIRECTORY.mkdir(); } logger.info("Checking for a plugins folder..."); if (!Files.PLUGINS_DIRECTORY.exists()) { logger.info("Plugins directory not found, creating one."); Files.PLUGINS_DIRECTORY.mkdir(); } try { logger.info("Grabbing and applying system look and feel..."); UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { logger.info("Something went wrong when applying the look and feel, using the default one..."); e.printStackTrace(); } logger.info("Starting event manager..."); EventManager.init(); logger.info("Detecting plugin files..."); File[] pluginFiles = PluginManager.getPluginFiles(Files.PLUGINS_DIRECTORY); logger.info("Detected " + pluginFiles.length + " plugin files in the plugins directory!"); logger.info("Beginning load/register plugin process..."); for (File pluginFile : pluginFiles) { logger.info("Loading file " + FilenameUtils.removeExtension(pluginFile.getName()) + "..."); try { PluginManager.registerAndLoadPlugin(pluginFile); } catch (Exception e) { logger.error("Failed to load file " + FilenameUtils.removeExtension(pluginFile.getName()) + "!"); e.printStackTrace(); } } logger.info("All plugin files were loaded/registered to OpenByte."); logger.info("Showing graphical interface to user..."); WelcomeFrame welcomeFrame = new WelcomeFrame(); welcomeFrame.setVisible(true); }
From source file:Inmemantlr.java
public static void main(String[] args) { LOGGER.info("Inmemantlr tool"); HelpFormatter hformatter = new HelpFormatter(); Options options = new Options(); // Binary arguments options.addOption("h", "print this message"); Option grmr = Option.builder().longOpt("grmrfiles").hasArgs().desc("comma-separated list of ANTLR files") .required(true).argName("grmrfiles").type(String.class).valueSeparator(',').build(); Option infiles = Option.builder().longOpt("infiles").hasArgs() .desc("comma-separated list of files to parse").required(true).argName("infiles").type(String.class) .valueSeparator(',').build(); Option utilfiles = Option.builder().longOpt("utilfiles").hasArgs() .desc("comma-separated list of utility files to be added for " + "compilation").required(false) .argName("utilfiles").type(String.class).valueSeparator(',').build(); Option odir = Option.builder().longOpt("outdir") .desc("output directory in which the dot files will be " + "created").required(false).hasArg(true) .argName("outdir").type(String.class).build(); options.addOption(infiles);/* w w w . ja v a2 s .c om*/ options.addOption(grmr); options.addOption(utilfiles); options.addOption(odir); CommandLineParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); if (cmd.hasOption('h')) { hformatter.printHelp("java -jar inmemantlr.jar", options); System.exit(0); } } catch (ParseException e) { hformatter.printHelp("java -jar inmemantlr.jar", options); LOGGER.error(e.getMessage()); System.exit(-1); } // input files Set<File> ins = getFilesForOption(cmd, "infiles"); // grammar files Set<File> gs = getFilesForOption(cmd, "grmrfiles"); // utility files Set<File> uf = getFilesForOption(cmd, "utilfiles"); // output dir Set<File> od = getFilesForOption(cmd, "outdir"); if (od.size() > 1) { LOGGER.error("output directories must be less than or equal to 1"); System.exit(-1); } if (ins.size() <= 0) { LOGGER.error("no input files were specified"); System.exit(-1); } if (gs.size() <= 0) { LOGGER.error("no grammar files were specified"); System.exit(-1); } LOGGER.info("create generic parser"); GenericParser gp = null; try { gp = new GenericParser(gs.toArray(new File[gs.size()])); } catch (FileNotFoundException e) { LOGGER.error(e.getMessage()); System.exit(-1); } if (!uf.isEmpty()) { try { gp.addUtilityJavaFiles(uf.toArray(new String[uf.size()])); } catch (FileNotFoundException e) { LOGGER.error(e.getMessage()); System.exit(-1); } } LOGGER.info("create and add parse tree listener"); DefaultTreeListener dt = new DefaultTreeListener(); gp.setListener(dt); LOGGER.info("compile generic parser"); try { gp.compile(); } catch (CompilationException e) { LOGGER.error("cannot compile generic parser: {}", e.getMessage()); System.exit(-1); } String fpfx = ""; for (File of : od) { if (!of.exists() || !of.isDirectory()) { LOGGER.error("output directory does not exist or is not a " + "directory"); System.exit(-1); } fpfx = of.getAbsolutePath(); } Ast ast; for (File f : ins) { try { gp.parse(f); } catch (IllegalWorkflowException | FileNotFoundException e) { LOGGER.error(e.getMessage()); System.exit(-1); } ast = dt.getAst(); if (!fpfx.isEmpty()) { String of = fpfx + "/" + FilenameUtils.removeExtension(f.getName()) + ".dot"; LOGGER.info("write file {}", of); try { FileUtils.writeStringToFile(new File(of), ast.toDot(), "UTF-8"); } catch (IOException e) { LOGGER.error(e.getMessage()); System.exit(-1); } } else { LOGGER.info("Tree for {} \n {}", f.getName(), ast.toDot()); } } System.exit(0); }
From source file:andrew.addons.NextFile.java
public static String nextFile(String filename) { int a = 1;/* w w w .j a v a 2 s . c o m*/ File file = new File(filename); while (file.exists() || file.isFile()) { file = new File(FilenameUtils.removeExtension(filename) + "(" + Integer.toString(a) + ")." + FilenameUtils.getExtension(filename)); a++; } return file.getName(); }
From source file:andrew.addons.NextFile.java
public static String findExt(String folder, String file) { File dir = new File(folder); File[] list = dir.listFiles(); if (list != null) { for (File fil : list) { if (file.equals(FilenameUtils.removeExtension(fil.getName()))) return fil.getName(); }//from ww w .j av a 2 s. co m } return ""; }
From source file:de.mprengemann.intellij.plugin.androidicons.util.ExportNameUtils.java
public static String getExportNameFromFilename(String filename) { String exportName = FilenameUtils.removeExtension(filename); if (exportName.matches("[a-z0-9_.]*")) { return exportName; }//from w ww.j a va2 s . c om exportName = exportName.toLowerCase(); return exportName.replaceAll("([^(a-z0-9_.)])", "_"); }