/** * Gets the base name, minus the full path and extension, from a full filename. * <p> * This method will handle a file in either Unix or Windows format. * The text after the last forward or backslash and before the last dot is returned. * <pre> * a/b/c.txt --> c * a.txt --> a * a/b/c --> c * a/b/c/ --> "" * </pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to query, null returns null * @return the name of the file without the path, or an empty string if none exists. Null bytes inside string * will be removed */ public static String getBaseName(final String filename) { return removeExtension(getName(filename)); }
/** * Gets the base name, minus the full path and extension, from a full filename. * <p> * This method will handle a file in either Unix or Windows format. * The text after the last forward or backslash and before the last dot is returned. * <pre> * a/b/c.txt --> c * a.txt --> a * a/b/c --> c * a/b/c/ --> "" * </pre> * <p> * The output will be the same irrespective of the machine that the code is running on. * * @param filename the filename to query, null returns null * @return the name of the file without the path, or an empty string if none exists */ public static String getBaseName(String filename) { return removeExtension(getName(filename)); }
@Test public void testRemoveExtension() { assertEquals(null, FilenameUtils.removeExtension(null)); assertEquals("file", FilenameUtils.removeExtension("file.ext")); assertEquals("README", FilenameUtils.removeExtension("README")); assertEquals("domain.dot", FilenameUtils.removeExtension("domain.dot.com")); assertEquals("image", FilenameUtils.removeExtension("image.jpeg")); assertEquals("a.b/c", FilenameUtils.removeExtension("a.b/c")); assertEquals("a.b/c", FilenameUtils.removeExtension("a.b/c.txt")); assertEquals("a/b/c", FilenameUtils.removeExtension("a/b/c")); assertEquals("a.b\\c", FilenameUtils.removeExtension("a.b\\c")); assertEquals("a.b\\c", FilenameUtils.removeExtension("a.b\\c.txt")); assertEquals("a\\b\\c", FilenameUtils.removeExtension("a\\b\\c")); assertEquals("C:\\temp\\foo.bar\\README", FilenameUtils.removeExtension("C:\\temp\\foo.bar\\README")); assertEquals("../filename", FilenameUtils.removeExtension("../filename.ext")); }
destFileName = FilenameUtils.removeExtension(destFileName) + "-" + sha + FilenameUtils.EXTENSION_SEPARATOR + FilenameUtils.getExtension(destFileName);
destFileName = FilenameUtils.removeExtension(destFileName) + "-" + sha + FilenameUtils.EXTENSION_SEPARATOR + FilenameUtils.getExtension(destFileName);
destFileName = FilenameUtils.removeExtension(destFileName) + "-" + sha + FilenameUtils.EXTENSION_SEPARATOR + FilenameUtils.getExtension(destFileName);
destFileName = FilenameUtils.removeExtension(destFileName) + "-" + sha + FilenameUtils.EXTENSION_SEPARATOR + FilenameUtils.getExtension(destFileName);
public SerializedFileReader(Path file) throws IOException { String fileName = file.getFileName().toString(); String fileExt = FilenameUtils.getExtension(fileName); // load audio buffer if existing readResourceStream(file.resolveSibling(fileName + ".streamingResourceImage")); readResourceStream(file.resolveSibling(fileName + ".resS")); // join split serialized files before loading if (fileExt.startsWith("split")) { L.fine("Found split serialized file"); fileName = FilenameUtils.removeExtension(fileName); List<Path> parts = new ArrayList<>(); int splitIndex = 0; // collect all files with .split0 to .splitN extension while (true) { String splitName = String.format("%s.split%d", fileName, splitIndex); Path part = file.resolveSibling(splitName); if (Files.notExists(part)) { break; } L.log(Level.FINE, "Adding splinter {0}", part.getFileName()); splitIndex++; parts.add(part); } // load all parts to one byte buffer in = DataReaders.forByteBuffer(ByteBufferUtils.load(parts)); } else { in = DataReaders.forFile(file, READ); } }
/** * Command line interface to the vocal tract linear scaler effect. * * @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); } }
/** * Command line interface to the vocal tract linear scaler effect. * * @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); } }
final String fileName = FilenameUtils.removeExtension(f.getName()); final String ext = FilenameUtils.getExtension(f.getName()); if (!IGNORED_FILES.accept(f) && !"js".equals(ext)) {
pomProperties = retrievePomProperties(path, jar); } else { path = FilenameUtils.removeExtension(dependency.getActualFilePath()) + ".pom"; pomFile = new File(path);
private String getName(String application) { return removeExtension(FilenameUtils.getName(application)); }
public static String getExportNameFromFilename(String filename) { String exportName = FilenameUtils.removeExtension(filename); if (exportName.matches("[a-z0-9_.]*")) { return exportName; } exportName = exportName.toLowerCase(); return exportName.replaceAll("([^(a-z0-9_.)])", "_"); }
protected File postDownload(File archive) { File parentFolder = archive.getParentFile(); File[] ls = parentFolder.listFiles(); for (File f : ls) { if (getDriverName().contains(removeExtension(f.getName()))) { log.trace("Found binary in post-download: {}", f); return f; } } throw new WebDriverManagerException("Driver " + getDriverName() + " not found (using temporal folder " + parentFolder + ")"); }
/** * Return supportFiles (if found) for the specified file * * @param filePath * @return */ public List<File> getSupportFiles(String filePath) { List<File> supportFiles = null; String parent = FilenameUtils.getFullPath(filePath); String mainName = FilenameUtils.getName(filePath); String baseName = FilenameUtils.removeExtension(mainName); for (String extension : supportingExtensions) { String newFilePath = parent + baseName + extension; File file = new File(newFilePath); if (file.exists()) { if (supportFiles == null) { supportFiles = new ArrayList<File>(); } supportFiles.add(file); } } return supportFiles; } }
@Override 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())); } } };
/** * Returns a {@link File} for the given obs complex data to be written to. The output file * location is determined off of the {@link OpenmrsConstants#GLOBAL_PROPERTY_COMPLEX_OBS_DIR} * and the file name is determined off the current obs.getComplexData().getTitle(). * * @param obs the Obs with a non-null complex data on it * @return File that the complex data should be written to */ public File getOutputFileToWrite(Obs obs) throws IOException { String title = obs.getComplexData().getTitle(); String titleWithoutExtension = FilenameUtils.removeExtension(title); String extension = "." + StringUtils.defaultIfEmpty(FilenameUtils.getExtension(title), "dat"); String uuid = obs.getUuid(); String filename; if (StringUtils.isNotBlank(titleWithoutExtension)) { filename = titleWithoutExtension + "_" + uuid + extension; } else { filename = uuid + extension; } File dir = OpenmrsUtil.getDirectoryInApplicationDataDirectory( Context.getAdministrationService().getGlobalProperty(OpenmrsConstants.GLOBAL_PROPERTY_COMPLEX_OBS_DIR)); File outputfile = new File(dir, filename); return outputfile; }
@Test public void getOutputFileToWrite_shouldCorrectlyNameTitledFileWithoutExtension() throws IOException, ParseException { ComplexData complexDataWithoutExtension = new ComplexData(FilenameUtils.removeExtension(FILENAME), null); Obs obsWithoutExtension = new Obs(); obsWithoutExtension.setComplexData(complexDataWithoutExtension); File extensionlessFile = handler.getOutputFileToWrite(obsWithoutExtension); extensionlessFile.createNewFile(); String[] nameWithoutExtension = extensionlessFile.getName().split("_|\\."); String titlePartExtensionless = nameWithoutExtension[0]; String uuidPartExtensionless = nameWithoutExtension[1]; String extensionPartExtensionless = nameWithoutExtension[2]; assertEquals(titlePartExtensionless, FilenameUtils.removeExtension(FILENAME)); assertEquals(extensionPartExtensionless, "dat"); assertEquals(uuidPartExtensionless, obsWithoutExtension.getUuid()); }
@Test public void getOutputFileToWrite_shouldCorrectlyNameTitledFileWithExtension() throws IOException, ParseException { ComplexData complexDataWithTitle = new ComplexData(FILENAME, null); Obs obsWithTitle = new Obs(); obsWithTitle.setComplexData(complexDataWithTitle); File titledFile = handler.getOutputFileToWrite(obsWithTitle); titledFile.createNewFile(); String[] nameWithTitle = titledFile.getName().split("_|\\."); String titlePart = nameWithTitle[0]; String uuidPartWithTitle = nameWithTitle[1]; String extensionPart = nameWithTitle[2]; assertEquals(titlePart, FilenameUtils.removeExtension(FILENAME)); assertEquals(extensionPart, "txt"); assertEquals(uuidPartWithTitle, obsWithTitle.getUuid()); }