List of usage examples for org.apache.commons.io FilenameUtils getFullPath
public static String getFullPath(String filename)
From source file:net.sf.zekr.common.config.ApplicationConfig.java
@SuppressWarnings("unchecked") public AudioData loadAudioData(File audioFile, boolean convertOldFormat) throws FileNotFoundException, UnsupportedEncodingException, ConfigurationException, IOException { PropertiesConfiguration pc = ConfigUtils.loadConfig(audioFile, "UTF-8"); AudioData audioData;/* www . j a v a2 s . co m*/ audioData = new AudioData(); audioData.id = pc.getString("audio.id"); audioData.file = audioFile; // note that audio.version should be made up of digits and dots only, so 0.7.5beta1 is invalid. audioData.version = pc.getString("audio.version"); if (StringUtils.isBlank(audioData.version)) { // old format logger.warn("Not a valid recitation file. No version specified: " + audioFile); if (convertOldFormat) { logger.info("Will try to convert recitation file: " + audioFile); audioData = RecitationPackConverter.convert(audioFile); if (audioData == null) { logger.info("Conversion failed for " + audioFile); return null; } File destDir = new File( FilenameUtils.getFullPath(audioFile.getAbsolutePath()) + "old-recitation-files"); logger.info(String.format("Move %s to %s.", audioFile, destDir)); FileUtils.moveFileToDirectory(audioFile, destDir, true); Writer w = new FileWriter(audioFile); StringWriter sw = new StringWriter(); audioData.save(sw); w.write(sw.toString()); IOUtils.closeQuietly(w); return audioData; } else { return null; } } else if (CommonUtils.compareVersions(audioData.version, AudioData.BASE_VALID_VERSION) < 0) { logger.warn(String.format( "Version is not supported anymore: %s. Zekr supports a recitation file of version %s or newer.", audioData.version, AudioData.BASE_VALID_VERSION)); return null; } audioData.lastUpdate = pc.getString("audio.lastUpdate"); audioData.quality = pc.getString("audio.quality", "?"); // audioData.name = pc.getString("audio.name"); audioData.license = pc.getString("audio.license"); audioData.locale = new Locale(pc.getString("audio.language"), pc.getString("audio.country")); audioData.type = pc.getString("audio.type", "online"); audioData.setLanguage(audioData.locale.getDisplayLanguage());//this will make it accessible from LocateResource super class. audioData.loadLocalizedNames(pc, "audio.reciter"); Iterator<String> keys = pc.getKeys("audio.reciter"); while (keys.hasNext()) { String key = keys.next(); if (key.equals("audio.reciter")) { continue; } String lang = key.substring("audio.reciter".length() + 1); audioData.localizedNameMap.put(lang, pc.getString(key)); } audioData.offlineUrl = pc.getString("audio.offlineUrl"); audioData.onlineUrl = pc.getString("audio.onlineUrl"); audioData.onlineAudhubillah = pc.getString("audio.onlineAudhubillah"); // keep backward compatibility for old typo in files (bismillam instead of bismillah) audioData.onlineBismillah = pc.getString("audio.onlineBismillah", pc.getString("audio.onlineBismillam")); // keep backward compatibility for old typo in files (saghaghallah instead of sadaghallah) audioData.onlineSadaghallah = pc.getString("audio.onlineSadaghallah", pc.getString("audio.onlineSaghaghallah")); audioData.offlineAudhubillah = pc.getString("audio.offlineAudhubillah"); // keep backward compatibility for old typo in files (bismillam instead of bismillah) audioData.offlineBismillah = pc.getString("audio.offlineBismillah", pc.getString("audio.offlineBismillam")); // keep backward compatibility for old typo in files (saghaghallah instead of sadaghallah) audioData.offlineSadaghallah = pc.getString("audio.offlineSadaghallah", pc.getString("audio.offlineSaghaghallah")); return audioData; }
From source file:MSUmpire.DIA.DIAPack.java
public boolean MGFgenerated() { if (new File(FilenameUtils.getFullPath(Filename) + GetQ3Name() + ".mgf").exists()) { return true; }//from w ww . j a v a 2s . c o m return false; }
From source file:MSUmpire.DIA.DIAPack.java
private void RemoveMGF() { String mgffile = FilenameUtils.getFullPath(Filename) + GetQ1Name() + ".mgf"; String mgffile2 = FilenameUtils.getFullPath(Filename) + GetQ2Name() + ".mgf"; String mgffile3 = FilenameUtils.getFullPath(Filename) + GetQ3Name() + ".mgf"; File file = new File(mgffile); if (file.exists()) { file.delete();// w ww.j a v a 2s .co m } file = new File(mgffile2); if (file.exists()) { file.delete(); } file = new File(mgffile3); if (file.exists()) { file.delete(); } mgffile = FilenameUtils.getFullPath(Filename) + GetQ1Name() + ".mgf.temp"; mgffile2 = FilenameUtils.getFullPath(Filename) + GetQ2Name() + ".mgf.temp"; mgffile3 = FilenameUtils.getFullPath(Filename) + GetQ3Name() + ".mgf.temp"; file = new File(mgffile); if (file.exists()) { file.delete(); } file = new File(mgffile2); if (file.exists()) { file.delete(); } file = new File(mgffile3); if (file.exists()) { file.delete(); } }
From source file:de.tudarmstadt.ukp.clarin.webanno.api.dao.RepositoryServiceDbData.java
@Override public void savePropertiesFile(Project aProject, InputStream aIs, String aFileName) throws IOException { String path = dir.getAbsolutePath() + PROJECT + aProject.getId() + "/" + FilenameUtils.getFullPath(aFileName); FileUtils.forceMkdir(new File(path)); File newTcfFile = new File(path, FilenameUtils.getName(aFileName)); OutputStream os = null;//from w ww .ja v a 2s . c om try { os = new FileOutputStream(newTcfFile); copyLarge(aIs, os); } finally { closeQuietly(os); closeQuietly(aIs); } }
From source file:MSUmpire.DIA.DIAPack.java
private void RenameMGF(String tag) { String mgffile = FilenameUtils.getFullPath(Filename) + GetQ1Name() + ".mgf.temp"; String mgffile2 = FilenameUtils.getFullPath(Filename) + GetQ2Name() + ".mgf.temp"; String mgffile3 = FilenameUtils.getFullPath(Filename) + GetQ3Name() + ".mgf.temp"; File file = new File(mgffile); if (file.exists()) { file.renameTo(new File(file.getAbsolutePath().replace(".mgf.temp", tag + ".mgf"))); }//from ww w.j ava 2 s . c om file = new File(mgffile2); if (file.exists()) { file.renameTo(new File(file.getAbsolutePath().replace(".mgf.temp", tag + ".mgf"))); } file = new File(mgffile3); if (file.exists()) { file.renameTo(new File(file.getAbsolutePath().replace(".mgf.temp", tag + ".mgf"))); } }
From source file:it.drwolf.ridire.session.JobManager.java
public void retrieveCleanedText(CrawledResource cr) { File resourceDir = new File( FilenameUtils.getFullPath(cr.getArcFile().replaceAll("__\\d+", "")) + JobManager.RESOURCESDIR); File cleanedTextFile = new File(resourceDir, cr.getDigest() + ".txt"); if (cleanedTextFile.exists() && cleanedTextFile.canRead()) { try {/* w w w.j a v a2s . co m*/ this.setCleanedText(FileUtils.readFileToString(cleanedTextFile)); } catch (IOException e) { e.printStackTrace(); } } else { this.setCleanedText(""); } }
From source file:it.drwolf.ridire.session.JobManager.java
public void retrievePoSText(CrawledResource cr) { File resourceDir = new File( FilenameUtils.getFullPath(cr.getArcFile().replaceAll("__\\d+", "")) + JobManager.RESOURCESDIR); File posTextFile = new File(resourceDir, cr.getDigest() + ".txt.pos"); List<PoSLine> posLines = new ArrayList<PoSLine>(); try {//from w ww.j ava2 s. co m List<String> lines = FileUtils.readLines(posTextFile); StrTokenizer tokenizer = StrTokenizer.getTSVInstance(); for (String l : lines) { tokenizer.reset(l); String[] tokens = tokenizer.getTokenArray(); if (tokens.length == 3) { PoSLine poSLine = new PoSLine(); poSLine.setForm(tokens[0].trim()); poSLine.setPosTag(tokens[1].trim()); poSLine.setLemma(tokens[2].trim()); posLines.add(poSLine); } } } catch (IOException e) { } this.setPosText(posLines); }
From source file:com.mirth.connect.cli.CommandLineInterface.java
private void commandExportMessages(Token[] arguments) { if (hasInvalidNumberOfArguments(arguments, 2)) { return;/*w ww .j a va 2 s .com*/ } // file path String path = arguments[1].getText(); File fXml = new File(path); // message filter MessageFilter filter = new MessageFilter(); String channelId = arguments[2].getText(); // export mode ContentType contentType = null; boolean includeAttachments = false; if (arguments.length >= 4) { String modeArg = arguments[3].getText(); if (StringUtils.equals(modeArg, "raw")) { contentType = ContentType.RAW; } else if (StringUtils.equals(modeArg, "processedraw")) { contentType = ContentType.PROCESSED_RAW; } else if (StringUtils.equals(modeArg, "transformed")) { contentType = ContentType.TRANSFORMED; } else if (StringUtils.equals(modeArg, "encoded")) { contentType = ContentType.ENCODED; } else if (StringUtils.equals(modeArg, "sent")) { contentType = ContentType.SENT; } else if (StringUtils.equals(modeArg, "response")) { contentType = ContentType.RESPONSE; } else if (StringUtils.equals(modeArg, "responsetransformed")) { contentType = ContentType.RESPONSE_TRANSFORMED; } else if (StringUtils.equals(modeArg, "processedresponse")) { contentType = ContentType.PROCESSED_RESPONSE; } else if (StringUtils.equals(modeArg, "xml-attach")) { includeAttachments = true; } } // page size int pageSize = 100; if (arguments.length == 5) { pageSize = NumberUtils.toInt(arguments[4].getText()); } int messageCount = 0; try { filter.setMaxMessageId(client.getMaxMessageId(channelId)); MessageWriter messageWriter = null; try { out.println("Exporting messages to file: " + fXml.getPath()); PaginatedMessageList messageList = new PaginatedMessageList(); messageList.setChannelId(channelId); messageList.setClient(client); messageList.setIncludeContent(true); messageList.setMessageFilter(filter); messageList.setPageSize(pageSize); MessageWriterOptions writerOptions = new MessageWriterOptions(); writerOptions.setBaseFolder(new File(".").getPath()); writerOptions.setContentType(contentType); writerOptions.setDestinationContent(false); writerOptions.setEncrypt(false); writerOptions.setRootFolder(FilenameUtils.getFullPath(fXml.getAbsolutePath())); writerOptions.setFilePattern(FilenameUtils.getName(fXml.getAbsolutePath())); writerOptions.setArchiveFormat(null); writerOptions.setCompressFormat(null); writerOptions.setIncludeAttachments(includeAttachments); messageWriter = MessageWriterFactory.getInstance().getMessageWriter(writerOptions, client.getEncryptor()); AttachmentSource attachmentSource = null; if (writerOptions.includeAttachments()) { attachmentSource = new AttachmentSource() { @Override public List<Attachment> getMessageAttachments(Message message) throws ClientException { return client.getAttachmentsByMessageId(message.getChannelId(), message.getMessageId()); } }; } messageCount = new MessageExporter().exportMessages(messageList, messageWriter, attachmentSource); messageWriter.finishWrite(); } catch (Exception e) { Throwable cause = ExceptionUtils.getRootCause(e); error("unable to write file(s) " + path + ": " + cause, cause); } finally { if (messageWriter != null) { try { messageWriter.close(); } catch (Exception e) { Throwable cause = ExceptionUtils.getRootCause(e); error("unable to close file(s) " + path + ": " + cause, cause); } } } } catch (Exception e) { Throwable cause = ExceptionUtils.getRootCause(e); error("Unable to retrieve max message ID: " + cause, cause); } out.println("Messages Export Complete. " + messageCount + " Messages Exported."); }
From source file:it.drwolf.ridire.session.JobManager.java
private void selectResourceToBeValidated(int amount, int startIdx, int endIdx, EntityManager entityManager2, Job j) throws NoSuchAlgorithmException, IOException { if (amount < 1) { return;/*from ww w . j ava2s . com*/ } List<Integer> ids = new ArrayList<Integer>(); Map<String, Integer> hashes = new HashMap<String, Integer>(); int cursize = hashes.size(); while (hashes.size() < amount) { for (CrawledResource cr : (List<CrawledResource>) entityManager2.createQuery( "from CrawledResource cr where cr.job=:j and cr.wordsNumber<:eidx and cr.wordsNumber>=:sidx and cr.deleted=false order by rand()") .setParameter("j", j).setParameter("sidx", startIdx).setParameter("eidx", endIdx) .setMaxResults(amount).getResultList()) { if (cr.getExtractedTextHash() == null) { File f = new File(FilenameUtils.getFullPath(cr.getArcFile()) + JobMapperMonitor.RESOURCESDIR + cr.getDigest() + ".txt"); if (f.exists() && f.canRead()) { cr.setExtractedTextHash(MD5DigestCreator.getMD5Digest(f)); entityManager2.merge(cr); } else { continue; } } hashes.put(cr.getExtractedTextHash(), cr.getId()); } if (cursize == hashes.size()) { break; } else { cursize = hashes.size(); } } ids.addAll(hashes.values()); if (ids.size() > 0) { entityManager2.createQuery("update CrawledResource cr set cr.validation=:v where cr.id in (:ids)") .setParameter("ids", ids).setParameter("v", CrawledResource.CHOOSEN_FOR_VALIDATION) .executeUpdate(); } }
From source file:com.abiquo.api.services.cloud.VirtualMachineService.java
/** * Performs an instance of type {@link SnapshotType#FROM_IMPORTED_VIRTUALMACHINE} * //w w w. ja va 2s .c o m * @param virtualAppliance {@link VirtualAppliance} where the {@link VirtualMachine} is * contained. * @param virtualMachine The {@link VirtualMachine} to instance. * @param originalState The original {@link VirtualMachineState}. * @param instanceName The final name of the {@link VirtualMachineTemplate} * @return The {@link Task} UUID for progress tracking */ private String instanceImportedVirtualMachine(final VirtualAppliance virtualAppliance, final VirtualMachine virtualMachine, final VirtualMachineState originalState, final String instanceName) { Datacenter datacenter = virtualMachine.getHypervisor().getMachine().getDatacenter(); // Create the folder structure in the destination repository String ovfPath = amService.preBundleTemplate(datacenter.getId(), virtualAppliance.getEnterprise().getId(), instanceName); // Do the instance String snapshotPath = FilenameUtils.getFullPath(ovfPath); String snapshotFilename = FilenameUtils.getName(virtualMachine.getVirtualMachineTemplate().getPath()); return tarantino.snapshotVirtualMachine(virtualAppliance, virtualMachine, originalState, instanceName, snapshotPath, snapshotFilename); }