List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:edu.cornell.med.icb.goby.alignments.TestIterateSortedAlignment.java
@Test public void testIterateSorted() throws IOException { final String basename = "align-skip-to-1-concat"; 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; }//from w ww. ja v a 2 s .co m writer.setTargetLengths(targetLengths); // we write this alignment sorted: writer.setSorted(true); Alignments.AlignmentEntry.Builder newEntry; newEntry = prepareAlignmentEntry(0, 1, 1, 30, false, new int[0]); writer.appendEntry(newEntry.build()); newEntry = prepareAlignmentEntry(0, 1, 130, 30, false, new int[] { 11, 12 }); writer.appendEntry(newEntry.build()); newEntry = prepareAlignmentEntry(0, 1, 135, 35, false, new int[] { 6 }); writer.appendEntry(newEntry.build()); newEntry = prepareAlignmentEntry(0, 2, 1230, 30, false, new int[0]); writer.appendEntry(newEntry.build()); newEntry = prepareAlignmentEntry(0, 2, 3000, 30, false, new int[0]); writer.appendEntry(newEntry.build()); writer.close(); writer.printStats(System.out); final Int2IntMap positionMap = new Int2IntOpenHashMap(); IterateSortedAlignmentsListImpl iterator = new IterateSortedAlignmentsListImpl() { @Override public void processPositions(int referenceIndex, int intermediatePosition, DiscoverVariantPositionData positionBaseInfos) { // store one-based positions: positionMap.put(intermediatePosition + 1, positionBaseInfos.size()); System.out.printf("position: %d listSize: %d%n", referenceIndex, positionBaseInfos.size()); } }; iterator.iterate(basenamePath); for (int i = 1; i < 35; i++) { assertEquals("[i=" + i + "] position " + i, 1, positionMap.get(i)); } for (int i = 130; i < 135; i++) { assertEquals("[i=" + i + "] position " + i, 1, positionMap.get(i)); } for (int i = 135; i < 165; i++) { assertEquals("[i=" + i + "] position " + i, 2, positionMap.get(i)); } for (int i = 165; i < 170; i++) { assertEquals("[i=" + i + "] position " + i, 1, positionMap.get(i)); } for (int i = 1230; i < 1265; i++) { assertEquals("[i=" + i + "] position " + i, 1, positionMap.get(i)); } for (int i = 3000; i < 3035; i++) { assertEquals("[i=" + i + "] position " + i, 1, positionMap.get(i)); } }
From source file:io.wcm.devops.conga.generator.util.FileUtil.java
/** * Get template path for a role file.//ww w . j a va2 s.c o m * @param role Role * @param roleFile Role file * @return Path or null if not defined */ public static String getTemplatePath(Role role, RoleFile roleFile) { String path = roleFile.getTemplate(); if (StringUtils.isEmpty(path)) { return null; } if (StringUtils.isNotEmpty(role.getTemplateDir())) { path = FilenameUtils.concat(role.getTemplateDir(), path); } return path; }
From source file:biz.dfch.j.graylog.plugin.filter.metricsValidation.java
public metricsValidation() throws IOException, URISyntaxException { try {//from ww w .j a v a2 s. co m LOG.debug(String.format("[%d] Initialising plugin ...\r\n", Thread.currentThread().getId())); // get config file CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource(); URI uri = codeSource.getLocation().toURI(); // String path = uri.getSchemeSpecificPart(); // path would contain absolute path including jar file name with extension // String path = FilenameUtils.getPath(uri.getPath()); // path would contain relative path (no leading '/' and no jar file name String path = FilenameUtils.getPath(uri.getPath()); if (!path.startsWith("/")) { path = String.format("/%s", path); } String baseName = FilenameUtils.getBaseName(uri.getSchemeSpecificPart()); if (null == baseName || baseName.isEmpty()) { baseName = this.getClass().getPackage().getName(); } // get config values configurationFileName = FilenameUtils.concat(path, baseName + ".conf"); JSONParser jsonParser = new JSONParser(); LOG.info(String.format("Loading configuration file '%s' ...", configurationFileName)); Object object = jsonParser.parse(new FileReader(configurationFileName)); JSONObject jsonObject = (JSONObject) object; String pluginPriority = (String) jsonObject.get(DF_PLUGIN_PRIORITY); Boolean pluginDropMessage = (Boolean) jsonObject.get(DF_PLUGIN_DROP_MESSAGE); Boolean pluginDisabled = (Boolean) jsonObject.get(DF_PLUGIN_DISABLED); // metrics = (HashMap) jsonObject.get("metrics"); // String fieldName = "cpu.average"; // Set<String> keys = metrics.keySet(); // for(String key : keys) // { // Map metric = (Map) metrics.get(key); // LOG.info(String.format("%s [type %s] [range %s .. %s]", key, metric.get("type").toString(), metric.get("minValue").toString(), metric.get("maxValue").toString())); // } // set configuration Map<String, Object> map = new HashMap<>(); map.put(DF_PLUGIN_PRIORITY, pluginPriority); map.put(DF_PLUGIN_DROP_MESSAGE, pluginDropMessage); map.put(DF_PLUGIN_DISABLED, pluginDisabled); //map.put(DF_PLUGIN_METRICS, metrics); initialize(new Configuration(map)); } catch (IOException ex) { LOG.error(String.format("[%d] Initialising plugin FAILED. Filter will be disabled.\r\n%s\r\n", Thread.currentThread().getId(), ex.getMessage())); LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - IOException - Filter will be disabled."); ex.printStackTrace(); } catch (Exception ex) { LOG.error(String.format("[%d] Initialising plugin FAILED. Filter will be disabled.\r\n", Thread.currentThread().getId())); LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - Exception - Filter will be disabled."); ex.printStackTrace(); } }
From source file:com.abiquo.am.services.DiskFileServiceImpl.java
/** * Or return DISK_FILE_NOT_FOUND/*ww w . j a va 2 s . co m*/ */ private File getFile(final String path) { File file = new File(FilenameUtils.concat(repositoryPath, path)); if (!file.exists()) { throw new AMException(AMError.DISK_FILE_NOT_FOUND, path); } return file; }
From source file:net.sf.jvifm.Main.java
public static boolean createFileLock() { File lockFile = new File(FilenameUtils.concat(HomeLocator.getConfigHome(), ".lock")); try {//from ww w .j a v a2s . c o m FileChannel channel = new RandomAccessFile(lockFile, "rw").getChannel(); fileLock = channel.tryLock(); if (fileLock != null) { return true; } } catch (Exception e) { } return false; }
From source file:net.ageto.gyrex.impex.console.internal.ImpexConsoleCommands.java
/** * Reads properties from file//from w w w . j av a 2 s . c o m * * @param configSourcePath * @param context * @return */ public static boolean initPropertiesFile(String configSourcePath, IRuntimeContext context) { String propertiesFilename = FilenameUtils.concat(configSourcePath, DEFAULT_PROPERY_FILENAME); File propertiesFile = new File(propertiesFilename); if (!propertiesFile.exists()) { System.err.println(propertiesFilename + " file does not exist. Aborting"); return false; } URI propertiesUri = propertiesFile.toURI(); URL propertiesUrl; try { propertiesUrl = propertiesUri.toURL(); } catch (MalformedURLException e) { System.err.println("File could not be read." + e); return false; } ConfigureRepositoryPreferences.readRepositoryPreferences(propertiesUrl, CASSANDRA_REPOSITORY_ID, context); System.out.println(propertiesFilename + " file processed successfully."); return true; }
From source file:jp.co.opentone.bsol.linkbinder.util.AttachmentUtil.java
/** * ?????./*from w ww . jav a 2 s .com*/ * @param key Key * @return ????? */ public static String createFileName(String key) { return FilenameUtils.concat(getRoot().getAbsolutePath(), key); }
From source file:com.enderville.enderinstaller.util.InstallScript.java
/** * Unpacks all the contents of the old minecraft.jar to the temp directory. * * @param tmpdir The temp directory to unpack to. * @param mcjar The location of the old minecraft.jar * @throws IOException//w w w .j ava 2 s . c om */ public static void unpackMCJar(File tmpdir, File mcjar) throws IOException { byte[] dat = new byte[4 * 1024]; JarFile jar = new JarFile(mcjar); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String name = entry.getName(); //This gets rid of META-INF if it exists. if (name.startsWith("META-INF")) { continue; } InputStream in = jar.getInputStream(entry); File dest = new File(FilenameUtils.concat(tmpdir.getPath(), name)); if (entry.isDirectory()) { //I don't think this actually happens LOGGER.warn("Found a directory while iterating over jar."); dest.mkdirs(); } else if (!dest.getParentFile().exists()) { if (!dest.getParentFile().mkdirs()) { throw new IOException("Couldn't create directory for " + name); } } FileOutputStream out = new FileOutputStream(dest); int len = -1; while ((len = in.read(dat)) > 0) { out.write(dat, 0, len); } out.flush(); out.close(); in.close(); } }
From source file:com.blueverdi.rosietheriveter.AlbumPageFactory.java
public AlbumPage getAlbumPage(int index) { if (index < 0) { throw new IllegalArgumentException("index < 0"); }/*ww w .j av a 2 s . co m*/ if (index >= imageFiles.length) { throw new IllegalArgumentException("index too large"); } AlbumPage ret = new AlbumPage(); ret.BitmapName = getBitmapName(imageFiles[index]); ret.bitmap = getBitmapFromAssets(ret.BitmapName); String audioFileName = FilenameUtils.concat(audioSource, FilenameUtils.getBaseName(imageFiles[index]) + ".mp3"); ret.mp3 = null; try { context.getAssets().open(audioFileName); ret.mp3 = audioFileName; } catch (IOException ex) { } return ret; }
From source file:edu.cornell.med.icb.goby.counts.TestPeakAggregator.java
@Test public void testHasNext() throws IOException { final String basename = FilenameUtils.concat(BASE_TEST_DIR, "counts-101.bin"); writeSomeCounts(basename);// w w w .j a v a 2s . c om final CountsReader countReader = new CountsReader(new FileInputStream(basename)); final PeakAggregator peakIterator = new PeakAggregator(countReader); assertTrue(peakIterator.hasNext()); peakIterator.next(); assertTrue(peakIterator.hasNext()); peakIterator.next(); assertFalse(peakIterator.hasNext()); try { peakIterator.next(); } catch (NoSuchElementException e) { // we expect this return; } fail("Expected an exception when calling next too many times"); }