List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:io.insideout.stanbol.enhancer.nlp.freeling.Freeling.java
@SuppressWarnings("unchecked") public Freeling(final String configurationPath, final String configurationFilenameSuffix, final String freelingSharePath, final String freelingLibPath, final String locale, final int maxInitThreads, final int poolSize, final int minQueueSize) { //determine the supported languages File configDir = new File(configurationPath); if (!configDir.isDirectory()) { throw new IllegalArgumentException( "The parsed configDirectory '" + configDir + "' is not a directory!"); }/*from w ww. j a v a 2s .c o m*/ log.info("Reading Freeling Configuration from Directory: {}", configDir); Map<String, File> supportedLanguages = new HashMap<String, File>(); String langIdConfigFile = null; if (configDir.isDirectory()) { for (File confFile : (Collection<File>) FileUtils.listFiles(configDir, new SuffixFileFilter(configurationFilenameSuffix), null)) { Properties prop = new Properties(); InputStream in = null; try { in = new FileInputStream(confFile); prop.load(in); String lang = prop.getProperty("Lang"); String langIdentFileName = prop.getProperty("LangIdentFile"); if (lang != null) { //not a Analyzer config File existing = supportedLanguages.get(lang); if (existing == null) { log.info(" ... adding language '{}' with config {}", lang, confFile); supportedLanguages.put(lang, confFile); } else { //two configs for the same language //take the one that is more similar to the language name int eld = StringUtils.getLevenshteinDistance(lang, FilenameUtils.getBaseName(existing.getName())); int cld = StringUtils.getLevenshteinDistance(lang, FilenameUtils.getBaseName(confFile.getName())); if (cld < eld) { log.info(" ... setting language '{}' to config {}", lang, confFile); supportedLanguages.put(lang, confFile); } } } else if (langIdentFileName != null) { if (langIdentFileName.startsWith("$FREELING")) { langIdentFileName = FilenameUtils.concat(freelingSharePath, langIdentFileName.substring(langIdentFileName.indexOf(File.separatorChar) + 1)); } if (langIdConfigFile != null) { log.warn( "Multiple LanguageIdentification configuration files. " + "Keep using '{}' and ignore '{}'!", langIdConfigFile, langIdentFileName); } else { log.info(" ... setting language identification config to '{}'", langIdentFileName); langIdConfigFile = langIdentFileName; } } } catch (IOException e) { log.error("Unable to read configuration file " + confFile, e); } finally { IOUtils.closeQuietly(in); } } } //init the ThreadPool used to create Freeling components //this is mainly needed for beeing able to ensure that only one Freeling //component is created at a time. This may be necessary in some //environment to avoid random crashes. freelingInitThreadPool = Executors .newFixedThreadPool(maxInitThreads <= 0 ? DEFAULT_CONCURRENT_THREADS : maxInitThreads); //Init the Analyzers if (supportedLanguages.isEmpty()) { log.warn("The parsed configDirectory '{}' does not contain any valid " + "language configuration (*.{}) files!", configDir, configurationFilenameSuffix); } else { AnalyzerFactory analyzerFactory = new AnalyzerFactory(freelingLibPath, freelingSharePath, locale, freelingInitThreadPool); //now init the ResourcePool(s) log.info("init ResourcePools (size: " + poolSize + ")"); for (Entry<String, File> supported : supportedLanguages.entrySet()) { Map<String, Object> context = new HashMap<String, Object>(); context.put(AnalyzerFactory.PROPERTY_LANGUAGE, supported.getKey()); context.put(AnalyzerFactory.PROPERTY_CONFIG_FILE, supported.getValue()); log.debug(" ... create ResourcePool for {}", context); analyzerPools.put(supported.getKey(), new ResourcePool<Analyzer>(poolSize, minQueueSize, analyzerFactory, context)); } } if (langIdConfigFile == null) { log.warn( "The parsed configDirectory '{}' does not contain the " + "Language Identification Component configuration (a *.{}) file! " + "Language Identification Service will not ba available.", configDir, configurationFilenameSuffix); langIdPool = null; } else { LangIdFactory langIdFactory = new LangIdFactory(freelingLibPath, langIdConfigFile, locale, freelingInitThreadPool); //Finally init the language identifier resource pool langIdPool = new ResourcePool<LanguageIdentifier>(poolSize, minQueueSize, langIdFactory, null); } }
From source file:com.abiquo.am.services.TemplateService.java
private TemplateDto fixFilePathWithRelativeTemplatePath(final TemplateDto ovfpi, final String relativePackagePath) { String diskPath = ovfpi.getDiskFilePath(); if (diskPath.startsWith("http://")) { diskPath = diskPath.substring(diskPath.lastIndexOf('/') + 1); }//w ww .j av a2 s . c o m ovfpi.setDiskFilePath(FilenameUtils.concat(relativePackagePath, diskPath)); return ovfpi; }
From source file:com.mbrlabs.mundus.core.kryo.KryoManager.java
/** * Loads a scene./*from www. j av a 2s . co m*/ * * Does however not initialize ModelInstances, Terrains, ... -> * ProjectManager * * @param context * project context of the scene * @param sceneName * name of the scene to load * @return loaded scene * @throws FileNotFoundException */ public SceneDescriptor loadScene(ProjectContext context, String sceneName) throws FileNotFoundException { String sceneDir = FilenameUtils.concat(context.path + "/" + ProjectManager.PROJECT_SCENES_DIR, sceneName + ProjectManager.PROJECT_SCENE_EXTENSION); Input input = new Input(new FileInputStream(sceneDir)); SceneDescriptor sceneDescriptor = kryo.readObjectOrNull(input, SceneDescriptor.class); return sceneDescriptor; }
From source file:com.stgmastek.core.logic.ExecutionOrder.java
/** * Saves the state of the batch for revision runs usage * If the current batch is 1000 and revision is 1 then the file would * be saved as '1000_1.savepoint' //from w w w . j ava 2s .co m * * @param batchContext * The job batchContext of the batch * @throws BatchException * Any exception occurred during the serialization process */ public static synchronized void saveBatchState(BatchContext batchContext) throws BatchException { BatchInfo toSaveBatchInfo = batchContext.getBatchInfo(); toSaveBatchInfo.setProgressLevelAtLastSavePoint( (ProgressLevel) ProgressLevel.getProgressLevel(toSaveBatchInfo.getBatchNo()).clone()); //clone is necessary as ProgresLevel is static if (logger.isDebugEnabled()) { logger.debug("Saving Current Batch progress level as ==>" + ProgressLevel.getProgressLevel(toSaveBatchInfo.getBatchNo()).toString()); } String savepointFilePath = Configurations.getConfigurations().getConfigurations("CORE", "SAVEPOINT", "DIRECTORY"); ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(new FileOutputStream(FilenameUtils.concat(savepointFilePath, toSaveBatchInfo.getBatchNo() + "_" + toSaveBatchInfo.getBatchRevNo() + ".savepoint"))); oos.writeObject(toSaveBatchInfo); oos.flush(); batchContext.setBatchStateSaved(true); } catch (FileNotFoundException e) { batchContext.setBatchStateSaved(false); logger.error(e); throw new BatchException(e.getMessage(), e); } catch (IOException e) { batchContext.setBatchStateSaved(false); logger.error(e); throw new BatchException(e.getMessage(), e); } finally { IOUtils.closeQuietly(oos); } }
From source file:edu.cornell.med.icb.goby.alignments.TestIterateSortedAlignment.java
@Test public void testIterateSortedTwoMutationsSmall() throws IOException { final String basename = "align-skip-to-1-concat-two-mutations-small"; final String basenamePath = FilenameUtils.concat(BASE_TEST_DIR, basename); final AlignmentWriterImpl writer = new AlignmentWriterImpl(basenamePath); writer.setNumAlignmentEntriesPerChunk(1); final int numTargets = 3; final int[] targetLengths = new int[numTargets]; for (int referenceIndex = 0; referenceIndex < numTargets; referenceIndex++) { targetLengths[referenceIndex] = 1000; }/*w w w . jav a 2s. co m*/ writer.setTargetLengths(targetLengths); // we write this alignment sorted: writer.setSorted(true); Alignments.AlignmentEntry.Builder newEntry; newEntry = prepareAlignmentEntry(0, 1, 100, 3, true, new int[] { 2, 4 }, 5); writer.appendEntry(newEntry.build()); writer.close(); writer.printStats(System.out); final IntSet variantReadIndices = new IntOpenHashSet(); final IntSet variantPositionOnRef = new IntOpenHashSet(); IterateSortedAlignmentsListImpl iterator = new IterateSortedAlignmentsListImpl() { public void processPositions(int referenceIndex, int intermediatePosition, DiscoverVariantPositionData positionBaseInfos) { } @Override public void observeVariantBase(ConcatSortedAlignmentReader sortedReaders, Alignments.AlignmentEntry alignmentEntry, Int2ObjectMap<DiscoverVariantPositionData> positionToBases, Alignments.SequenceVariation var, char toChar, char fromChar, byte toQual, int currentReferenceIndex, int currentRefPosition, int currentReadIndex) { variantReadIndices.add(currentReadIndex); variantPositionOnRef.add(currentRefPosition); } }; iterator.iterate(basenamePath); assertTrue(variantReadIndices.contains(2)); assertTrue(variantReadIndices.contains(4)); assertTrue(variantPositionOnRef.contains(101)); assertTrue(variantPositionOnRef.contains(103)); }
From source file:es.urjc.mctwp.bbeans.research.image.SelectImagesToImport.java
/** * Retrieve thumbnails from temp collection and stores its content * into web context user folder. It cleans previous images. *//* www. ja v a 2 s . c o m*/ private void populateThumbNails() { List<ThumbNail> aux = null; getSession().cleanUserTempDirectory(); Command cmd = getCommand(LoadThumbsOfTemporalImages.class); ((LoadThumbsOfTemporalImages) cmd).setTempColl(folder); cmd = runCommand(cmd); aux = ((LoadThumbsOfTemporalImages) cmd).getResult(); if (aux != null) { thumbs = new ArrayList<ThumbSelectItem>(); for (ThumbNail tn : aux) { //Copy content from collection to web context user folder try { FileUtils.copyFileToDirectory(tn.getContent(), getSession().getThumbDir()); File th = new File( FilenameUtils.concat(getSession().getRelativeThumbDir(), tn.getContent().getName())); tn.setContent(th); ThumbSelectItem tsi = new ThumbSelectItem(); tsi.setThumbId(tn.getId()); tsi.setPath(tn.getContent().getPath()); if (tn.getPatInfo() != null) { tsi.setPatName(tn.getPatInfo().getName()); tsi.setPatCode(tn.getPatInfo().getCode()); tsi.setStdCode(tn.getPatInfo().getStudy()); } thumbs.add(tsi); } catch (IOException e) { } } Collections.sort(thumbs); } }
From source file:edu.cornell.med.icb.goby.alignments.TestSkipTo.java
@Test public void testFewSkips2() throws IOException { final String basename = "align-skip-to-2"; final AlignmentWriterImpl writer = new AlignmentWriterImpl(FilenameUtils.concat(BASE_TEST_DIR, basename)); writer.setNumAlignmentEntriesPerChunk(numEntriesPerChunk); final int numTargets = 3; final int[] targetLengths = new int[numTargets]; for (int referenceIndex = 0; referenceIndex < numTargets; referenceIndex++) { targetLengths[referenceIndex] = 1000; }/*from w ww .j a v a2 s . c om*/ writer.setTargetLengths(targetLengths); // we write this alignment sorted: writer.setSorted(true); writer.setAlignmentEntry(0, 1, 12, 30, false, constantQueryLength); writer.appendEntry(); writer.setAlignmentEntry(0, 1, 13, 30, false, constantQueryLength); writer.appendEntry(); writer.setAlignmentEntry(0, 1, 13, 30, false, constantQueryLength); writer.appendEntry(); writer.setAlignmentEntry(0, 2, 123, 30, false, constantQueryLength); writer.appendEntry(); writer.setAlignmentEntry(0, 2, 300, 30, false, constantQueryLength); writer.appendEntry(); writer.setAlignmentEntry(0, 2, 300, 30, false, constantQueryLength); writer.appendEntry(); writer.close(); writer.printStats(System.out); final AlignmentReader reader = new AlignmentReaderImpl(FilenameUtils.concat(BASE_TEST_DIR, basename)); final Alignments.AlignmentEntry c = reader.skipTo(2, 0); assertEquals(2, c.getTargetIndex()); assertEquals(123, c.getPosition()); final Alignments.AlignmentEntry d = reader.skipTo(2, 300); assertEquals(2, d.getTargetIndex()); assertEquals(300, d.getPosition()); final Alignments.AlignmentEntry e = reader.skipTo(2, 300); assertEquals(2, e.getTargetIndex()); assertEquals(300, e.getPosition()); assertFalse(reader.hasNext()); }
From source file:com.r573.enfili.ws.client.WsRestClient.java
public File postAndDownloadFile(String path, Object postObj, File downloadDir, ArrayList<String> acceptTypes) { String postObjJson = JsonHelper.toJson(postObj); log.debug("POST JSON " + postObjJson); WebResource.Builder builder = jerseyClient.resource(baseUrl + path).type(MediaType.APPLICATION_JSON_TYPE); builder = addAcceptTypes(builder, acceptTypes); builder = addCookies(builder);//from w w w.j a va 2 s.com ClientResponse response = getResource(path, new HashMap<String, String>()).post(ClientResponse.class, postObjJson); log.debug("status=" + response.getStatus()); String receivedType = response.getHeaders().getFirst("Content-Type"); if (receivedType == null) { log.error("Null Content-Type returned from the server"); return null; } else if (receivedType.equalsIgnoreCase("application/json")) { log.error("Failed to download file with error response " + response.getEntity(String.class)); return null; } else { String contentDisposition = response.getHeaders().getFirst("Content-Disposition"); String fileName = null; if ((contentDisposition != null) && (contentDisposition.startsWith("attachment"))) { String[] split1 = contentDisposition.split(";"); String[] split2 = split1[1].split("="); fileName = split2[1].trim(); if (fileName.startsWith("\"")) { fileName = fileName.substring(1, fileName.length() - 1); } } else { fileName = UUID.randomUUID().toString(); } File fileToSave = new File(FilenameUtils.concat(downloadDir.getPath(), fileName)); InputStream inputStream = response.getEntityInputStream(); try { FileUtils.copyInputStreamToFile(inputStream, fileToSave); return fileToSave; } catch (IOException e) { log.error(StringHelper.stackTraceToString(e)); return null; } } }
From source file:net.bpelunit.framework.control.deploy.ode.ODEDeployer.java
private String getArchiveLocation(String pathToTest) { String pathToArchive = FilenameUtils.concat(pathToTest, FilenameUtils.getFullPath(fArchive)); String archiveName = FilenameUtils.getName(fArchive); return FilenameUtils.concat(pathToArchive, archiveName); }
From source file:com.abiquo.am.services.TemplateConventions.java
/** * Create a path in the Enterprise Repository based on the OVF location. Codify the hostname and * the path to the root folder. ej (wwww.abiquo.com/ovfindex/package1/envelope.ovf -> * enterpriseRepo/www.abiquo.com/ovfindex/package1 ) * /*from ww w. ja v a 2s . c o m*/ * @return the path where the OVF will be deployed into the current enterprise repository. */ public static String getTemplatePath(final String enterpriseRepositoryPath, final String ovfid) { return FilenameUtils.concat(enterpriseRepositoryPath, getRelativePackagePath(ovfid)); }