List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:de.fhg.iais.asc.xslt.binaries.DownloadAndScale.java
private void addBinaryNodeWithPath(List<Node> result, Node inputNode, Object variant, String subPath, String mimeType) {/*from ww w . jav a 2 s . c om*/ final Element binaryElement = this.targetDoc.createElement("binary"); copyAttributes(inputNode, binaryElement, ATTRNAMES_COPY_TO_RESULT); if (variant instanceof URI) { binaryElement.setAttribute(ATTRNAME_PATH, variant.toString()); } else { String resultPath = this.parameters.get(PARAMNAME_RESULT_PATH); if (StringUtils.isNotEmpty(resultPath)) { binaryElement.setAttribute(PARAMNAME_RESULT_PATH, resultPath); } binaryElement.setAttribute(ATTRNAME_LOCAL_PATHNAME, (String) variant); if (mimeType.startsWith("video/") || mimeType.startsWith("audio/")) { // Todo Test anpassen binaryElement.setAttribute(ATTRNAME_CATEGORY, "full"); } if (!mimeType.equals("video/vimeo")) { String prefix = FilenameUtils.removeExtension((String) variant) .replace(FilenameUtils.removeExtension(subPath), ""); binaryElement.setAttribute(ATTRNAME_PATH, prefix + binaryElement.getAttribute(ATTRNAME_POSITION) + getExtension((String) variant)); if (mimeType.startsWith("image/") || mimeType.equals("application/pdf")) { // ToDo Test anpassen binaryElement.setAttribute(ATTRNAME_CATEGORY, prefix.replace("/", "")); } } else { binaryElement.setAttribute(ATTRNAME_PATH, (String) variant); } } binaryElement.setAttribute(ATTRNAME_MIMETYPE, mimeType); // binaryElement.setAttribute(ATTRNAME_FULL, full); result.add(binaryElement); }
From source file:com.wx3.galacdecks.Bootstrap.java
private void importAiHints(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); String script = String.join("\n", lines); AiHint hint = new AiHint(id, script); //datastore.createAiHint(hint); aiHintCache.put(id, hint); logger.info("Imported hint " + id); }// w w w. ja v a2 s .c o m } catch (Exception e) { throw new RuntimeException("Failed to parse " + filePath + ": " + e.getMessage()); } } }); }
From source file:edu.cornell.med.icb.goby.modes.CompactToFastaMode.java
@Override public void execute() throws IOException { // output file extension is based on the output format type final String outputExtension = "." + outputFormat.name().toLowerCase(Locale.getDefault()); if (outputFilename == null) { outputFilename = FilenameUtils.removeExtension(inputFilename) + (hashOutputFilename ? hash() : "") + outputExtension;/*w w w . j ava2 s . c om*/ } else if (hashOutputFilename) { outputFilename = FilenameUtils.removeExtension(outputFilename) + (hashOutputFilename ? hash() : "") + outputExtension; } ReadSet readIndexFilter = new ReadSet(); if (readIndexFilterFile == null) { readIndexFilter = null; } else { readIndexFilter.load(readIndexFilterFile); } final ProgressLogger progress = new ProgressLogger(); progress.start(); progress.displayFreeMemory = true; // Only sanger and illumina encoding are supported at this time if (qualityEncoding == QualityEncoding.SOLEXA) { throw new UnsupportedOperationException( "SOLEXA encoding is not supported " + "at this time for lack of clear documentation."); } else if (qualityEncoding != QualityEncoding.SANGER && qualityEncoding != QualityEncoding.ILLUMINA) { throw new UnsupportedOperationException("Unknown encoding: " + qualityEncoding); } ReadsReader reader = null; Writer writer = null; OutputStreamWriter pairWriter = null; final int newEntryCharacter; switch (outputFormat) { case FASTQ: newEntryCharacter = '@'; break; case FASTA: default: newEntryCharacter = '>'; break; } try { writer = new OutputStreamWriter(new FastBufferedOutputStream(new FileOutputStream(outputFilename))); pairWriter = processPairs ? new OutputStreamWriter(new FastBufferedOutputStream(new FileOutputStream(outputPairFilename))) : null; final MutableString colorSpaceBuffer = new MutableString(); final MutableString sequence = new MutableString(); final MutableString sequencePair = new MutableString(); if (hasStartOrEndPosition) { reader = new ReadsReader(startPosition, endPosition, inputFilename); } else { reader = new ReadsReader(inputFilename); } for (final Reads.ReadEntry readEntry : reader) { if (readIndexFilter == null || readIndexFilter.contains(readEntry.getReadIndex())) { final String description; if (indexToHeader) { description = Integer.toString(readEntry.getReadIndex()); } else if (identifierToHeader && readEntry.hasReadIdentifier()) { description = readEntry.getReadIdentifier(); } else if (readEntry.hasDescription()) { description = readEntry.getDescription(); } else { description = Integer.toString(readEntry.getReadIndex()); } writer.write(newEntryCharacter); writer.write(description); writer.write('\n'); final boolean processPairInThisRead = processPairs && readEntry.hasSequencePair(); if (processPairInThisRead) { pairWriter.write(newEntryCharacter); pairWriter.write(description); pairWriter.write('\n'); } observeReadIndex(readEntry.getReadIndex()); ReadsReader.decodeSequence(readEntry, sequence); if (processPairInThisRead) { ReadsReader.decodeSequence(readEntry, sequencePair, true); } if (queryLengths != null) { queryLengths.put(readEntry.getReadIndex(), sequence.length()); } MutableString transformedSequence = sequence; MutableString transformedSequencePair = sequencePair; if (outputColorMode) { ColorSpaceConverter.convert(transformedSequence, colorSpaceBuffer, referenceConversion); transformedSequence = colorSpaceBuffer; if (processPairInThisRead) { ColorSpaceConverter.convert(transformedSequencePair, colorSpaceBuffer, referenceConversion); transformedSequencePair = colorSpaceBuffer; } } if (outputFakeNtMode) { for (int i = 0; i < transformedSequence.length(); i++) { transformedSequence.charAt(i, getFakeNtCharacter(transformedSequence.charAt(i))); } if (processPairInThisRead) { for (int i = 0; i < transformedSequencePair.length(); i++) { transformedSequencePair.charAt(i, getFakeNtCharacter(transformedSequencePair.charAt(i))); } } } if (trimAdaptorLength > 0) { transformedSequence = transformedSequence.substring(trimAdaptorLength); if (processPairInThisRead) { transformedSequencePair = transformedSequencePair.substring(trimAdaptorLength); } } // filter unrecognized bases from output if (alphabet != null) { for (int i = 0; i < transformedSequence.length(); i++) { if (alphabet.indexOf(transformedSequence.charAt(i)) == -1) { transformedSequence.charAt(i, 'N'); } } } if (processPairInThisRead) { if (alphabet != null) { for (int i = 0; i < transformedSequencePair.length(); i++) { if (alphabet.indexOf(transformedSequencePair.charAt(i)) == -1) { transformedSequencePair.charAt(i, 'N'); } } } } writeSequence(writer, transformedSequence, fastaLineLength); if (processPairInThisRead) { writeSequence(pairWriter, transformedSequencePair, fastaLineLength); } if (outputFormat == OutputFormat.FASTQ) { final int readLength = transformedSequence.length(); final byte[] qualityScores = readEntry.getQualityScores().toByteArray(); final boolean hasQualityScores = readEntry.hasQualityScores() && !ArrayUtils.isEmpty(qualityScores); writeQualityScores(writer, hasQualityScores, qualityScores, outputFakeQualityMode, readLength); if (processPairInThisRead) { final int readLengthPair = transformedSequencePair.length(); final byte[] qualityScoresPair = readEntry.getQualityScoresPair().toByteArray(); final boolean hasPairQualityScores = readEntry.hasQualityScoresPair() && !ArrayUtils.isEmpty(qualityScoresPair); writeQualityScores(pairWriter, hasPairQualityScores, qualityScoresPair, outputFakeQualityMode, readLengthPair); } } ++numberOfFilteredSequences; progress.lightUpdate(); ++numberOfSequences; } } } finally { IOUtils.closeQuietly(writer); if (processPairs) { IOUtils.closeQuietly(pairWriter); } if (reader != null) { try { reader.close(); } catch (IOException e) { // NOPMD // silently ignore } } } progress.stop(); }
From source file:de.uzk.hki.da.cb.UnpackAction.java
/** * @return/* w w w . j ava 2 s . c o m*/ */ private Map<String, List<File>> generateDocumentsToFilesMap() { Map<String, List<File>> documentsToFiles = new HashMap<String, List<File>>(); Collection<File> files = FileUtils.listFiles(wa.dataPath().toFile(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File file : files) { String document = file.getAbsolutePath().replace(wa.dataPath().toFile().getAbsolutePath(), ""); document = document.substring(1); document = FilenameUtils.removeExtension(document); if (!documentsToFiles.keySet().contains(document)) { List<File> filesList = new ArrayList<File>(); filesList.add(file); documentsToFiles.put(document, filesList); } else { documentsToFiles.get(document).add(file); } } return documentsToFiles; }
From source file:de.mprengemann.intellij.plugin.androidicons.settings.PluginSettings.java
private void scanForMaterialIconsAssets() { int categoriesCount = 0; int assetCount = 0; if (this.selectedMaterialIconsFile != null && this.selectedMaterialIconsFile.getCanonicalPath() != null) { File assetRoot = new File(this.selectedMaterialIconsFile.getCanonicalPath()); final FilenameFilter drawableFileNameFiler = new FilenameFilter() { @Override//from w w w . ja va2 s . c o m public boolean accept(File file, String s) { if (!FilenameUtils.isExtension(s, "png")) { return false; } String filename = FilenameUtils.removeExtension(s); return filename.startsWith("ic_") && filename.endsWith("_black_48dp"); } }; final FilenameFilter folderFileNameFiler = new FilenameFilter() { @Override public boolean accept(File file, String s) { return !s.startsWith(".") && new File(file, s).isDirectory() && !BLACKLISTED_MATERIAL_ICONS_FOLDER.contains(FilenameUtils.removeExtension(s)); } }; File[] categories = assetRoot.listFiles(folderFileNameFiler); if (categories != null) { categoriesCount = categories.length; if (categories.length >= 1) { for (File category : categories) { File[] densities = category.listFiles(folderFileNameFiler); if (densities != null && densities.length >= 1) { File exDensity = densities[0]; File[] assets = exDensity.listFiles(drawableFileNameFiler); assetCount += assets != null ? assets.length : 0; } } } } } materialIconsFoundCategories.setText(categoriesCount + " categories"); materialIconsFoundDrawables.setText(assetCount + " drawables"); }
From source file:de.mprengemann.intellij.plugin.androidicons.dialogs.AndroidBatchScaleImporter.java
private void initRenderers() { final DefaultTableCellRenderer fileCellRenderer = new DefaultTableCellRenderer() { @Override//from w w w . j ava 2 s .c o m protected void setValue(Object o) { File file = (File) o; if (file == null) { setText(""); return; } if (file.isDirectory()) { setText(file.getAbsolutePath()); } else { setText(FilenameUtils.removeExtension(file.getName())); } } }; fileCellRenderer.setHorizontalTextPosition(DefaultTableCellRenderer.TRAILING); table.setDefaultRenderer(File.class, fileCellRenderer); table.setDefaultRenderer(ArrayList.class, new DefaultTableCellRenderer() { @Override protected void setValue(Object o) { if (o == null) { setText(""); } else { ArrayList list = (ArrayList) o; Collections.sort(list); StringBuilder buffer = new StringBuilder(); Iterator iterator = list.iterator(); while (iterator.hasNext()) { Object val = iterator.next(); buffer.append(val.toString()); if (iterator.hasNext()) { buffer.append(", "); } } setText(buffer.toString()); } } }); }
From source file:eu.edisonproject.training.execute.Main.java
private static void calculateTFIDF(String in, String out) throws IOException { File tmpFolder = null;// ww w . jav a2 s. c om try { String contextName = FilenameUtils.removeExtension(in.substring(in.lastIndexOf(File.separator) + 1)); ITFIDFDriver tfidfDriver = new TFIDFDriverImpl(contextName); File inFile = new File(in); String workingFolder = System.getProperty("working.folder"); if (workingFolder == null) { workingFolder = prop.getProperty("working.folder", System.getProperty("java.io.tmpdir")); } tmpFolder = new File(workingFolder + File.separator + System.currentTimeMillis()); tmpFolder.mkdir(); tmpFolder.deleteOnExit(); setTFIDFDriverImplPaths(inFile, tmpFolder); tfidfDriver.executeTFIDF(tmpFolder.getAbsolutePath()); tfidfDriver.driveProcessResizeVector(); File ctxPath = new File(TFIDFDriverImpl.CONTEXT_PATH); for (File f : ctxPath.listFiles()) { if (FilenameUtils.getExtension(f.getName()).endsWith("csv")) { FileUtils.moveFile(f, new File(out + File.separator + f.getName())); } } } finally { if (tmpFolder != null && tmpFolder.exists()) { tmpFolder.delete(); FileUtils.forceDelete(tmpFolder); } } }
From source file:de.fhg.iais.asc.sipmaker.impl.DefaultSipMaker.java
private void addPostprocessingScripts(String scriptsFolder, File sipMakerBaseDir, TransformerListBuilder builder) { File postprocessingFolder = new File(getTransformersDir(sipMakerBaseDir), scriptsFolder); if (!postprocessingFolder.exists()) { throw new AscConfigFailureException("Loading postprocessing scripts failed: Folder '" + postprocessingFolder.getAbsolutePath() + "' does not exist!"); }/*from w w w. j a v a2 s . c om*/ Collection<File> postprocessingScripts = FileUtils.listFiles(postprocessingFolder, new String[] { "xsl" }, true); Iterator<File> scriptIter = postprocessingScripts.iterator(); while (scriptIter.hasNext()) { AbstractTransformer preprocessTransformer = new AscTransformXSLResolver(postprocessingFolder) .createPostprocessingTransformer(FilenameUtils.removeExtension(scriptIter.next().getName())); builder.addTransformer(preprocessTransformer); } }
From source file:com.vvote.verifier.component.votePacking.VotePackingDataStore.java
/** * Load the mixnet output data/*ww w . jav a 2s .c o m*/ * * @throws JSONException * @throws MixDataException * @throws ASN1Exception * @throws JSONIOException */ private void loadMixOutputData() throws JSONException, MixDataException, ASN1Exception, JSONIOException { this.mixOutput = new HashMap<RaceIdentifier, List<List<ECPoint>>>(); final File mixOutputDirectory = new File(this.mixOutputPath); logger.debug("Loading in the mix output data from the folder: {}", mixOutputDirectory); // check whether the provided directory is valid if (!mixOutputDirectory.isDirectory()) { logger.error("The mix output folder must be a directory: {}", mixOutputDirectory); throw new MixDataException("The mix output folder must be a directory: " + mixOutputDirectory); } String jsonFile = null; RaceIdentifier currentIdentifier = null; JSONArray mixOutputArray = null; JSONArray plaintexts = null; List<ECPoint> currentIds = null; List<List<ECPoint>> currentFileIds = null; // loop over each file in the directory for (File file : mixOutputDirectory.listFiles()) { logger.debug("Current file in mix output directory: {}", file.getName()); if (IOUtils.checkExtension(FileType.MIX_OUTPUT, file.getName())) { // get equivalent json filename jsonFile = IOUtils.addExtension(FilenameUtils.removeExtension(file.getPath()), FileType.JSON); // convert from asn.1 to json format ASN1ToJSONConverter.asn1ToJSON(file.getPath(), jsonFile, FileType.MIX_OUTPUT); // get current identifier currentIdentifier = Utils.getRaceIdentifierFromFileName(jsonFile, this.hasRaceMap); mixOutputArray = IOUtils.readJSONArrayFromFile(jsonFile); currentFileIds = new ArrayList<List<ECPoint>>(); // loop over each ballot for (int i = 0; i < mixOutputArray.length(); i++) { currentIds = new ArrayList<ECPoint>(); plaintexts = mixOutputArray.getJSONArray(i); // loop over each plaintext for (int j = 0; j < plaintexts.length(); j++) { currentIds.add(ECUtils.constructECPointFromJSON(plaintexts.getJSONObject(j))); } currentFileIds.add(currentIds); } this.mixOutput.put(currentIdentifier, currentFileIds); } } logger.debug("Successfully loaded mixnet output data"); }
From source file:de.mprengemann.intellij.plugin.androidicons.forms.MaterialIconsImporter.java
private void fillSizes() { final String lastSelectedSize = this.lastSelectedSize; sizeSpinner.removeAllItems();//w w w . j av a2 s .co m if (this.assetRoot.getCanonicalPath() == null) { return; } File assetRoot = new File(this.assetRoot.getCanonicalPath()); assetRoot = new File(assetRoot, (String) categorySpinner.getSelectedItem()); assetRoot = new File(assetRoot, DEFAULT_RESOLUTION); final String assetName = (String) assetSpinner.getSelectedItem(); final FilenameFilter drawableFileNameFiler = new FilenameFilter() { @Override public boolean accept(File file, String s) { if (!FilenameUtils.isExtension(s, "png")) { return false; } String filename = FilenameUtils.removeExtension(s); return filename.startsWith("ic_" + assetName + "_"); } }; File[] assets = assetRoot.listFiles(drawableFileNameFiler); Set<String> sizes = new HashSet<String>(); for (File asset : assets) { String drawableName = FilenameUtils.removeExtension(asset.getName()); String[] numbers = drawableName.replaceAll("[^-?0-9]+", " ").trim().split(" "); drawableName = numbers[numbers.length - 1].trim() + "dp"; sizes.add(drawableName); } List<String> list = new ArrayList<String>(); list.addAll(sizes); Collections.sort(list); for (String size : list) { sizeSpinner.addItem(size); } if (list.contains(lastSelectedSize)) { sizeSpinner.setSelectedIndex(list.indexOf(lastSelectedSize)); } }