List of usage examples for org.apache.commons.io FilenameUtils getBaseName
public static String getBaseName(String filename)
From source file:com.googlecode.dex2jar.v3.Main.java
public static void doData(byte[] data, File destJar, boolean handleException) throws IOException { DexFileReader reader = new DexFileReader(data); DexExceptionHandlerImpl handler = handleException ? new DexExceptionHandlerImpl() : null; Dex2jar.from(reader).withExceptionHandler(handler).to(destJar); if (handleException) { Map<Method, Exception> exceptions = handler.getExceptions(); if (exceptions != null && exceptions.size() > 0) { File errorFile = new File(destJar.getParentFile(), FilenameUtils.getBaseName(destJar.getName()) + ".error.zip"); handler.dumpException(reader, errorFile); System.err.println("Detail Error Information in File " + errorFile); System.err.println(//from www .j ava2 s . c o m "Please report this file to http://code.google.com/p/dex2jar/issues/entry if possible."); } } }
From source file:edu.harvard.med.screensaver.util.FileUtils.java
/** * Returns a File object with a new parent directory and/or a new file * extension./*w w w . ja v a 2 s.c om*/ * * @param file the File object to be modified * @param newDirectory the output directory; if null the file original * file directory is used. * @param newExtension the extension to use when saving the file, * replacing the file's original filename extension; if null * original filename extension is used. A leading period will be * added if it does not exist. * @return the modified File object */ public static File modifyFileDirectoryAndExtension(File file, File newDirectory, String newExtension) { if (newExtension == null) { newExtension = FilenameUtils.getExtension(file.getName()); } else { if (newExtension.startsWith(".")) { newExtension = newExtension.substring(1); } } if (newDirectory == null) { newDirectory = file.getParentFile(); } File outputFile = new File(newDirectory, FilenameUtils.getBaseName(file.getName()) + "." + newExtension); return outputFile; }
From source file:net.mitnet.tools.pdf.book.io.FileNameHelper.java
public static String rewriteFileNameSuffix(String sourceFileName, String newFileNameExtension) { String pathPath = FilenameUtils.getFullPath(sourceFileName); String baseFileName = FilenameUtils.getBaseName(sourceFileName); String newFileName = baseFileName + newFileNameExtension; String newFile = FilenameUtils.concat(pathPath, newFileName); return newFile; }
From source file:com.github.lucapino.sheetmaker.renderer.TemplateFilter.java
public static Map<String, String> createTokenMap(Movie movie, MovieInfo movieInfo, Episode episode) { Map<String, String> result = new HashMap<>(); result.put("%TITLEPATH%", movieInfo.getTitlePath()); // %MOVIEFILENAME% Current movie filename Spread.2009.mkv (for c,\movies\spread\spread.2009.mkv) result.put("%MOVIEFILENAME%", movieInfo.getMovieFileName()); // %MOVIEFILENAMEWITHOUTEXT% Current movie filename without extension Spread.2009 (for c,\Movies\Spread\Spread.2009.mkv) result.put("%MOVIEFILENAMEWITHOUTEXT%", FilenameUtils.getBaseName(movieInfo.getMovieFileName())); // %MOVIEFOLDER% Current movie folder name Spread (for c,\Movies\Spread\Spread.2009.mkv) result.put("%MOVIEFOLDER%", movieInfo.getMovieFolder()); // %MOVIEPARENTFOLDER% Current movie parent folder name Movies (for c,\Movies\Spread\Spread.2009.mkv) result.put("%MOVIEPARENTFOLDER%", movieInfo.getParentMovieFolder()); result.put("%TITLE%", movie.getTitle()); // %ORIGINALTITLE% Original movie title Inglourious Basterds result.put("%ORIGINALTITLE%", movie.getOriginalTitle()); // %PLOT% Synopsis Some description of the movie. result.put("%PLOT%", movie.getPlot()); // %TAGLINE% The Tagline Some tagline result.put("%TAGLINE%", movie.getTagline()); // %COMMENTS% Free "joker" field for the user own data Some free test the user can place on the sheet //TODO// www. j a v a2 s . c o m result.put("%COMMENTS%", ""); result.put("%YEAR%", movie.getYear()); result.put("%RUNTIME%", movie.getRuntime()); String actors = movie.getActors().toString(); result.put("%ACTORS%", actors.substring(1, actors.length() - 1)); String genres = movie.getGenres().toString(); result.put("%GENRES%", genres.substring(1, genres.length() - 1)); String directors = movie.getDirectors().toString(); result.put("%DIRECTORS%", directors.substring(1, directors.length() - 1)); result.put("%CERTIFICATION%", movie.getCertification()); result.put("%RELEASEDATE%", movie.getReleaseDate()); result.put("%MPAA%", movie.getMPAA()); // %IMDBID% IMDb Id of the movie tt1186370 result.put("%IMDBID%", movie.getImdbId()); result.put("%CERTIFICATIONTEXT%", movie.getCertification()); String countries = movie.getCountries().toString(); result.put("%COUNTRIES%", countries.substring(1, countries.length() - 1)); String studios = movie.getStudios().toString(); result.put("%STUDIOS%", studios.substring(1, studios.length() - 1)); // %ALLSUBTITLES% List of distinct embedded/external subtitles (English names) English, Spanish,German * String allSubtitles = movieInfo.getAllSubtitles().toString(); result.put("%ALLSUBTITLES%", allSubtitles.substring(1, allSubtitles.length() - 1)); // %ALLSUBTITLESTEXT% List of distinct embedded/external subtitles (native names) English, Espanol,Deutsch * String allLocalizedSubtitles = movieInfo.getAllLocalizedSubtitles().toString(); result.put("%ALLSUBTITLESTEXT%", allLocalizedSubtitles.substring(1, allLocalizedSubtitles.length() - 1)); String embeddedSubtitles = movieInfo.getEmbeddedSubtitles().toString(); result.put("%SUBTITLES%", embeddedSubtitles.substring(1, embeddedSubtitles.length() - 1)); // %SUBTITLES1% %SUBTITLES5% Individual embedded subtitles (English names) English // %SUBTITLESTEXT% List of embedded subtitles (Native names) English, Francais, Deutsch * String embeddedLocalizedSubtitles = movieInfo.getEmbeddedLocalizedSubtitles().toString(); result.put("%SUBTITLESTEXT%", embeddedLocalizedSubtitles.substring(1, embeddedLocalizedSubtitles.length() - 1)); // %EXTERNALSUBTITLESTEXT% List of external subtitles (Native names) English, Francais, Deutsch * String externalLocalizedSubtitles = movieInfo.getExternalLocalizedSubtitles().toString(); result.put("%EXTERNALSUBTITLESTEXT%", externalLocalizedSubtitles.substring(1, externalLocalizedSubtitles.length() - 1)); // %EXTERNALSUBTITLES% List of external subtitles (English names) English, French * String externalSubtitles = movieInfo.getExternalSubtitles().toString(); result.put("%EXTERNALSUBTITLES%", externalSubtitles.substring(1, externalSubtitles.length() - 1)); // %EXTERNALSUBTITLES1% %EXTERNALSUBTITLES5% Individual external subtitles (English names) English // TODO // %RATING% The rating of the movie (x of 10) 6.8/10 result.put("%RATING%", (Double.valueOf(movie.getRatingPercent()) / 10) + "/10"); // %RATINGPERCENT% The rating as percent 68 result.put("%RATINGPERCENT%", movie.getRatingPercent()); if (episode != null) { /** * ************** Start TV Shows ******************** */ // %SEASON% The autodetected season number for the current movie 4 result.put("%SEASON%", "" + episode.getSeason().getNumber()); // %EPISODE% The autodetected episode (or CD) number for the current movie 2 result.put("%EPISODE%", "" + episode.getNumber()); // %EPISODETITLE% The current episode name Fire + Water result.put("%EPISODETITLE%", episode.getTitle()); // %EPISODEPLOT% Synopsis of the current episode Some description of the episode. result.put("%EPISODEPLOT%", episode.getOverview()); // %EPISODERELEASEDATE% Release date of the current episode 12.03.2010 (formatted using collector's format) // TODO result.put("%EPISODERELEASEDATE%", ""); // %EPISODELIST% List of episodes for the current season 1, 2, 3 * List<Episode> episodes = episode.getSeason().getEpisodes(); List<String> episodeList = new ArrayList<>(); for (Episode currentEpisode : episodes) { episodeList.add("" + currentEpisode.getNumber()); } String res = episodeList.toString(); result.put("%EPISODELIST%", res.substring(1, res.length() - 1)); // %EPISODENAMESLIST% List of episodes titles for the current season Title One, Title Two * episodes = episode.getSeason().getEpisodes(); List<String> episodeNameList = new ArrayList<>(); for (Episode currentEpisode : episodes) { episodeNameList.add(currentEpisode.getTitle()); } res = episodeNameList.toString(); result.put("%EPISODENAMESLIST%", res.substring(1, res.length() - 1)); // %EPISODEGUESTSTARS% List of guest stars for the current episode John B, John C * List<String> episodeGuestsList = episode.getGuestStars(); String episodeGuests = episodeGuestsList.toString(); result.put("%EPISODEGUESTSTARS%", episodeGuests.substring(1, episodeGuests.length() - 1)); // %EPISODEWRITERS% List of writers for the current episode John B, John C * // TODO result.put("%EPISODEWRITERS%", ""); } /** * ************** End TV Shows ******************** */ // %MEDIAFORMATTEXT% See below list of media values supported. Loaded from /Template/MediaFormats/MediaFormat/@Name Returns value from @Text attribute MKV result.put("%MEDIAFORMATTEXT%", movieInfo.getMediaformat()); // %SOUNDFORMATTEXT% See below list of sound values supported. /Template/SoundFormats/SoundFormat/@Name Returns value from @Text attribute MP3 result.put("%SOUNDFORMATTEXT%", movieInfo.getSoundFormat()); // %RESOLUTIONTEXT% See below list of resolution values supported. /Template/Resolutions/Resolution/@Name Returns value from @Text attribute 1080P result.put("%RESOLUTIONTEXT%", movieInfo.getResolution()); // %VIDEOFORMATTEXT% See below list of video values supported. /Template/VideoFormats/VideoFormat/@Name Returns value from @Text attribute AVC result.put("%VIDEOFORMATTEXT%", movieInfo.getVideoFormat()); result.put("%FRAMERATETEXT%", movieInfo.getFrameRate()); // %FRAMERATE% Formatted frame rate of the movie (to allow mapping to filenames). The . character is replaced by the _ character. 23_976 result.put("%FRAMERATE%", movieInfo.getFrameRate().replace(".", "_")); result.put("%ASPECTRATIOTEXT%", movieInfo.getAspectRatio()); // %ASPECTRATIO% Formatted aspect ration (to allow mapping to filenames). The . character is replaced by the _ character and the , character is replaced by -. 16-9 or 2_35-1 or 4-3 result.put("%ASPECTRATIO%", movieInfo.getAspectRatio().replace(":", "-")); result.put("%VIDEORESOLUTION%", movieInfo.getVideoResolution()); // %VIDEORESOLUTIONTEXT% The movie resolution 1920x1080 result.put("%VIDEORESOLUTIONTEXT%", movieInfo.getVideoResolution()); // TODO result.put("%VIDEOCODECTEXT%", ""); result.put("%VIDEOBITRATETEXT%", movieInfo.getVideoBitrate()); result.put("%AUDIOCODECTEXT%", movieInfo.getAllAudioInfo().get(0).getAudioCodec()); result.put("%AUDIOCHANNELSTEXT%", movieInfo.getAudioChannels()); result.put("%AUDIOBITRATETEXT%", movieInfo.getAudioBitrate()); // TODO, convert in minutes result.put("%DURATIONTEXT%", movieInfo.getDuration()); // %DURATION% The detected (mediainfo) duration of the movie (minutes) 98 result.put("%DURATION%", movieInfo.getDuration()); // %DURATIONSEC% The detected (mediainfo) duration of the movie (seconds) 5880 result.put("%DURATIONSEC%", "" + (Integer.valueOf(movieInfo.getDuration()) * 60)); // TODO, convert in human kB, MB, GB result.put("%FILESIZETEXT%", movieInfo.getFileSize()); // %CONTAINERTEXT% The detected (mediainfo) container format (as it comes from MediaInfo) Matroska result.put("%CONTAINERTEXT%", movieInfo.getContainer()); // %LANGUAGECODE% The two letter ISO code of the language of the first audio stream en result.put("%LANGUAGECODE%", movieInfo.getLanguageCode()); // %LANGUAGE% The language of the first audio stream (always the English name) Spanish result.put("%LANGUAGE%", movieInfo.getLanguage()); // %LANGUAGES% The languages of all audio streams (always the English names) Spanish/English/Italian * List<String> languages = new ArrayList<>(); for (AudioInfo audioInfo : movieInfo.getAllAudioInfo()) { languages.add(audioInfo.getLanguage()); } String languagesString = languages.toString(); result.put("%LANGUAGES%", languagesString.substring(1, languagesString.length() - 1)); // %LANGUAGECODES% The two letter ISO code of the languages of all audio streams es/en/it * List<String> languagesCodes = new ArrayList<>(); for (AudioInfo audioInfo : movieInfo.getAllAudioInfo()) { languagesCodes.add(audioInfo.getLanguageCode().toLowerCase()); } String languagesCodesString = languagesCodes.toString(); result.put("%LANGUAGECODES%", languagesCodesString.substring(1, languagesCodesString.length() - 1)); // %CERTIFICATIONCOUNTRYCODE% The two letter code of the country selected in Options/IMDB as Certification Country (default value, us) es result.put("%CERTIFICATIONCOUNTRYCODE%", "us"); // %LANGUAGES1% %LANGUAGES5% Individual audio languages (English names) English // TODO result.put("%LANGUAGES1%", ""); return result; }
From source file:ijfx.ui.utils.NamingUtils.java
public static File addSuffix(File original, String suffix) { String baseName = FilenameUtils.getBaseName(original.getName()); String extension = FilenameUtils.getExtension(original.getName()); String finalName = new StringBuilder().append(baseName).append("_").append(suffix).append(".") .append(extension).toString(); return new File(original.getParent(), finalName); }
From source file:com.kegare.frozenland.util.Version.java
private static void initialize() { CURRENT = Optional.of(Strings.nullToEmpty(Frozenland.metadata.version)); LATEST = Optional.fromNullable(CURRENT.orNull()); File file = FrozenUtils.getModContainer().getSource(); if (file != null && file.exists()) { if (file.isFile()) { String name = FilenameUtils.getBaseName(file.getName()); if (StringUtils.endsWithIgnoreCase(name, "dev")) { DEV_DEBUG = true;/*from ww w . j a va 2s . com*/ } } else if (file.isDirectory()) { DEV_DEBUG = true; } } else if (!FMLForgePlugin.RUNTIME_DEOBF) { DEV_DEBUG = true; } if (Frozenland.metadata.version.endsWith("dev")) { DEV_DEBUG = true; } else if (DEV_DEBUG) { Frozenland.metadata.version += "-dev"; } }
From source file:avantssar.aslanpp.testing.HTMLHelper.java
public static void fileOrDash(PrintStream out, File root, File aslanPPfile, String prefix) { if (aslanPPfile != null) { out.print("<a href='"); out.print(removePrefix(root, aslanPPfile)); out.print("'>"); if (prefix != null) { out.print(prefix);//from w w w.jav a 2s. c om } else { out.print(FilenameUtils.getBaseName(aslanPPfile.getName())); } out.print("</a>"); } else { if (prefix != null) { out.print(prefix); } else { out.print("-"); } } }
From source file:com.kegare.friendlymobs.util.Version.java
private static void initialize() { CURRENT = Optional.of(Strings.nullToEmpty(FriendlyMobs.metadata.version)); LATEST = Optional.fromNullable(CURRENT.orNull()); File file = FriendlyUtils.getModContainer().getSource(); if (file != null && file.exists()) { if (file.isFile()) { if (StringUtils.endsWithIgnoreCase(FilenameUtils.getBaseName(file.getName()), "dev")) { DEV_DEBUG = true;//from w ww .j ava 2s . c o m } } else { DEV_DEBUG = true; } } else if (!FMLForgePlugin.RUNTIME_DEOBF) { DEV_DEBUG = true; } if (StringUtils.endsWithIgnoreCase(getCurrent(), "dev")) { DEV_DEBUG = true; } else if (DEV_DEBUG) { FriendlyMobs.metadata.version += "-dev"; } }
From source file:com.github.signed.sandboxes.maven.ZipDumper.java
private void classifyFile(LegalRelevantFiles legalRelevantFiles, FileHeader fileHeader) { if (fileHeader.isDirectory()) { return;/*from w w w. j av a 2 s .co m*/ } String extension = FilenameUtils.getExtension(fileHeader.getFileName()); if ("class".equals(extension)) { return; } String baseName = FilenameUtils.getBaseName(fileHeader.getFileName()); if ("license".equalsIgnoreCase(baseName)) { legalRelevantFiles.licenseFile(fileHeader); } else if ("notice".equalsIgnoreCase(baseName)) { legalRelevantFiles.noticeFile(fileHeader); } }
From source file:eu.mrbussy.pdfsplitter.Splitter.java
/** * Split the given PDF file into multiple files using pages. * //from w w w . ja v a 2s . com * @param filename * - Name of the PDF to split * @param useSubFolder * - Use a separate folder to place the files in. */ public static void Run(File file, boolean useSubFolder) { PdfReader reader = null; String format = null; if (useSubFolder) { format = "%1$s%2$s%4$s"; // Directory format try { FileUtils.forceMkdir( new File(String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()), FilenameUtils.getBaseName(file.getAbsolutePath()), FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } format = "%1$s%2$s%4$s%2$s_%%03d.%3$s"; // Directory format + filename } else format = "%1$s%2$s_%%03d.%3$s"; String splitFile = String.format(format, FilenameUtils.getFullPath(file.getAbsolutePath()), FilenameUtils.getBaseName(file.getAbsolutePath()), FilenameUtils.getExtension(file.getAbsolutePath()), IOUtils.DIR_SEPARATOR); try { reader = new PdfReader(new FileInputStream(file)); if (reader.getNumberOfPages() > 0) { for (int pageNum = 1; pageNum <= reader.getNumberOfPages(); pageNum++) { System.out.println(String.format(splitFile, pageNum)); String filename = String.format(splitFile, pageNum); Document document = new Document(reader.getPageSizeWithRotation(1)); PdfCopy writer = new PdfCopy(document, new FileOutputStream(filename)); document.open(); // Copy the page from the original PdfImportedPage page = writer.getImportedPage(reader, pageNum); writer.addPage(page); document.close(); writer.close(); } } } catch (Exception ex) { // TODO Implement exception handling ex.printStackTrace(System.err); } finally { if (reader != null) // Always close the stream reader.close(); } }