List of usage examples for org.apache.commons.io FilenameUtils getExtension
public static String getExtension(String filename)
From source file:de.tudarmstadt.ukp.dkpro.core.testing.IOTestRunner.java
public static void testOneWay(Class<? extends CollectionReader> aReader, Class<? extends AnalysisComponent> aWriter, String aExpectedFile, String aFile, Object... aExtraParams) throws Exception { Class<?> dkproReaderBase = Class.forName(RESOURCE_COLLECTION_READER_BASE); if (!dkproReaderBase.isAssignableFrom(aReader)) { throw new IllegalArgumentException( "Reader must be a subclass of [" + RESOURCE_COLLECTION_READER_BASE + "]"); }// ww w . ja va 2 s . c om Class<?> dkproWriterBase = Class.forName(JCAS_FILE_WRITER_IMPL_BASE); if (!dkproWriterBase.isAssignableFrom(aWriter)) { throw new IllegalArgumentException("writer must be a subclass of [" + JCAS_FILE_WRITER_IMPL_BASE + "]"); } // We assume that the writer is creating a file with the same extension as is provided as // the expected file String extension = FilenameUtils.getExtension(aExpectedFile); String name = FilenameUtils.getBaseName(aFile); testOneWay2(aReader, aWriter, aExpectedFile, name + "." + extension, aFile, aExtraParams); }
From source file:de.uzk.hki.da.convert.CLIConversionStrategy.java
/** * Convert file.// w w w. java 2s . c om * * @param ci the ci * @return the list * @throws FileNotFoundException the file not found exception */ @Override public List<Event> convertFile(WorkArea wa, ConversionInstruction ci) throws FileNotFoundException { if (pkg == null) throw new IllegalStateException("Package not set"); Path.make(wa.dataPath(), object.getNameOfLatestBRep(), ci.getTarget_folder()).toFile().mkdirs(); String[] commandAsArray = assemble(wa, ci, object.getNameOfLatestBRep()); if (!cliConnector.execute(commandAsArray)) throw new RuntimeException("convert did not succeed"); String targetSuffix = ci.getConversion_routine().getTarget_suffix(); if (targetSuffix.equals("*")) targetSuffix = FilenameUtils.getExtension(toAbsolutePath(wa.dataPath(), ci.getSource_file())); DAFile result = new DAFile(object.getNameOfLatestBRep(), ci.getTarget_folder() + "/" + FilenameUtils.removeExtension(Matcher.quoteReplacement( FilenameUtils.getName(toAbsolutePath(wa.dataPath(), ci.getSource_file())))) + "." + targetSuffix); Event e = new Event(); e.setType("CONVERT"); e.setDetail(StringUtilities.createString(commandAsArray)); e.setSource_file(ci.getSource_file()); e.setTarget_file(result); e.setDate(new Date()); List<Event> results = new ArrayList<Event>(); results.add(e); return results; }
From source file:com.doplgangr.secrecy.filesystem.encryption.AES_ECB_Crypter.java
@Override public CipherOutputStream getCipherOutputStream(File file, String outputFileName) throws SecrecyCipherStreamException, FileNotFoundException { Cipher c;//from w ww .j ava2 s . c om try { c = Cipher.getInstance(mode); } catch (NoSuchAlgorithmException e) { throw new SecrecyCipherStreamException("Encryption algorithm not found!"); } catch (NoSuchPaddingException e) { throw new SecrecyCipherStreamException("Selected padding not found!"); } try { c.init(Cipher.ENCRYPT_MODE, aesKey); } catch (InvalidKeyException e) { throw new SecrecyCipherStreamException("Invalid encryption key!"); } String filename = Base64Coder.encodeString(FilenameUtils.removeExtension(file.getName())) + "." + FilenameUtils.getExtension(file.getName()); File outputFile = new File(vaultPath + "/" + filename); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(outputFile), Config.BLOCK_SIZE); return new CipherOutputStream(bufferedOutputStream, c); }
From source file:ch.cyberduck.core.local.LaunchServicesApplicationFinder.java
@Override public List<Application> findAll(final String filename) { final String extension = FilenameUtils.getExtension(filename); if (StringUtils.isEmpty(extension)) { return Collections.emptyList(); }/*from w w w. j a va 2 s.co m*/ if (!defaultApplicationListCache.containsKey(extension)) { final List<Application> applications = new ArrayList<Application>(); for (String identifier : this.findAllForType(extension)) { applications.add(this.getDescription(identifier)); } // Because of the different API used the default opening application may not be included // in the above list returned. Always add the default application anyway. final Application defaultApplication = this.find(filename); if (this.isInstalled(defaultApplication)) { if (!applications.contains(defaultApplication)) { applications.add(defaultApplication); } } defaultApplicationListCache.put(extension, applications); } return defaultApplicationListCache.get(extension); }
From source file:com.masl.mp3Jukebox.SoundLoader.java
@SideOnly(Side.CLIENT) public void loadmusic() { File musicfile = null;/*w ww .jav a 2 s .co m*/ musicfile = new File(Minecraft.getMinecraft().mcDataDir, "music"); mp3Jukebox.logger.log(Level.INFO, "Music-Folder at: " + musicfile.getAbsolutePath()); musicfile.mkdirs(); mp3Player.resetMusicList(); int count = 0; for (File m : musicfile.listFiles()) { if (FilenameUtils.getExtension(m.getAbsolutePath()).equals("ogg") || FilenameUtils.getExtension(m.getAbsolutePath()).equals("mp3")) { mp3Player.addMusicTitle(m); count++; } } mp3Jukebox.logger.log(Level.INFO, "ADDED " + count + " Songs to Playlist."); }
From source file:com.qwazr.extractor.ParserInterface.java
/** * Read a document and fill the resultBuilder. * * @param parameters The optional parameters of the parser * @param filePath the path of the file instance of the document to parse * @param extension an optional extension of the file * @param mimeType an optional mime type of the file * @param resultBuilder the result builder to fill * @throws Exception if any error occurs *///from w w w.j ava 2 s . com default void parseContent(final MultivaluedMap<String, String> parameters, final Path filePath, String extension, final String mimeType, final ParserResultBuilder resultBuilder) throws Exception { if (extension == null) extension = FilenameUtils.getExtension(filePath.getFileName().toString()); try (final InputStream in = Files.newInputStream(filePath); final BufferedInputStream bIn = new BufferedInputStream(in);) { parseContent(parameters, bIn, extension, mimeType, resultBuilder); } }
From source file:com.br.helpdesk.controller.AttachmentsController.java
/** * download/*from w w w. j ava2 s . c o m*/ */ @RequestMapping(value = "/{attachmentId}", method = RequestMethod.GET) @ResponseBody public void downloadFile(HttpServletRequest request, HttpServletResponse response, @PathVariable(value = "attachmentId") Long attachmentId) throws Exception { Attachments attachment = attachmentsService.findById(attachmentId); String contentType = MimeTypeConstants.getMimeType(FilenameUtils.getExtension(attachment.getName())); response.setContentType(contentType); response.setContentLength(attachment.getByteArquivo().length); response.setHeader("Content-Disposition", "attachment; filename=\"" + attachment.getName() + "\""); FileCopyUtils.copy(attachment.getByteArquivo(), response.getOutputStream()); }
From source file:com.orange.ocara.model.export.docx.AuditDocxExporter.java
private void copyAuditObjectIcon(AuditObject auditObject, File iconDir) throws IOException { File from = new File(auditObject.getObjectDescription().getIcon()); String extension = FilenameUtils.getExtension(from.getPath()); File to = new File(iconDir, String.format("%s.%s", auditObject.getObjectDescriptionId(), extension)); FileUtils.copyFile(from, to);// ww w . ja va 2s .co m }
From source file:io.proleap.vb6.runner.impl.VbParseTestRunnerImpl.java
private boolean isStandardModule(final File inputFile) { final String extension = FilenameUtils.getExtension(inputFile.getName()); return "bas".equals(extension); }
From source file:com.willkara.zeteo.explorers.Explorer.java
public void namer(final File f, ConcurrentHashMap mapper) { String extension = FilenameUtils.getExtension(f.getName()); BaseFileType bft = new BaseFileType(f); if (extension.equals("")) { extension = "N/A"; }//ww w .ja v a 2 s .c o m List<BaseFileType> nameList = (List<BaseFileType>) mapper.get(extension); // if list does not exist create it if (nameList == null) { nameList = new ArrayList<>(); nameList.add(bft); mapper.put(extension, nameList); //System.out.println("Added new one to map."); } else { // add if item is not already in list if (!nameList.contains(bft)) { nameList.add(bft); } //System.out.println("Added to map."); } }