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.algorithmic.algorithm.TestAccumulate.java
@Test public void testBaseCountPipeLine() throws IOException { final String basename = FilenameUtils.concat(testDir, "align-reads"); AlignmentWriterImpl alignmentWriter = null; try {// w ww. j ava2s. c o m int constantQueryLength = 40; alignmentWriter = new AlignmentWriterImpl(basename); Alignments.AlignmentEntry.Builder currentEntry = alignmentWriter.getAlignmentEntry(); currentEntry.setScore(30); currentEntry.setPosition(5); currentEntry.setQueryIndex(1); currentEntry.setTargetIndex(1); currentEntry.setMatchingReverseStrand(false); currentEntry.setQueryAlignedLength(5); currentEntry.setQueryLength(constantQueryLength); alignmentWriter.appendEntry(); currentEntry = alignmentWriter.getAlignmentEntry(); currentEntry.setScore(30); currentEntry.setPosition(3); currentEntry.setQueryIndex(1); currentEntry.setTargetIndex(1); currentEntry.setMatchingReverseStrand(false); currentEntry.setQueryAlignedLength(5); currentEntry.setQueryLength(constantQueryLength); alignmentWriter.appendEntry(); currentEntry = alignmentWriter.getAlignmentEntry(); currentEntry.setScore(30); currentEntry.setPosition(3); currentEntry.setQueryIndex(1); currentEntry.setTargetIndex(1); currentEntry.setMatchingReverseStrand(false); currentEntry.setQueryAlignedLength(4); currentEntry.setQueryLength(constantQueryLength); alignmentWriter.appendEntry(); currentEntry = alignmentWriter.getAlignmentEntry(); currentEntry.setScore(30); currentEntry.setPosition(8); currentEntry.setQueryIndex(1); currentEntry.setTargetIndex(1); currentEntry.setMatchingReverseStrand(false); currentEntry.setQueryAlignedLength(4); currentEntry.setQueryLength(constantQueryLength); alignmentWriter.appendEntry(); alignmentWriter.printStats(System.out); } finally { if (alignmentWriter != null) { try { alignmentWriter.close(); } catch (IOException e) { // NOPMD // nothing to do - ignore } } } alignmentWriter.printStats(System.out); AlignmentReader alignmentReader = null; try { alignmentReader = new AlignmentReaderImpl(basename); computeCount.startPopulating(); while (alignmentReader.hasNext()) { final Alignments.AlignmentEntry alignmentEntry = alignmentReader.next(); final int startPosition = alignmentEntry.getPosition(); final int alignmentLength = alignmentEntry.getQueryAlignedLength(); LOG.debug("start " + startPosition + " length " + alignmentLength); // shifted the ends populating by 1 computeCount.populate(startPosition, startPosition + alignmentLength); } } finally { if (alignmentReader != null) { alignmentReader.close(); } } final String countsFile = FilenameUtils.concat(testDir, "align-count"); CountsWriterI countsWriterI = null; CountsReader countsReader = null; try { countsWriterI = new CountsWriter(new FileOutputStream(countsFile)); computeCount.accumulate(); computeCount.baseCount(countsWriterI); countsReader = new CountsReader(new FileInputStream(countsFile)); final int[] exp = { 0, 0, 0, 2, 2, 3, 3, 3, 3, 2, 2, 1, 1 }; int i = 0; while (countsReader.hasNextPosition()) { assertEquals(exp[i], countsReader.nextCountAtPosition()); i++; } } finally { if (countsWriterI != null) { try { countsWriterI.close(); } catch (IOException e) { // NOPMD // nothing to do - ignore } } if (countsReader != null) { try { countsReader.close(); } catch (IOException e) { // NOPMD // nothing to do - ignore } } } }
From source file:com.blueverdi.rosietheriveter.AlbumPageFactory.java
private String getBitmapName(String filename) { return FilenameUtils.concat(imageSource, filename); }
From source file:com.xiaomi.linden.cluster.ShardClient.java
public ShardClient(final ZkClient zkClient, final String zk, final String path, final LindenService.ServiceIface localClient, final int localPort, final int shardId) { this.zk = zk; this.path = path; this.localClient = localClient; this.shardId = shardId; this.localHostPort = String.format("%s:%s", CommonUtils.getLocalHost(), localPort); // if the path does not exist, create it. // the path may be created later, so the listener will not work // and the isAvailable will always be false. if (!zkClient.exists(path)) { zkClient.createPersistent(path, true); }//from w w w . j a v a 2 s . c om List<String> children = zkClient.getChildren(path); final Map<String, Map.Entry<String, LindenService.ServiceIface>> lindenClients = new ConcurrentHashMap<>(); zkClient.subscribeChildChanges(path, new LindenZKListener(path, children) { @Override public void onChildChange(String parent, List<String> children, List<String> newAdded, List<String> deleted) { for (String node : newAdded) { String fullPath = FilenameUtils.separatorsToUnix(FilenameUtils.concat(path, node)); byte[] bytes = zkClient.readData(fullPath); ServiceInstance instance = JSONObject.parseObject(new String(bytes), ServiceInstance.class); String hostPort = String.format("%s:%s", instance.getServiceEndpoint().getHost(), instance.getServiceEndpoint().getPort()); if (localHostPort.equals(hostPort)) { haslocalClient = true; lindenClients.put(node, new AbstractMap.SimpleEntry<>(hostPort, localClient)); LOGGER.info("Linden local node {} {} joined shard {}.", node, hostPort, shardId); } else { LindenService.ServiceIface client = Thrift.newIface(hostPort, LindenService.ServiceIface.class); lindenClients.put(node, new AbstractMap.SimpleEntry<>(hostPort, client)); LOGGER.info("Linden node {} {} joined shard {}.", node, hostPort, shardId); } } for (String node : deleted) { if (lindenClients.containsKey(node)) { String hostPort = lindenClients.get(node).getKey(); lindenClients.remove(node); LOGGER.info("Linden node {} {} left shard {}.", node, hostPort, shardId); } } // ensure the new node overrides the old node. List<String> sortedNodes = new ArrayList<>(); for (String node : lindenClients.keySet()) { sortedNodes.add(node); } Collections.sort(sortedNodes, Collections.reverseOrder()); Set<String> uniqueClients = new HashSet<>(); for (String node : sortedNodes) { String hostPort = lindenClients.get(node).getKey(); if (uniqueClients.contains(hostPort)) { lindenClients.remove(node); LOGGER.warn("Linden node {} {} is duplicated in shard {}, removed!", node, hostPort, shardId); } else { uniqueClients.add(hostPort); } } LOGGER.info("{} Linden node in shard {}.", lindenClients.size(), shardId); List<Map.Entry<String, LindenService.ServiceIface>> tempClients = new ArrayList<>(); for (String node : lindenClients.keySet()) { tempClients.add(lindenClients.get(node)); String hostPort = lindenClients.get(node).getKey(); LOGGER.info("Linden node {} {} on service in shard {}.", node, hostPort, shardId); } clients = tempClients; } }); }
From source file:com.zappy.purefit6.service.WeekFacadeREST.java
/** * Edit week program.//from www .ja v a 2s . c o m * @param id Id of week to edit URL * @param uploadedInputStream Image FORM * @param fileDetail Image FORM * @param name Weekly program name */ @PUT @Path("{id}") @Consumes(MediaType.MULTIPART_FORM_DATA) public void edit(@PathParam("id") Integer id, @FormDataParam("image") InputStream uploadedInputStream, @FormDataParam("image") FormDataContentDisposition fileDetail, @FormDataParam("name") String name) { try { //Copy file File destination = new File( FilenameUtils.concat("/home/gianksp/Desktop/test/week", fileDetail.getFileName())); FileUtils.copyInputStreamToFile(uploadedInputStream, destination); //Create element Week week = new Week(); week.setIdWeek(id); week.setName(name); week.setImagePath(destination.getAbsolutePath()); //Store element super.edit(week); } catch (IOException ex) { log.log(Level.SEVERE, "Unable to import week program image " + " .name:" + name + " .fileName:" + fileDetail.getName(), ex); } catch (Exception ex) { log.log(Level.SEVERE, "Unable to create week program " + " .name:" + name, ex); } }
From source file:biz.dfch.j.graylog2.plugin.filter.dfchBizExecScript.java
public dfchBizExecScript() throws IOException, URISyntaxException { try {// w ww .ja v a2s . c o m LOG.debug(String.format("*** [%d] %s: Initialising plugin ...\r\n", Thread.currentThread().getId(), DF_PLUGIN_NAME)); // 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 leadig '/' 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(); Object object = jsonParser.parse(new FileReader(configurationFileName)); JSONObject jsonObject = (JSONObject) object; String scriptEngine = (String) jsonObject.get(DF_SCRIPT_ENGINE); String scriptPathAndName = (String) jsonObject.get(DF_SCRIPT_PATH_AND_NAME); if (null == scriptPathAndName || scriptPathAndName.isEmpty()) { scriptPathAndName = FilenameUtils.concat(path, (String) jsonObject.get(DF_SCRIPT_NAME)); } Boolean scriptCacheContents = (Boolean) jsonObject.get(DF_SCRIPT_CACHE_CONTENTS); Boolean scriptDisplayOutput = (Boolean) jsonObject.get(DF_SCRIPT_DISPLAY_OUTPUT); 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); // set configuration Map<String, Object> map = new HashMap<>(); map.put(DF_SCRIPT_ENGINE, scriptEngine); map.put(DF_SCRIPT_PATH_AND_NAME, scriptPathAndName); map.put(DF_SCRIPT_DISPLAY_OUTPUT, scriptDisplayOutput); map.put(DF_SCRIPT_CACHE_CONTENTS, scriptCacheContents); map.put(DF_PLUGIN_PRIORITY, pluginPriority); map.put(DF_PLUGIN_DROP_MESSAGE, pluginDropMessage); map.put(DF_PLUGIN_DISABLED, pluginDisabled); initialize(new Configuration(map)); } catch (IOException ex) { LOG.error(String.format("*** [%d] %s: Initialising plugin FAILED. Filter will be disabled.\r\n%s\r\n", Thread.currentThread().getId(), DF_PLUGIN_NAME, ex.getMessage())); LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - IOException - Filter will be disabled."); ex.printStackTrace(); } catch (Exception ex) { LOG.error(String.format("*** [%d] %s: Initialising plugin FAILED. Filter will be disabled.\r\n", Thread.currentThread().getId(), DF_PLUGIN_NAME)); LOG.error("*** " + DF_PLUGIN_NAME + "::dfchBizExecScript() - Exception - Filter will be disabled."); ex.printStackTrace(); } }
From source file:cop.maven.plugins.AbstractRamlConfigMojoTest.java
@Test public void shouldReturnYamlFileWhenYamlOptionSet() throws Exception { setYaml(mojo, "raml.yml"); File dir = TestUtils.createTempDir(); String path = TestUtils.createTempFile(dir, "raml.yml").getParentFile().getAbsolutePath(); setBuildResources(mojo, new ArrayList<Resource>() { {/* w w w .jav a 2 s . co m*/ add(TestUtils.createResource(TestUtils.createTempDir(dir, "foo").getAbsolutePath())); add(TestUtils.createResource(path)); } }); assertThat(getYaml(mojo).getAbsolutePath()).isEqualTo(FilenameUtils.concat(path, "raml.yml")); assertThat(((LogMock) mojo.getLog()).getInfoContent()).startsWith("found raml configuration file"); }
From source file:es.urjc.mctwp.image.impl.collection.fs.ImageContentCollectionFSImpl.java
/** * Create a subdirectory for store dicom files * //from ww w. j a v a2 s. c om * @param name */ public void createCollection(String name) throws ImageCollectionException { if ((name != null) && (name.length() > 0)) { File temp = new File(FilenameUtils.concat(basedir.getAbsolutePath(), name)); if (temp.exists()) { String error = "Collection [" + name + "] already exists"; logger.error(error); throw new ImageCollectionException(error); } else { try { temp.mkdir(); } catch (Exception e) { logger.error(e.getMessage()); throw new ImageCollectionException(e); } } } else { String error = "Can't create collection, given name is null or empty"; logger.error(error); throw new ImageCollectionException(error); } }
From source file:com.r573.enfili.common.io.file.PathBuilder.java
public String toPath() { String path = prefix; for (String element : elements) { path = FilenameUtils.concat(path, element); } return path; }
From source file:net.sf.jvifm.model.FileModelManager.java
public void rename(String srcName, String destName, String path) { File file = new File(path); String parent = file.getParent(); String newName = file.getName().replaceAll(srcName, destName); if (parent != null) { file.renameTo(new File(FilenameUtils.concat(parent, newName))); } else {/*from www .ja v a 2 s . c o m*/ file.renameTo(new File(newName)); } }
From source file:net.leegorous.jsc.JSC.java
private void addClasspath(JsContextManager mgr, String rootPath, String cp) { if (cp == null) return;/*from w w w . j ava 2s .c o m*/ List classpath = (List) cpMap.get(cp); if (classpath != null) return; List cps = normalizePath(cp); List result = new ArrayList(); for (Iterator it = cps.iterator(); it.hasNext();) { String str = (String) it.next(); File f = new File(getRealPath("/" + str)); if (f.exists()) { mgr.addClasspath(f); result.add(f.getAbsoluteFile()); continue; } String path = FilenameUtils.concat(rootPath, str); mgr.addClasspath(path); result.add(path); } cpMap.put(cp, result); }