List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:io.blobkeeper.file.service.FileListServiceImpl.java
private File getFile(java.io.File filePath, String blobFileName) { java.io.File file = new java.io.File(FilenameUtils.concat(filePath.getAbsolutePath(), blobFileName)); return new File(file); }
From source file:com.enioka.jqm.tools.LibraryResolverFS.java
private void loadCache(Node node, JobDef jd, EntityManager em) throws JqmPayloadException { jqmlogger.debug("Resolving classpath for job definition " + jd.getApplicationName()); File jarFile = new File(FilenameUtils.concat(new File(node.getRepo()).getAbsolutePath(), jd.getJarPath())); File jarDir = jarFile.getParentFile(); File libDir = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "lib")); File libDirExtracted = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "libFromJar")); File pomFile = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "pom.xml")); if (!jarFile.canRead()) { jqmlogger.warn("Cannot read file at " + jarFile.getAbsolutePath() + ". Job instance will crash. Check job definition or permissions on file."); throw new JqmPayloadException("File " + jarFile.getAbsolutePath() + " cannot be read"); }//from w w w . j a v a2 s . co m // POM file should be deleted if it comes from the jar file. Otherwise, it would stay into place and modifications to the internal // pom would be ignored. boolean pomFromJar = false; // 1st: if no pom, no lib dir => find a pom inside the JAR. (& copy it, we will read later) if (!pomFile.exists() && !libDir.exists()) { jqmlogger.trace("No pom inside jar directory. Checking for a pom inside the jar file"); InputStream is = null; FileOutputStream os = null; ZipFile zf = null; try { zf = new ZipFile(jarFile); Enumeration<? extends ZipEntry> zes = zf.entries(); while (zes.hasMoreElements()) { ZipEntry ze = zes.nextElement(); if (ze.getName().endsWith("pom.xml")) { is = zf.getInputStream(ze); os = new FileOutputStream(pomFile); IOUtils.copy(is, os); pomFromJar = true; break; } } } catch (Exception e) { throw new JqmPayloadException("Could not handle pom inside jar", e); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); Helpers.closeQuietly(zf); } } // 2nd: no pom, no pom inside jar, no lib dir => find a lib dir inside the jar if (!pomFile.exists() && !libDir.exists()) { jqmlogger.trace("Checking for a lib directory inside jar"); InputStream is = null; FileOutputStream os = null; ZipFile zf = null; FileUtils.deleteQuietly(libDirExtracted); try { zf = new ZipFile(jarFile); Enumeration<? extends ZipEntry> zes = zf.entries(); while (zes.hasMoreElements()) { ZipEntry ze = zes.nextElement(); if (ze.getName().startsWith("lib/") && ze.getName().endsWith(".jar")) { if (!libDirExtracted.isDirectory() && !libDirExtracted.mkdir()) { throw new JqmPayloadException("Could not extract libraries from jar"); } is = zf.getInputStream(ze); os = new FileOutputStream(FilenameUtils.concat(libDirExtracted.getAbsolutePath(), FilenameUtils.getName(ze.getName()))); IOUtils.copy(is, os); } } } catch (Exception e) { throw new JqmPayloadException("Could not handle internal lib directory", e); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); Helpers.closeQuietly(zf); } // If libs were extracted, put in cache and return if (libDirExtracted.isDirectory()) { FileFilter fileFilter = new WildcardFileFilter("*.jar"); File[] files = libDirExtracted.listFiles(fileFilter); URL[] libUrls = new URL[files.length]; try { for (int i = 0; i < files.length; i++) { libUrls[i] = files[i].toURI().toURL(); } } catch (Exception e) { throw new JqmPayloadException("Could not handle internal lib directory", e); } // Put in cache putInCache(libUrls, jd.getApplicationName()); return; } } // 3rd: if pom, use pom! if (pomFile.exists() && !libDir.exists()) { jqmlogger.trace("Reading a pom file"); ConfigurableMavenResolverSystem resolver = LibraryResolverMaven.getMavenResolver(em); // Resolve File[] depFiles = null; try { depFiles = resolver.loadPomFromFile(pomFile).importRuntimeDependencies().resolve() .withTransitivity().asFile(); } catch (IllegalArgumentException e) { // Happens when no dependencies inside pom, which is a weird use of the feature... jqmlogger.trace("No dependencies inside pom.xml file - no libs will be used", e); depFiles = new File[0]; } // Extract results URL[] tmp = LibraryResolverMaven.extractMavenResults(depFiles); // Put in cache putInCache(tmp, jd.getApplicationName()); // Cleanup if (pomFromJar && !pomFile.delete()) { jqmlogger.warn("Could not delete the temp pom file extracted from the jar."); } return; } // 4: if lib, use lib... (lib has priority over pom) if (libDir.exists()) { jqmlogger.trace( "Using the lib directory " + libDir.getAbsolutePath() + " as the source for dependencies"); FileFilter fileFilter = new WildcardFileFilter("*.jar"); File[] files = libDir.listFiles(fileFilter); URL[] tmp = new URL[files.length]; for (int i = 0; i < files.length; i++) { try { tmp[i] = files[i].toURI().toURL(); } catch (MalformedURLException e) { throw new JqmPayloadException("incorrect file inside lib directory", e); } } // Put in cache putInCache(tmp, jd.getApplicationName()); return; } throw new JqmPayloadException( "There is no lib dir or no pom.xml inside the directory containing the jar or inside the jar. The jar cannot be launched."); }
From source file:io.github.retz.executor.RetzExecutorTest.java
@Test public void notEnough() throws IOException { assert driver.start() == Protos.Status.DRIVER_RUNNING; // check registered called String tempFilename = FilenameUtils.concat("/tmp", folder.newFile().getName()); System.err.println("Temporary file: " + tempFilename); assert !new File(tempFilename).exists(); Job job = new Job("appname", "touch " + tempFilename, null, new Range(3, 0), new Range(128, 0)); Protos.TaskInfo task = Protos.TaskInfo.newBuilder() .setTaskId(Protos.TaskID.newBuilder().setValue("foobar-task").build()) .setData(ByteString.copyFromUtf8(mapper.writeValueAsString(job))) .setExecutor(executor.getExecutorInfo()).setSlaveId(executor.getSlaveInfo().getId()) .addAllResources(ResourceConstructor.construct(1, 12)).setName("yeah, holilday!").build(); executor.launchTask(driver, task);//from ww w . j a va 2 s . c o m assert !new File(tempFilename).exists(); assert driver.stop() == Protos.Status.DRIVER_STOPPED; // check shutdown called }
From source file:com.base2.kagura.core.authentication.FileAuthentication.java
private String getFile(String filenameToAdd) { LOG.info("Using config path: {}", configPath); String filename = FilenameUtils.concat(configPath, filenameToAdd); if (filename == null) { final String basePath = FilenameUtils.concat(System.getProperty("user.dir"), configPath); if (basePath != null) { filename = FilenameUtils.concat(basePath, filenameToAdd); }//from ww w . j av a 2 s .c o m } return filename; }
From source file:com.enderville.enderinstaller.util.InstallerConfig.java
/** * The location of minecraft.jar.//w w w .ja v a2s . c o m * * @return */ public static String getMinecraftJar() { return FilenameUtils.normalize(FilenameUtils.concat(getMinecraftFolder(), "bin/minecraft.jar")); }
From source file:com.citrix.cpbm.portal.fragment.controllers.AbstractLogoController.java
@RequestMapping(value = ("/connector/{serviceId}/{type}"), method = RequestMethod.GET) public void getServiceLogo(@PathVariable String serviceId, @PathVariable String type, ModelMap map, HttpServletResponse response) {/*w w w. j av a 2 s. c om*/ Service service = connectorConfigurationManagerService.getService(serviceId); List<ServiceImage> images = new ArrayList<ServiceImage>(service.getImages()); for (ServiceImage serviceImage : images) { if (serviceImage.getImagetype().equals(type)) { String cssdkFilesDirectory = FilenameUtils.concat( config.getValue(Names.com_citrix_cpbm_portal_settings_services_datapath), service.getServiceName() + "_" + service.getVendorVersion()); logoResponse(FilenameUtils.concat(CssdkConstants.IMAGES_DIRECTORY, serviceImage.getImagepath()), "", response, cssdkFilesDirectory); return; } } }
From source file:com.abiquo.am.services.filesystem.TemplateFileSystem.java
public static TemplateStateDto getTemplateStatus(final String enterpriseRepositoryPath, final String ovfId) { final TemplateStateDto state = new TemplateStateDto(); state.setOvfId(ovfId);/*from w ww. java 2 s. c o m*/ if (!TemplateConventions.isValidOVFLocation(ovfId)) { state.setStatus(TemplateStatusEnumType.ERROR); state.setErrorCause(AMError.TEMPLATE_INVALID_LOCATION.toString()); return state; } final boolean isInstance = TemplateConventions.isBundleOvfId(ovfId); final String packagePath = getTemplatePath(enterpriseRepositoryPath, ovfId); if (isInstance) { final String snapshot = ovfId.substring(ovfId.lastIndexOf('/') + 1, ovfId.indexOf("-snapshot-")); final String masterPath = TemplateConventions.getTemplatePath(enterpriseRepositoryPath, TemplateConventions.getBundleMasterOvfId(ovfId)); final File folder = new File(masterPath); if (folder.list(new FilenameFilter() { @Override public boolean accept(final File file, final String name) { return name.startsWith(snapshot); } }).length == 0) { state.setStatus(TemplateStatusEnumType.NOT_DOWNLOAD); } else { state.setStatus(TemplateStatusEnumType.DOWNLOAD); } return state; } final String ovfEnvelopePath = FilenameUtils.concat(enterpriseRepositoryPath, getRelativeTemplatePath(ovfId)); File errorMarkFile = new File(packagePath + TEMPLATE_STATUS_ERROR_MARK); if (errorMarkFile.exists()) { state.setStatus(TemplateStatusEnumType.ERROR); state.setErrorCause(readErrorMarkFile(errorMarkFile)); } else if (new File(packagePath + TEMPLATE_STATUS_DOWNLOADING_MARK).exists()) { state.setStatus(TemplateStatusEnumType.DOWNLOADING); } else if (!new File(ovfEnvelopePath).exists()) { state.setStatus(TemplateStatusEnumType.NOT_DOWNLOAD); } else { state.setStatus(TemplateStatusEnumType.DOWNLOAD); } return state; }
From source file:com.abiquo.appliancemanager.ApplianceManagerAsserts.java
/** * /* www . java 2 s .co m*/ * * */ protected static void createBundleDiskFile(final String ovfId, final String snapshot) throws Exception { EnterpriseRepositoryService er = ErepoFactory.getRepo(String.valueOf(idEnterprise)); final String ovfpath = TemplateConventions.getRelativePackagePath(ovfId); final String diskFilePathRel = er.getDiskFilePath(ovfId); // final String diskFilePathRel = diskFilePath.substring(diskFilePath.lastIndexOf('/')); final String path = FilenameUtils.concat(FilenameUtils.concat(er.path(), ovfpath), (snapshot + "-snapshot-" + diskFilePathRel)); // "/opt/testvmrepo/1/rs.bcn.abiquo.com/m0n0wall/000snap000-snapshot-m0n0wall-1.3b18-i386-flat.vmdk" File f = new File(path); f.createNewFile(); f.deleteOnExit(); FileWriter fileWriter = new FileWriter(f); for (int i = 0; i < 1000; i++) { fileWriter.write(i % 1); } fileWriter.close(); }
From source file:edu.cornell.med.icb.goby.alignments.TestMerge.java
@Test public void testMergeTranscriptRuns() throws IOException { final Merge merger = new Merge("test-data/alignments/geneTranscriptInfo.txt", 3); final List<File> inputFiles = new ArrayList<File>(); inputFiles.add(new File(FilenameUtils.concat(BASE_TEST_DIR, "transcript-101"))); final String outputFile = FilenameUtils.concat(BASE_TEST_DIR, "out-transcript-101-merged"); merger.setK(1);/* w w w .j a va 2 s . c om*/ merger.merge(inputFiles, outputFile); // With k=1, the merge should keep query=0 and query=2 final String basename = outputFile; final int count = countAlignmentEntries(basename); assertEquals("Only best score, non ambiguous gene matches should be kept. ", 4 - 1, count); // -1 removes an entry with lower score final AlignmentReaderImpl reader = new AlignmentReaderImpl(outputFile); reader.readHeader(); assertEquals(5, reader.getNumberOfTargets()); assertArrayEquals(new int[] { 1024, 5678, 1237, 9, 143 }, reader.getTargetLength()); assertEquals(3, reader.getNumberOfQueries()); final int maxTargetIndex = -1; final IntSet queryIndices = new IntArraySet(); final IntSet targetIndices = new IntArraySet(); while (reader.hasNext()) { final Alignments.AlignmentEntry alignmentEntry = reader.next(); queryIndices.add(alignmentEntry.getQueryIndex()); targetIndices.add(alignmentEntry.getQueryIndex()); } assertEquals(true, queryIndices.contains(0)); assertEquals(true, queryIndices.contains(2)); assertEquals(false, queryIndices.contains(1)); assertEquals(false, queryIndices.contains(1)); }
From source file:au.org.ala.delta.model.ResourceSettings.java
/** * @return A list of the resource path locations *///from ww w. ja v a 2 s .co m public List<String> getResourcePathLocations() { List<String> retList = new ArrayList<String>(); for (String resourcePath : _resourceLocations) { if (_remoteResourceLocations.contains(resourcePath) || new File(resourcePath).isAbsolute() || StringUtils.isEmpty(_dataSetPath)) { retList.add(resourcePath); } else { retList.add(FilenameUtils.concat(_dataSetPath, resourcePath)); } } return retList; }