List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:com.jadarstudios.rankcapes.forge.cape.CapePack.java
/** * Loads a cape using the given InputStream. * * @param name name to use with the created ResourceLocation. * @param imageInput input to a valid image file. * * @return a StaticCape instance.//from w ww.ja v a 2 s. co m * * @throws IOException */ public StaticCape loadCape(String name, InputStream imageInput) throws IOException { // removes extension just in case. name = FilenameUtils.removeExtension(name).trim(); BufferedImage image = ImageIO.read(imageInput); return new StaticCape(name, image); }
From source file:edu.cornell.med.icb.goby.util.SimulateBisulfiteReads.java
protected void process(DoubleList methylationRates, CharSequence segmentBases, int from, Writer writer) throws IOException { readLength = Math.min(segmentBases.length(), readLength); final String trueRateFilename = FilenameUtils.removeExtension(outputFilename) + "-true-methylation.tsv"; final PrintWriter trueRateWriter = new PrintWriter(new FileWriter(trueRateFilename)); if (bisulfiteTreatment) { writeTrueRatesBisulfite(methylationRates, segmentBases, from, trueRateWriter); } else {/* ww w.j a v a 2s. c o m*/ writeTrueRatesMutations(methylationRates, segmentBases, from, trueRateWriter); } process(segmentBases, from, writer); writer.close(); }
From source file:jease.cms.service.Imports.java
private static File newFile(String filename, InputStream inputStream) throws IOException { File file = new File(); file.setId(Filenames.asId(filename)); file.setTitle(FilenameUtils.removeExtension(filename)); file.setLastModified(new Date()); file.setContentType(MimeTypes.guessContentTypeFromName(filename)); copyStreamToFile(inputStream, file.getFile()); return file;/*from w w w . j ava 2 s .c o m*/ }
From source file:ca.phon.plugins.praat.TextGridManager.java
/** * Return the default textGrid file for the given session. * //from w w w . j a va2 s. c o m * @param session */ public File defaultTextGridFile(Session session) { final String textGridFolder = textGridFolder(session.getCorpus(), session.getName()); List<File> textGridFiles = textGridFilesForSession(session.getCorpus(), session.getName()); final String mediaLocation = FilenameUtils.removeExtension(session.getMediaLocation()); final File mediaFile = new File(mediaLocation); final File defaultTgFile = new File(textGridFolder, mediaFile.getName() + TEXTGRID_EXT); if (textGridFiles.contains(defaultTgFile)) { return defaultTgFile; } // try session name final File backupTgFile = new File(textGridFolder, session.getName() + TEXTGRID_EXT); if (textGridFiles.contains(backupTgFile)) { return backupTgFile; } // finally return the first file found if (textGridFiles.size() > 0) { return textGridFiles.get(0); } return null; }
From source file:edu.cornell.med.icb.goby.stats.AnnotationAveragingWriter.java
public AnnotationAveragingWriter(final OutputInfo outputInfo, RandomAccessSequenceInterface genome, MethylCountProvider provider) {//ww w . java 2 s.co m super(new NullWriter()); String contextString = doc.getString("contexts"); String[] contextTokens = contextString.split(","); if (contextTokens.length != 0) { LOG.info("registering user defined contexts: " + ObjectArrayList.wrap(contextTokens)); contexts = contextTokens; } estimateIntraGroupDifferences = doc.getBoolean("estimate-intra-group-differences"); estimateIntraGroupP = doc.getBoolean("estimate-empirical-P"); writeCounts = doc.getBoolean("write-counts"); writeObservations = doc.getBoolean("write-observations"); if (estimateIntraGroupDifferences || estimateIntraGroupP) { String basename = FilenameUtils.removeExtension(outputInfo.getFilename()); if (basename == null) { basename = Long.toString(new Date().getTime()); } if (writeObservations) { String filename = basename + "-" + (estimateIntraGroupDifferences ? "null" : "test") + "-observations.tsv"; try { obsWriter = new ObservationWriter(new FileWriter(filename)); obsWriter.setHeaderIds( new String[] { "context", "chromosome", "start", "end", "annotation-id" }); } catch (IOException e) { LOG.error("Cannot open observation file for writing: " + filename); } } } this.provider = provider; this.outputInfo = outputInfo; if (!estimateIntraGroupDifferences) { outputWriter = outputInfo.getPrintWriter(); } else { outputWriter = new NullWriter(); } this.genome = genome; initialized = false; processGroups = true; }
From source file:de.teamgrit.grit.preprocess.IliasPreprocessor.java
/** * Sets the Students name and mail according to his submission. * /*from w w w.jav a2s .c o m*/ * @param studentData * the Student * @param studentSubmission * his Submission * @param studentSubmissions * the map storing the students and their submissions */ private static void setSubmitted(StudentRepoData studentData, Submission studentSubmission, Map<Student, Submission> studentSubmissions) { String downloadedFile = FilenameUtils .removeExtension(Paths.get(studentData.getSubmissionPath()).getFileName().toString()); String studentFile = studentSubmission.getSourceCodeLocation().getFileName().toString(); if (studentFile.equals(downloadedFile)) { Student student = studentSubmission.getStudent(); student.setName(studentData.getFirstName() + " " + studentData.getLastName()); student.setEmail(studentData.getEmail()); studentSubmissions.put(student, studentSubmission); } }
From source file:com.door43.translationstudio.SettingsActivity.java
/** * Shows the simplified settings UI if the device configuration if the * device configuration dictates that a simplified, single-pane UI should be * shown.// w ww . j ava 2 s . c o m */ private void setupSimplePreferencesScreen() { if (!isSimplePreferences(this)) { return; } // In the simplified UI, fragments are not used at all and we instead // use the older PreferenceActivity APIs. // Add 'general' preferences. addPreferencesFromResource(R.xml.general_preferences); // NOTE: this is a copy paste from GeneralPreferenceFragment // identify all typefaces in the assets directory AssetManager am = getResources().getAssets(); String fileList[] = null; ArrayList<String> entries = new ArrayList<String>(); ArrayList<String> entryValues = new ArrayList<String>(); try { fileList = am.list("fonts"); } catch (IOException e) { Logger.e(this.getClass().getName(), "failed to load font assets", e); } if (fileList != null) { for (int i = 0; i < fileList.length; i++) { File typeface = AppContext.context().getAssetAsFile("fonts/" + fileList[i]); if (typeface != null) { TTFAnalyzer analyzer = new TTFAnalyzer(); String fontname = ""; fontname = analyzer.getTtfFontName(typeface.getAbsolutePath()); if (fontname == null) { fontname = FilenameUtils.removeExtension(typeface.getName()); } entries.add(fontname); entryValues.add(fileList[i]); } } } ListPreference pref = (ListPreference) findPreference(KEY_PREF_TRANSLATION_TYPEFACE); pref.setEntries(entries.toArray(new CharSequence[entries.size()])); pref.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()])); bindPreferenceSummaryToValue(pref); // Add 'sharing' preferences, and a corresponding header. // PreferenceCategory preferenceHeader = new PreferenceCategory(this); // preferenceHeader.setTitle(R.string.pref_header_sharing); // getPreferenceScreen().addPreference(preferenceHeader); // addPreferencesFromResource(R.xml.sharing_preferences); // Add 'server' preferences, and a corresponding header. PreferenceCategory preferenceHeader = new PreferenceCategory(this); preferenceHeader.setTitle(R.string.pref_header_synchronization); getPreferenceScreen().addPreference(preferenceHeader); addPreferencesFromResource(R.xml.server_preferences); // Add 'legal' preferences, and a corresponding header. preferenceHeader = new PreferenceCategory(this); preferenceHeader.setTitle(R.string.pref_header_legal); getPreferenceScreen().addPreference(preferenceHeader); addPreferencesFromResource(R.xml.legal_preferences); // add 'advanced' preferences and coresponding hreader preferenceHeader = new PreferenceCategory(this); preferenceHeader.setTitle(R.string.pref_header_advanced); getPreferenceScreen().addPreference(preferenceHeader); addPreferencesFromResource(R.xml.advanced_preferences); // bind the correct legal document to the preference intent bindPreferenceClickToLegalDocument(findPreference("license_agreement"), R.string.license); bindPreferenceClickToLegalDocument(findPreference("statement_of_faith"), R.string.statement_of_faith); bindPreferenceClickToLegalDocument(findPreference("translation_guidelines"), R.string.translation_guidlines); bindPreferenceClickToLegalDocument(findPreference("software_licenses"), R.string.software_licenses); // Bind the summaries of EditText/List/Dialog/Ringtone preferences to // their values. When their values change, their summaries are updated // to reflect the new value, per the Android Design guidelines. // bindPreferenceSummaryToValue(findPreference(KEY_PREF_AUTOSAVE)); bindPreferenceSummaryToValue(findPreference(KEY_PREF_AUTH_SERVER)); bindPreferenceSummaryToValue(findPreference(KEY_PREF_GIT_SERVER)); bindPreferenceSummaryToValue(findPreference(KEY_PREF_AUTH_SERVER_PORT)); bindPreferenceSummaryToValue(findPreference(KEY_PREF_GIT_SERVER_PORT)); // bindPreferenceSummaryToValue(findPreference(KEY_PREF_EXPORT_FORMAT)); bindPreferenceSummaryToValue(findPreference(KEY_PREF_MEDIA_SERVER)); bindPreferenceSummaryToValue(findPreference(KEY_PREF_LOGGING_LEVEL)); bindPreferenceSummaryToValue(findPreference(KEY_PREF_BACKUP_INTERVAL)); bindPreferenceSummaryToValue(findPreference(KEY_PREF_TYPEFACE_SIZE)); }
From source file:com.doplgangr.secrecy.UpdateManager.UpdateManager.java
@Background void version32to40() { //walks the whole file tree, find out files that do not have encoded file names //and encode them. Collection files = FileUtils.listFiles(storage.getRoot(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (Object file : files) { File realFile = (File) file; String fileName = FilenameUtils.removeExtension(realFile.getName()); fileName = fileName.replace("_thumb", ""); if (".nomedia".equals(fileName)) continue; try {//from w ww . jav a 2 s .c o m Base64Coder.decodeString(fileName); } catch (IllegalArgumentException e) { String encodedFileName = Base64Coder.encodeString(fileName); fileName = realFile.getAbsolutePath().replace(fileName, encodedFileName); Boolean ignored = realFile.renameTo(new File(fileName)); } } onFinishAllUpgrade(); }
From source file:com.esri.geoevent.test.performance.ui.ReportOptionsController.java
/** * Toggles the report type and updates the UI state. * * @param event {@link ActionEvent} not used *///from ww w . j av a 2 s. c o m @FXML public void toggleReportType(final ActionEvent event) { if (report.getType() != reportType.getValue()) { report.setType(reportType.getValue()); String newFileName = FilenameUtils.removeExtension(report.getReportFile()) + "." + report.getType().toString().toLowerCase(); updateSelectedReportFile(newFileName); } }
From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.RemoteApiController.java
/** * Create a new project.//from w w w . j av a2 s . c om * * To test, use the Linux "curl" command. * * curl -v -F 'file=@test.zip' -F 'name=Test' -F 'filetype=tcf' * 'http://USERNAME:PASSWORD@localhost:8080/de.tudarmstadt.ukp.clarin.webanno.webapp/api/project * ' * * @param aName * the name of the project to create. * @param aFileType * the type of the files contained in the ZIP. The possible file types are configured * in the formats.properties configuration file of WebAnno. * @param aFile * a ZIP file containing the project data. * @throws Exception if there was en error. */ @RequestMapping(value = "/project", method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public @ResponseStatus(HttpStatus.NO_CONTENT) void createProject(@RequestParam("file") MultipartFile aFile, @RequestParam("name") String aName, @RequestParam("filetype") String aFileType) throws Exception { LOG.info("Creating project [" + aName + "]"); if (!ZipUtils.isZipStream(aFile.getInputStream())) { throw new InvalidFileNameException("", "is an invalid Zip file"); } // Get current user String username = SecurityContextHolder.getContext().getAuthentication().getName(); User user = userRepository.get(username); Project project = null; // Configure project if (!projectRepository.existsProject(aName)) { project = new Project(); project.setName(aName); // Create the project and initialize tags projectRepository.createProject(project, user); annotationService.initializeTypesForProject(project, user, new String[] {}, new String[] {}, new String[] {}, new String[] {}, new String[] {}, new String[] {}, new String[] {}, new String[] {}); // Create permission for this user ProjectPermission permission = new ProjectPermission(); permission.setLevel(PermissionLevel.ADMIN); permission.setProject(project); permission.setUser(username); projectRepository.createProjectPermission(permission); permission = new ProjectPermission(); permission.setLevel(PermissionLevel.USER); permission.setProject(project); permission.setUser(username); projectRepository.createProjectPermission(permission); } // Existing project else { throw new IOException("The project with name [" + aName + "] exists"); } // Iterate through all the files in the ZIP // If the current filename does not start with "." and is in the root folder of the ZIP, // import it as a source document File zimpFile = File.createTempFile(aFile.getOriginalFilename(), ".zip"); aFile.transferTo(zimpFile); ZipFile zip = new ZipFile(zimpFile); for (Enumeration<?> zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements();) { // // Get ZipEntry which is a file or a directory // ZipEntry entry = (ZipEntry) zipEnumerate.nextElement(); // If it is the zip name, ignore it if ((FilenameUtils.removeExtension(aFile.getOriginalFilename()) + "/").equals(entry.toString())) { continue; } // IF the current filename is META-INF/webanno/source-meta-data.properties store it // as // project meta data else if (entry.toString().replace("/", "") .equals((META_INF + "webanno/source-meta-data.properties").replace("/", ""))) { InputStream zipStream = zip.getInputStream(entry); projectRepository.savePropertiesFile(project, zipStream, entry.toString()); } // File not in the Zip's root folder OR not // META-INF/webanno/source-meta-data.properties else if (StringUtils.countMatches(entry.toString(), "/") > 1) { continue; } // If the current filename does not start with "." and is in the root folder of the // ZIP, import it as a source document else if (!FilenameUtils.getExtension(entry.toString()).equals("") && !FilenameUtils.getName(entry.toString()).equals(".")) { uploadSourceDocument(zip, entry, project, user, aFileType); } } LOG.info("Successfully created project [" + aName + "] for user [" + username + "]"); }