List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:edu.cornell.med.icb.goby.modes.ConcatenateCompactReadsMode.java
/** * Actually perform the split of the compact reads file between * start and end position to the new compact reads file. * * @throws java.io.IOException/*from ww w. j ava2 s . c o m*/ */ @Override public void execute() throws IOException { if (inputFiles == null || inputFiles.size() == 0) { throw new IOException("--input not specified"); } if (StringUtils.isBlank(outputFilename)) { throw new IOException("--output not specified"); } if (quickConcat) { performQuickConcat(); } else { final ReadsWriter writer = new ReadsWriterImpl(new FileOutputStream(outputFilename)); writer.setNumEntriesPerChunk(sequencePerChunk); final MutableString sequence = new MutableString(); ReadsReader readsReader = null; numberOfReads = 0; minReadLength = Integer.MAX_VALUE; maxReadLength = Integer.MIN_VALUE; int removedByFilterCount = 0; try { final ProgressLogger progress = new ProgressLogger(); progress.start("concatenating files"); progress.displayFreeMemory = true; progress.expectedUpdates = inputFiles.size(); progress.start(); for (final File inputFile : inputFiles) { readsReader = new ReadsReader(inputFile); String basename = FilenameUtils.removeExtension(inputFile.getPath()); String filterFilename = basename + optionalFilterExtension; File filterFile = new File(filterFilename); ReadSet readIndexFilter = null; if (filterFile.exists() && filterFile.canRead()) { readIndexFilter = new ReadSet(); readIndexFilter.load(filterFile); LOG.info(String.format("Loaded optional filter %s with %d elements. ", filterFile, readIndexFilter.size())); } else { if (optionalFilterExtension != null) { LOG.info("Could not locate filter for filename " + filterFilename); } } for (final Reads.ReadEntry readEntry : readsReader) { // only concatenate if (1) there is no filter or (2) the read index is in the filter. if (readIndexFilter == null || readIndexFilter.contains(readEntry.getReadIndex())) { final Reads.ReadEntry.Builder readEntryBuilder = Reads.ReadEntry.newBuilder(readEntry); readEntryBuilder.setReadIndex(numberOfReads); writer.appendEntry(readEntryBuilder); minReadLength = Math.min(minReadLength, readEntry.getReadLength()); maxReadLength = Math.max(maxReadLength, readEntry.getReadLength()); numberOfReads++; } else { removedByFilterCount++; } } readsReader.close(); readsReader = null; progress.update(); } progress.stop(); } finally { writer.printStats(System.out); System.out.println("Number of reads=" + numberOfReads); System.out.println("Minimum Read Length=" + minReadLength); System.out.println("Maximum Read Length=" + maxReadLength); System.out.println("Reads removed by filter=" + removedByFilterCount); writer.close(); if (readsReader != null) { readsReader.close(); } } } }
From source file:de.uni.bremen.monty.moco.Main.java
private static void writeAssembly(String outputFileName, String inputFileName, String llvmCode) throws IOException { PrintStream assemblyStream = null; if (outputFileName != null) { assemblyStream = new PrintStream(outputFileName); } else if (inputFileName != null) { assemblyStream = new PrintStream(FilenameUtils.removeExtension(inputFileName) + ".ll"); } else {/*from w w w . java 2 s . c o m*/ assemblyStream = new PrintStream("output.ll"); } assemblyStream.print(llvmCode); assemblyStream.close(); }
From source file:com.wx3.galacdecks.Bootstrap.java
private void importPlayValidators(GameDatastore datastore, String path) throws IOException { Files.walk(Paths.get(path)).forEach(filePath -> { if (Files.isRegularFile(filePath)) { try { if (FilenameUtils.getExtension(filePath.getFileName().toString()).toLowerCase().equals("js")) { String id = FilenameUtils.removeExtension(filePath.getFileName().toString()); List<String> lines = Files.readAllLines(filePath); if (lines.size() < 3) { throw new RuntimeException( "Script file should have at least 2 lines: description and code."); }/*from w w w .j a v a 2s . c om*/ String description = lines.get(0).substring(2).trim(); String script = String.join("\n", lines); ValidatorScript validator = ValidatorScript.createValidator(id, script, description); //datastore.createValidator(validator); playValidatorCache.put(id, validator); logger.info("Imported play validator " + id); } } catch (Exception e) { throw new RuntimeException("Failed to parse " + filePath + ": " + e.getMessage()); } } }); }
From source file:com.nohowdezign.gcpmanager.Main.java
public static void dowloadFile(Job job) throws CloudPrintException { SimpleDateFormat sdf = new SimpleDateFormat("MM-dd-yyyy HH-mm-ss"); File directory = new File( "./jobstorage/" + sdf.format(Long.parseLong(job.getCreateTime())) + "/" + job.getOwnerId() + "/"); if (!directory.exists()) { directory.mkdirs();//from w w w . j av a 2 s . co m } String fileName = FilenameUtils.removeExtension(job.getTitle()) + ".pdf"; File outputFile = new File(directory, fileName); if (!outputFile.exists()) { cloudPrint.downloadFile(job.getFileUrl(), outputFile); logger.info("mod date: {}", sdf.format(outputFile.lastModified())); JobStorageManager manager = new JobStorageManager(); manager.addJobFileDownloaded(outputFile); } }
From source file:ch.ifocusit.livingdoc.plugin.publish.HtmlPostProcessor.java
public String getPageTitle(Path path) { String pageContent = null;//from www .j a v a2 s. c o m try { pageContent = IOUtils.readFull(new FileInputStream(path.toFile())); } catch (FileNotFoundException e) { throw new IllegalStateException("Unable to read page title !", e); } try { if (isAdoc(path)) { return getTitle(asciidoctor, pageContent).orElseThrow( () -> new IllegalStateException("top-level heading or title meta information must be set")); } // try to read h1 tag return tagText(pageContent, "h1"); } catch (IllegalStateException e) { return FilenameUtils.removeExtension(path.getFileName().toString()); } }
From source file:io.proleap.vb6.asg.runner.impl.VbParserRunnerImpl.java
protected String getModuleName(final File inputFile) { return StringUtils.capitalize(FilenameUtils.removeExtension(inputFile.getName())); }
From source file:it.isislab.dmason.util.SystemManagement.Worker.thrower.DMasonWorkerWithGui.java
public DMasonWorkerWithGui(boolean start, boolean up, boolean batch, String topic, String ipCS, String portCS) { initComponents();/* w w w . ja v a 2s.c om*/ beaconListener = new BeaconMessageListener(); beaconListener.addObserver(this); new Thread(beaconListener).start(); connection = new ConnectionNFieldsWithActiveMQAPI(); connection.addObserver(this); setDefaultCloseOperation(EXIT_ON_CLOSE); setVisible(true); // Get the path from which worker was started String path; try { path = URLDecoder.decode( DMasonWorkerWithGui.class.getProtectionDomain().getCodeSource().getLocation().getFile(), "UTF-8"); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); path = ""; } logger.debug("Path: " + path); if (path.contains(".jar")) //from jar { File jarfile = new File(path); Digester dg = new Digester(DigestAlgorithm.MD5); try { InputStream in = new FileInputStream(path); digest = dg.getDigest(in); String fileName = FilenameUtils.removeExtension(jarfile.getName()); //save properties to project root folder dg.storeToPropFile(fileName + ".hash"); } catch (IOException ex) { ex.printStackTrace(); } catch (NoDigestFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { // not from jar digest = null; } autoStart = start; updated = up; myTopic = topic; isBatch = batch; ip = ipCS; port = portCS; if (autoStart) connect(); //initSchedule(); }
From source file:de.uzk.hki.da.cb.ConvertAction.java
private void addDAFileToDocument(Object o, DAFile file) { Document doc = o.getDocument(FilenameUtils.removeExtension(file.getRelative_path())); if (doc == null) { throw new IllegalStateException("Cannot add new dafile to document " + FilenameUtils.removeExtension(file.getRelative_path()) + "."); } else {//from w w w . j a va 2s . c o m doc.addDAFile(file); } }
From source file:jease.cms.service.Imports.java
private static Image newImage(String filename, InputStream inputStream) throws IOException { Image image = new Image(); image.setId(Filenames.asId(filename)); image.setTitle(FilenameUtils.removeExtension(filename)); image.setLastModified(new Date()); image.setContentType(MimeTypes.guessContentTypeFromName(filename)); copyStreamToFile(inputStream, image.getFile()); return image; }
From source file:de.uzk.hki.da.format.CLIConversionStrategy.java
/** * Tokenizes commandLine and replaces certain strings. * "input" and "output" get replaced by paths of source and destination file. * strings beginning with "{" and ending with "}" get replaced by the contents of additionalParams of the ConversionInstruction. * Each of the {}-surrounded string gets replaced by exactly one token of additional params. * * @param ci the ci//from ww w . j ava 2 s . c om * @param repName the rep name * @return The processed command as list of tokens. The tokenized string has the right format * for a call in Runtime.getRuntime().exec(commandToExecute). This holds especially true * for filenames (which replace the input/output parameters) that are separated by * whitespaces. "file 2.jpg" is represented as one token only. */ protected String[] assemble(ConversionInstruction ci, String repName) { String commandLine_ = commandLine; // replace additional params List<String> ap = tokenize(ci.getAdditional_params(), ","); for (String s : ap) { Pattern pattern = Pattern.compile("\\{.*?\\}"); Matcher matcher = pattern.matcher(commandLine_); commandLine_ = matcher.replaceFirst(s); } // tokenize before replacement to group original tokens together // (to prevent wrong tokenization like two tokens for "file" "2.jpg" // which can result from replacement) String[] tokenizedCmd = tokenize(commandLine_); String targetSuffix = ci.getConversion_routine().getTarget_suffix(); if (targetSuffix.equals("*")) targetSuffix = FilenameUtils.getExtension(ci.getSource_file().toRegularFile().getAbsolutePath()); Utilities.replace(tokenizedCmd, "input", ci.getSource_file().toRegularFile().getAbsolutePath()); Utilities.replace(tokenizedCmd, "output", object.getDataPath() + "/" + repName + "/" + Utilities.slashize(ci.getTarget_folder()) + FilenameUtils.removeExtension(Matcher.quoteReplacement( FilenameUtils.getName(ci.getSource_file().toRegularFile().getAbsolutePath()))) + "." + targetSuffix); return tokenizedCmd; }