List of usage examples for org.apache.commons.io FilenameUtils removeExtension
public static String removeExtension(String filename)
From source file:com.uwsoft.editor.controlles.ResolutionManager.java
public void resizeImagesTmpDirToResolution(String packName, File sourceFolder, ResolutionEntryVO resolution, File targetFolder) {/*from w w w.ja va2s. c om*/ float ratio = ResolutionManager.getResolutionRatio(resolution, dataManager.getCurrentProjectInfoVO().originalResolution); if (targetFolder.exists()) { try { FileUtils.cleanDirectory(targetFolder); } catch (IOException e) { e.printStackTrace(); } } // now pack TexturePacker.Settings settings = new TexturePacker.Settings(); settings.flattenPaths = true; settings.maxHeight = getMinSquareNum(resolution.height); settings.maxWidth = getMinSquareNum(resolution.height); settings.filterMag = Texture.TextureFilter.Linear; settings.filterMin = Texture.TextureFilter.Linear; TexturePacker tp = new TexturePacker(settings); for (final File fileEntry : sourceFolder.listFiles()) { if (!fileEntry.isDirectory()) { BufferedImage bufferedImage = ResolutionManager.imageResize(fileEntry, ratio); tp.addImage(bufferedImage, FilenameUtils.removeExtension(fileEntry.getName())); } } tp.pack(targetFolder, packName); }
From source file:net.sf.firemox.DeckBuilder.java
/** * Load a given deck file into the given list. * /*from ww w . j a va 2s. com*/ * @param fileName * deck file name. * @param names * loaded cards to complete. */ protected void loadDeck(String fileName, MListModel<MCardCompare> names) { // empty file name or deck? if (fileName == null || fileName.length() == 0) { return; } // Append the deck name final String deckName = FilenameUtils.removeExtension(FilenameUtils.getName(fileName)); setTitle("DeckBuilder : " + deckName); deckNameTxt.setText(deckName); names.clear(); datasets.removeAll(); try { Deck currentDeck = DeckReader.getDeck(this, fileName); if (currentDeck == null) { // Deck loading failure return; } // Validate this deck DeckReader.validateDeck(this, currentDeck, (String) null); // Update the card models of resolved cards final FileInputStream dbStream = MdbLoader.resetMdb(); for (MCardCompare cardCompare : currentDeck.getCards()) { names.add(cardCompare); datasets.addCard(cardCompare.getModel(dbStream), cardCompare.getAmount()); } constraintsChecker.setDeck(currentDeck); } catch (IOException e) { e.printStackTrace(); } finally { updateChecker(); setAsSaved(); } }
From source file:com.moviejukebox.scanner.AttachmentScanner.java
/** * Determines the content of the attachment by file name and mime type. * * @param inFileName/* w w w . ja va 2 s. c om*/ * @param inMimeType * @return the content, may be null if determination failed */ private static AttachmentContent determineContent(String inFileName, String inMimeType, int firstPart, int lastPart) { if (inFileName == null) { return null; } if (inMimeType == null) { return null; } String fileName = inFileName.toLowerCase(); String mimeType = inMimeType.toLowerCase(); if (VALID_TEXT_MIME_TYPES.contains(mimeType)) { // NFO for (String extension : NFO_EXTENSIONS) { if (extension.equalsIgnoreCase(FilenameUtils.getExtension(fileName))) { return new AttachmentContent(ContentType.NFO); } } } else if (VALID_IMAGE_MIME_TYPES.containsKey(mimeType)) { String check = FilenameUtils.removeExtension(fileName); // check for SET image boolean isSetImage = Boolean.FALSE; if (check.endsWith(".set")) { isSetImage = Boolean.TRUE; // fix check to look for image type // just removing extension which is ".set" in this moment check = FilenameUtils.removeExtension(check); } for (String posterToken : POSTER_TOKENS) { if (check.endsWith(posterToken) || check.equals(posterToken.substring(1))) { if (isSetImage) { // fileName = <any>.<posterToken>.set.<extension> return new AttachmentContent(ContentType.SET_POSTER); } // fileName = <any>.<posterToken>.<extension> return new AttachmentContent(ContentType.POSTER); } } if (check.endsWith(FANART_TOKEN) || check.equals(FANART_TOKEN.substring(1))) { if (isSetImage) { // fileName = <any>.<fanartToken>.set.<extension> return new AttachmentContent(ContentType.SET_FANART); } // fileName = <any>.<fanartToken>.<extension> return new AttachmentContent(ContentType.FANART); } if (check.endsWith(BANNER_TOKEN) || check.equals(BANNER_TOKEN.substring(1))) { if (isSetImage) { // fileName = <any>.<bannerToken>.set.<extension> return new AttachmentContent(ContentType.SET_BANNER); } // fileName = <any>.<bannerToken>.<extension> return new AttachmentContent(ContentType.BANNER); } // determination of exactly video image part for (int part = firstPart; part <= lastPart; part++) { String checkToken = VIDEOIMAGE_TOKEN + "_" + (part - firstPart + 1); if (check.endsWith(checkToken) || check.equals(checkToken.substring(1))) { // fileName = <any>.<videoimageToken>_<part>.<extension> return new AttachmentContent(ContentType.VIDEOIMAGE, part); } } // generic way of video image detection if (check.endsWith(VIDEOIMAGE_TOKEN) || check.equals(VIDEOIMAGE_TOKEN.substring(1))) { // fileName = <any>.<videoimageToken>.<extension> return new AttachmentContent(ContentType.VIDEOIMAGE); } } // no content type determined return null; }
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceObjectProviderBase.java
private String getModelMetaDataLocation(String aLocation) { String baseLocation = aLocation; if (baseLocation.toLowerCase().endsWith(".gz")) { baseLocation = baseLocation.substring(0, baseLocation.length() - 3); } else if (baseLocation.toLowerCase().endsWith(".bz2")) { baseLocation = baseLocation.substring(0, baseLocation.length() - 4); }//from w ww. j av a2 s.co m String modelMetaDataLocation = FilenameUtils.removeExtension(baseLocation) + ".properties"; return modelMetaDataLocation; }
From source file:com.warfrog.bitmapallthethings.BattEngine.java
private void decodeBitmap(String filename) throws IOException { System.out.println("Decoding " + filename); File inputFile = new File(filename); File outputFile = new File( outputDirectory + File.separator + FilenameUtils.removeExtension(inputFile.getName())); FileInputStream fis = new FileInputStream(filename); //skip 6 bytes fis.skip(6);// w w w . ja v a2 s. co m //read the length we encoded int fileSize = EndianUtils.readSwappedInteger(fis); //skip the rest of the header fis.skip(44); Files.copy(fis, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING); //truncate the file FileChannel outChan = new FileOutputStream(outputFile, true).getChannel(); outChan.truncate(fileSize); outChan.close(); //clean up if (isCleanUp()) { //delete the bitmap System.out.println("Deleting: " + inputFile); FileUtils.deleteQuietly(inputFile); } }
From source file:com.o2d.pkayjava.editor.proxy.ResolutionManager.java
public void resizeImagesTmpDirToResolution(String packName, File sourceFolder, ResolutionEntryVO resolution, File targetFolder) {/*from w ww. j ava2 s. co m*/ ProjectManager projectManager = facade.retrieveProxy(ProjectManager.NAME); float ratio = ResolutionManager.getResolutionRatio(resolution, projectManager.getCurrentProjectInfoVO().originalResolution); if (targetFolder.exists()) { try { FileUtils.cleanDirectory(targetFolder); } catch (IOException e) { e.printStackTrace(); } } // now pack TexturePacker.Settings settings = new TexturePacker.Settings(); settings.flattenPaths = true; settings.maxHeight = getMinSquareNum(resolution.height); settings.maxWidth = getMinSquareNum(resolution.height); settings.filterMag = Texture.TextureFilter.Linear; settings.filterMin = Texture.TextureFilter.Linear; TexturePacker tp = new TexturePacker(settings); for (final File fileEntry : sourceFolder.listFiles()) { if (!fileEntry.isDirectory()) { BufferedImage bufferedImage = ResolutionManager.imageResize(fileEntry, ratio); tp.addImage(bufferedImage, FilenameUtils.removeExtension(fileEntry.getName())); } } tp.pack(targetFolder, packName); }
From source file:ffx.potential.parsers.PDBFileMatcher.java
private File createVersionedCopy(File origFile) throws IOException { String filename = origFile.getName(); String ext = FilenameUtils.getExtension(filename); filename = FilenameUtils.removeExtension(origFile.getName()).concat(fileSuffix).concat(ext); File retFile = new File(filename); if (retFile.exists()) { for (int i = 2; i < 1000; i++) { retFile = new File(filename.concat("_" + i)); if (!retFile.exists()) { break; }//from w w w .java 2 s.c o m } if (retFile.exists()) { String exSt = "Versioning failed: all filenames from " + filename + " to " + filename + "_999 already exist."; throw new IOException(exSt); } } return retFile; }
From source file:com.uwsoft.editor.data.manager.DataManager.java
public void importExternalSpriteAnimationsIntoProject(final ArrayList<File> files, ProgressHandler progressHandler) { if (files.size() == 0) { return;//from ww w . ja va2 s .c o m } handler = progressHandler; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { String newAnimName = null; String rawFileName = files.get(0).getName(); String fileExtension = FilenameUtils.getExtension(rawFileName); if (fileExtension.equals("png")) { Settings settings = new Settings(); settings.square = true; settings.flattenPaths = true; TexturePacker texturePacker = new TexturePacker(settings); FileHandle pngsDir = new FileHandle(files.get(0).getParentFile().getAbsolutePath()); for (FileHandle entry : pngsDir.list(new PngFilenameFilter())) { texturePacker.addImage(entry.file()); } String fileNameWithoutExt = FilenameUtils.removeExtension(rawFileName); String fileNameWithoutFrame = fileNameWithoutExt.replaceAll("\\d*$", ""); String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutFrame; File targetDir = new File(targetPath); if (targetDir.exists()) { try { FileUtils.deleteDirectory(targetDir); } catch (IOException e) { e.printStackTrace(); } } texturePacker.pack(targetDir, fileNameWithoutFrame); newAnimName = fileNameWithoutFrame; } else { for (File file : files) { try { ArrayList<File> imgs = getAtlasPages(file); String fileNameWithoutExt = FilenameUtils.removeExtension(file.getName()); String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutExt; File targetDir = new File(targetPath); if (targetDir.exists()) { FileUtils.deleteDirectory(targetDir); } for (File img : imgs) { FileUtils.copyFileToDirectory(img, targetDir); } FileUtils.copyFileToDirectory(file, targetDir); newAnimName = fileNameWithoutExt; } catch (IOException e) { e.printStackTrace(); } } } if (newAnimName != null) { resolutionManager.resizeSpriteAnimationForAllResolutions(newAnimName, currentProjectInfoVO); } } }); executor.execute(new Runnable() { @Override public void run() { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); } }); executor.shutdown(); }
From source file:com.holycityaudio.SpinCAD.SpinCADFile.java
public void fileSaveSpj(SpinCADBank bank) { // Create a file chooser String savedPath = prefs.get("MRUSpjFolder", ""); String[] spnFileNames = new String[8]; final JFileChooser fc = new JFileChooser(savedPath); // In response to a button click: FileNameExtensionFilter filter = new FileNameExtensionFilter("Spin Project Files", "spj"); fc.setFileFilter(filter);//from w w w .j ava2s . c o m // XXX debug fc.showSaveDialog(new JFrame()); File fileToBeSaved = fc.getSelectedFile(); if (!fc.getSelectedFile().getAbsolutePath().endsWith(".spj")) { fileToBeSaved = new File(fc.getSelectedFile() + ".spj"); } int n = JOptionPane.YES_OPTION; if (fileToBeSaved.exists()) { JFrame frame1 = new JFrame(); n = JOptionPane.showConfirmDialog(frame1, "Would you like to overwrite it?", "File already exists!", JOptionPane.YES_NO_OPTION); } if (n == JOptionPane.YES_OPTION) { // filePath points at the desired Spj file String filePath = fileToBeSaved.getPath(); String folder = fileToBeSaved.getParent().toString(); // export the individual SPN files for (int i = 0; i < 8; i++) { try { String asmFileNameRoot = FilenameUtils.removeExtension(bank.patch[i].patchFileName); String asmFileName = folder + "\\" + asmFileNameRoot + ".spn"; if (bank.patch[i].patchFileName != "Untitled") { fileSaveAsm(bank.patch[i], asmFileName); spnFileNames[i] = asmFileName; } } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!", "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } finally { } } // now create the Spin Project file fileToBeSaved.delete(); BufferedWriter writer = null; try { writer = new BufferedWriter(new FileWriter(fileToBeSaved, true)); } catch (IOException e1) { e1.printStackTrace(); } try { writer.write("NUMDOCS:8"); writer.newLine(); } catch (IOException e1) { e1.printStackTrace(); } for (int i = 0; i < 8; i++) { try { if (bank.patch[i].patchFileName != "Untitled") { writer.write(spnFileNames[i] + ",1"); } else { writer.write(",0"); } writer.newLine(); } catch (IOException e) { JOptionPane.showOptionDialog(null, "File save error!\n" + filePath, "Error", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); e.printStackTrace(); } } // write the build flags try { writer.write(",1,1,1"); writer.newLine(); } catch (IOException e1) { e1.printStackTrace(); } try { writer.close(); } catch (IOException e) { e.printStackTrace(); } saveMRUSpjFolder(filePath); } }
From source file:edu.ur.ir.repository.service.DefaultRepositoryService.java
/** * Add the file to the repository.// w w w . ja v a 2 s . c o m * @throws edu.ur.file.IllegalFileSystemNameException * * @see edu.ur.ir.repository.RepositoryService#addFileInfo(edu.ur.ir.repository.Repository, java.io.File, java.lang.String, java.lang.String, java.lang.String) */ public FileInfo createFileInfo(Repository repository, File f, String fileName, String description) throws edu.ur.file.IllegalFileSystemNameException { FileInfo info = fileServerService.addFile(repository.getFileDatabase(), f, uniqueNameGenerator.getNextName(), getExtension(fileName), FilenameUtils.removeExtension(fileName)); info.setDescription(description); return info; }