List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:au.com.redboxresearchdata.fascinator.harvester.MintJsonHarvester.java
private void updateHarvestFileKeyValue(JsonObject harvest, String key, String path, String base) { String value = FilenameUtils.concat(path, base); updateHarvestKeyValue(harvest, key, value); }
From source file:com.jaeksoft.searchlib.scheduler.task.TaskFtpXmlFeed.java
@Override public void execute(Client client, TaskProperties properties, Variables variables, TaskLog taskLog) throws SearchLibException { String server = properties.getValue(propServer); String path = properties.getValue(propPath); String login = properties.getValue(propLogin); String password = properties.getValue(propPassword); String fileNamePattern = properties.getValue(propFileNamePattern); boolean deleteAfterLoad = Boolean.TRUE.toString().equals(properties.getValue(propDeleteAfterLoad)); boolean truncateWhenFilesFound = Boolean.TRUE.toString() .equals(properties.getValue(propTruncateIndexWhenFilesFound)); Pattern pattern = null;// w ww. j a v a 2 s . c o m if (fileNamePattern != null && fileNamePattern.length() > 0) pattern = Pattern.compile(fileNamePattern); String p = properties.getValue(propBuffersize); String xsl = properties.getValue(propXsl); File xmlTempResult = null; int bufferSize = 50; if (p != null && p.length() > 0) bufferSize = Integer.parseInt(p); HttpDownloader httpDownloader = client.getWebCrawlMaster().getNewHttpDownloader(true); FTPClient ftp = null; InputStream inputStream = null; try { // FTP Connection ftp = new FTPClient(); checkConnect(ftp, server, login, password); FTPFile[] files = ftp.listFiles(path, new FtpFileInstance.FtpInstanceFileFilter(true, false, null)); if (files == null) return; // Sort by ascendant filename String[] fileNames = new String[files.length]; int i = 0; for (FTPFile file : files) fileNames[i++] = file.getName(); Arrays.sort(fileNames); int ignored = 0; int loaded = 0; boolean bAlreadyTruncated = false; for (String fileName : fileNames) { String filePathName = FilenameUtils.concat(path, fileName); if (pattern != null) if (!pattern.matcher(fileName).find()) { ignored++; continue; } if (truncateWhenFilesFound && !bAlreadyTruncated) { client.deleteAll(); bAlreadyTruncated = true; } taskLog.setInfo("Working on: " + filePathName); inputStream = ftp.retrieveFileStream(filePathName); Node xmlDoc = null; if (xsl != null && xsl.length() > 0) { xmlTempResult = File.createTempFile("ossftpfeed", ".xml"); DomUtils.xslt(new StreamSource(inputStream), xsl, xmlTempResult); xmlDoc = DomUtils.readXml(new StreamSource(xmlTempResult), false); } else xmlDoc = DomUtils.readXml(new StreamSource(inputStream), false); client.updateXmlDocuments(xmlDoc, bufferSize, null, httpDownloader, taskLog); client.deleteXmlDocuments(xmlDoc, bufferSize, taskLog); inputStream.close(); inputStream = null; if (!ftp.completePendingCommand()) throw new SearchLibException("FTP Error"); if (xmlTempResult != null) { xmlTempResult.delete(); xmlTempResult = null; } checkConnect(ftp, server, login, password); if (deleteAfterLoad) ftp.deleteFile(filePathName); loaded++; } taskLog.setInfo(loaded + " file(s) loaded - " + ignored + " file(s) ignored"); } catch (XPathExpressionException e) { throw new SearchLibException(e); } catch (NoSuchAlgorithmException e) { throw new SearchLibException(e); } catch (ParserConfigurationException e) { throw new SearchLibException(e); } catch (SAXException e) { throw new SearchLibException(e); } catch (IOException e) { throw new SearchLibException(e); } catch (URISyntaxException e) { throw new SearchLibException(e); } catch (InstantiationException e) { throw new SearchLibException(e); } catch (IllegalAccessException e) { throw new SearchLibException(e); } catch (ClassNotFoundException e) { throw new SearchLibException(e); } catch (TransformerException e) { throw new SearchLibException(e); } finally { if (xmlTempResult != null) xmlTempResult.delete(); IOUtils.close(inputStream); try { if (ftp != null) if (ftp.isConnected()) ftp.disconnect(); } catch (IOException e) { Logging.warn(e); } if (httpDownloader != null) httpDownloader.release(); } }
From source file:edu.cornell.med.icb.goby.alignments.TestMerge.java
@Test public void testMerge2() throws IOException { final Merge merger = new Merge(3); final List<File> inputFiles; final String outputFile; final String basename; final int count; inputFiles = new ArrayList<File>(); inputFiles.add(new File(FilenameUtils.concat(BASE_TEST_DIR, "align-101"))); inputFiles.add(new File(FilenameUtils.concat(BASE_TEST_DIR, "align-101"))); outputFile = FilenameUtils.concat(BASE_TEST_DIR, "out-103-merged"); merger.setK(3);/* www . j av a 2 s . c om*/ merger.merge(inputFiles, outputFile); // With k=3 and twice the same input file, the merge should keep twice the queries with best score: basename = outputFile; count = countAlignmentEntries(basename); assertEquals(numQueries101 * 2, count); }
From source file:com.perceptive.epm.perkolcentral.bl.ImageNowLicenseBL.java
@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.SERIALIZABLE, rollbackFor = ExceptionWrapper.class) public void cancelImageNowLicense(Imagenowlicenses imagenowlicenses) throws ExceptionWrapper { try {//from www .ja v a2 s. c o m imagenowlicenses = imageNowLicenseDataAccessor .getAllImageNowLicensesByRequestId(imagenowlicenses.getImageNowLicenseRequestId()); File filePathForThisRequest = new File( FilenameUtils.concat(fileUploadPath, imagenowlicenses.getImageNowLicenseRequestId())); imageNowLicenseDataAccessor.deleteImageNowLicense(imagenowlicenses); FileUtils.deleteQuietly(filePathForThisRequest); } catch (Exception ex) { throw new ExceptionWrapper(ex); } }
From source file:com.xiaomi.linden.core.TestMultiLindenCore.java
@Test public void testIndexNameDivision() throws Exception { String path = FilenameUtils.concat(INDEX_DIR, "name/"); lindenConfig.setIndexDirectory(path).setLindenCoreMode(LindenConfig.LindenCoreMode.MULTI) .setMultiIndexDivisionType(LindenConfig.MultiIndexDivisionType.INDEX_NAME); lindenCore = new MultiLindenCoreImpl(lindenConfig); for (int i = 0; i < 400; ++i) { JSONObject json = new JSONObject(); json.put("type", "index"); json.put("index", "multi_" + i / 50); JSONObject content = new JSONObject(); content.put("id", i); content.put("title", "test " + i); json.put("content", content); handleRequest(json.toJSONString()); }//from w ww. j a v a 2s .c o m lindenCore.commit(); lindenCore.refresh(); Assert.assertEquals(8, lindenCore.getServiceInfo().getIndexNamesSize()); Assert.assertEquals(400, lindenCore.getServiceInfo().getDocsNum()); String bql = "select * from linden source"; LindenSearchRequest request = bqlCompiler.compile(bql).getSearchRequest(); LindenResult result = lindenCore.search(request); Assert.assertEquals(400, result.getTotalHits()); bql = "select * from multi_0 source"; request = bqlCompiler.compile(bql).getSearchRequest(); result = lindenCore.search(request); Assert.assertEquals(50, result.getTotalHits()); bql = "select * from non-existed source"; request = bqlCompiler.compile(bql).getSearchRequest(); result = lindenCore.search(request); Assert.assertFalse(result.isSuccess()); bql = "select * from multi_1, multi_2 source"; request = bqlCompiler.compile(bql).getSearchRequest(); result = lindenCore.search(request); Assert.assertEquals(100, result.getTotalHits()); handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_0\"}"); bql = "select * from multi_0 source"; request = bqlCompiler.compile(bql).getSearchRequest(); result = lindenCore.search(request); Assert.assertFalse(result.isSuccess()); handleRequest("{\"type\":\"delete_index\", \"index\":\"multi_2\"}"); Assert.assertEquals(6, lindenCore.getServiceInfo().getIndexNamesSize()); Assert.assertEquals(300, lindenCore.getServiceInfo().getDocsNum()); // delete doc 50, 200, 300, 390, 397, doc 0 and doc 100 doesn't exist since multi_0 and multi_1 index are deleted bql = "delete from linden where query is 'title:0 title:50 title:100 title:200 title:300 title:390 title:397'"; LindenDeleteRequest deleteRequest = bqlCompiler.compile(bql).getDeleteRequest(); lindenCore.delete(deleteRequest); lindenCore.commit(); lindenCore.refresh(); Assert.assertEquals(295, lindenCore.getServiceInfo().getDocsNum()); lindenCore.close(); }
From source file:edu.cornell.med.icb.goby.modes.TestSplicedSamHelper.java
public void testSamToCompactTrickCase1() throws IOException { SAMToCompactMode importer = new SAMToCompactMode(); importer.setInputFile("test-data/splicedsamhelper/tricky-spliced.sam"); final String outputFilename = FilenameUtils.concat(BASE_TEST_DIR, "spliced-output-alignment-1"); importer.setOutputFile(outputFilename); importer.execute();// w w w . j a va2s. co m AlignmentReader reader = new AlignmentReaderImpl(outputFilename); assertTrue(reader.hasNext()); Alignments.AlignmentEntry first = reader.next(); assertEquals(0, first.getQueryIndex()); assertEquals(0, first.getFragmentIndex()); assertTrue(first.hasPairAlignmentLink()); assertTrue(first.hasSplicedForwardAlignmentLink()); Assert.assertEquals(1, first.getSplicedForwardAlignmentLink().getFragmentIndex()); Assert.assertEquals(2, first.getPairAlignmentLink().getFragmentIndex()); assertFalse(first.hasSplicedBackwardAlignmentLink()); Alignments.AlignmentEntry second = reader.next(); assertEquals(0, second.getQueryIndex()); assertEquals(1, second.getFragmentIndex()); assertTrue(second.hasPairAlignmentLink()); Assert.assertEquals(2, second.getPairAlignmentLink().getFragmentIndex()); assertFalse(second.hasSplicedForwardAlignmentLink()); assertTrue(second.hasSplicedBackwardAlignmentLink()); Assert.assertEquals(0, second.getSplicedBackwardAlignmentLink().getFragmentIndex()); Alignments.AlignmentEntry third = reader.next(); assertEquals(0, third.getQueryIndex()); assertEquals(2, third.getFragmentIndex()); assertTrue(third.hasPairAlignmentLink()); Assert.assertEquals(1, third.getPairAlignmentLink().getFragmentIndex()); assertFalse(third.hasSplicedBackwardAlignmentLink()); assertTrue(third.hasSplicedForwardAlignmentLink()); Assert.assertEquals(3, third.getSplicedForwardAlignmentLink().getFragmentIndex()); Alignments.AlignmentEntry fourth = reader.next(); assertEquals(0, fourth.getQueryIndex()); assertEquals(3, fourth.getFragmentIndex()); assertTrue(fourth.hasPairAlignmentLink()); Assert.assertEquals(1, fourth.getPairAlignmentLink().getFragmentIndex()); assertTrue(fourth.hasSplicedBackwardAlignmentLink()); Assert.assertEquals(2, fourth.getSplicedBackwardAlignmentLink().getFragmentIndex()); assertFalse(fourth.hasSplicedForwardAlignmentLink()); }
From source file:com.mbrlabs.mundus.assets.EditorAssetManager.java
public PixmapTextureAsset createPixmapTextureAsset(int size) throws IOException { String pixmapFilename = "pixmap_" + UUID.randomUUID().toString() + ".png"; String metaFilename = pixmapFilename + ".meta"; // create meta file String metaPath = FilenameUtils.concat(rootFolder.path(), metaFilename); MetaFile meta = createNewMetaFile(new FileHandle(metaPath), AssetType.PIXMAP_TEXTURE); // create pixmap String pixmapPath = FilenameUtils.concat(rootFolder.path(), pixmapFilename); Pixmap pixmap = new Pixmap(size, size, Pixmap.Format.RGBA8888); FileHandle pixmapAssetFile = new FileHandle(pixmapPath); PixmapIO.writePNG(pixmapAssetFile, pixmap); pixmap.dispose();// w ww . ja v a2s. c om // load & return asset PixmapTextureAsset asset = new PixmapTextureAsset(meta, pixmapAssetFile); asset.load(); addAsset(asset); return asset; }
From source file:edu.kit.dama.util.SystemUtils.java
/** * Generate the open script for Unix systems. * * @return The full path to the open script. * * @throws IOException If the generation fails. *///from w ww . ja va 2s . c om private static String generateOpenScript() throws IOException { String scriptFile; FileWriter fout = null; try { scriptFile = FilenameUtils.concat(System.getProperty("java.io.tmpdir"), "stickFolder.sh"); fout = new FileWriter(scriptFile, false); StringBuilder b = new StringBuilder(); b.append("#!/bin/sh\n"); b.append("echo Changing access of $1 to 2770\n"); b.append("chmod 2770 $1 -R\n"); LOGGER.debug("Writing script data to '{}'", scriptFile); fout.write(b.toString()); fout.flush(); } finally { if (fout != null) { try { fout.close(); } catch (IOException ioe) {//ignore } } } return scriptFile; }
From source file:com.cloudant.sync.datastore.DatastoreManager.java
private String getDatastoreDirectory(String dbName) { return FilenameUtils.concat(this.path, dbName); }
From source file:com.xiaomi.linden.core.search.HotSwapLindenCoreImpl.java
@Override public synchronized Response swapIndex(String indexName) throws IOException { if (Strings.isNullOrEmpty(indexName)) { throw new IOException("Index name is empty in swap index request."); }//from w w w . j a va2 s. c om if (!indexName.startsWith(NEXT_INDEX_NAME_PREFIX)) { throw new IOException("Invalid index name: " + indexName); } // May receive swap request more than one times String nextIndexVersion = indexName.substring(NEXT_INDEX_NAME_PREFIX.length()); if (!currentIndexVersion.equals(nextIndexVersion)) { LOGGER.info("Begin swapping index " + indexName); if (!lindenCoreMap.containsKey(indexName)) { LOGGER.error("No index found for: " + indexName); return ResponseUtils.buildFailedResponse("No index found for: " + indexName); } if (lindenConfig.getIndexType() != LindenConfig.IndexType.RAM) { LindenCore nextCore = lindenCoreMap.remove(indexName); nextCore.close(); String dir = FilenameUtils.concat(baseIndexDir, indexName); String newIndexName = indexName.replaceFirst(NEXT_INDEX_NAME_PREFIX, CURRENT_INDEX_NAME_PREFIX); String destDir = FilenameUtils.concat(baseIndexDir, newIndexName); FileUtils.moveDirectory(new File(dir), new File(destDir)); LOGGER.info("Move " + dir + " directory to " + destDir); nextCore = getLindenCore(newIndexName); // swap String lastIndexName = currentIndexName; String lastIndexVersion = currentIndexVersion; currentLindenCore = nextCore; currentIndexName = newIndexName; currentIndexVersion = nextIndexVersion; // remove last core from map LindenCore lastCore = lindenCoreMap.remove(lastIndexName); // close last core lastCore.close(); // mark last core expired dir = FilenameUtils.concat(baseIndexDir, lastIndexName); destDir = FilenameUtils.concat(baseIndexDir, EXPIRED_INDEX_NAME_PREFIX + lastIndexVersion); FileUtils.moveDirectory(new File(dir), new File(destDir)); LOGGER.info("Expire index: " + lastIndexName); File[] files = getIndexDirectories(EXPIRED_INDEX_NAME_PREFIX); if (files != null && files.length > MAX_EXPIRED_INDEX_NUM) { File oldestExpiredIndexDir = files[files.length - 1]; FileUtils.deleteQuietly(oldestExpiredIndexDir); LOGGER.info("Delete expired index: " + oldestExpiredIndexDir.getName()); } } else { // RAM type // swap String lastIndexName = currentIndexName; currentLindenCore = lindenCoreMap.get(indexName); currentIndexName = indexName; // remove last core from map LindenCore lastCore = lindenCoreMap.remove(lastIndexName); // close last core lastCore.close(); } LOGGER.info("Swapping index " + indexName + " done"); } return ResponseUtils.SUCCESS; }