List of usage examples for org.apache.commons.io FilenameUtils getPath
public static String getPath(String filename)
From source file:com.bitplan.pdfindex.Pdfindexer.java
/** * create the index/* ww w.j ava 2 s . c o m*/ * @throws Exception -if a problem occurs */ protected void doIndex() throws Exception { List<DocumentSource> sources = null; if ((this.getSource() != null) || (this.getSourceFileList() != null) || this.arguments.size() > 0) { sources = createIndex(); if (this.extract) { for (DocumentSource source : sources) { PDDocument pdfdoc = source.getDocument(); if (source.file != null) { PDFTextStripper stripper = new PDFTextStripper(); String path = source.file.getPath(); String textpath = FilenameUtils.getPath(path) + FilenameUtils.getBaseName(path) + ".txt"; System.out.println("extracting text to " + textpath); PrintWriter textWriter = new PrintWriter(new File(textpath)); stripper.writeText(pdfdoc, textWriter); textWriter.close(); } } } } // create the main html output PrintWriter output = getOutput(); List<String> words = getSearchWords(); SortedMap<String, SearchResult> searchResults = new TreeMap<String, SearchResult>(); for (String word : words) { TopDocs topDocs = searchIndex(word, "content", getMaxHits()); searchResults.put(word, new SearchResult(searcher, topDocs)); } String html = this.getIndexAsHtml(searchResults); output.print(html); output.flush(); output.close(); }
From source file:com.iyonger.apm.web.service.PerfTestService.java
/** * Create {@link GrinderProperties} based on the passed {@link PerfTest}. * * @param perfTest base data//www . j a v a 2 s. c o m * @param scriptHandler scriptHandler * @return created {@link GrinderProperties} instance */ public GrinderProperties getGrinderProperties(PerfTest perfTest, ScriptHandler scriptHandler) { try { // Use default properties first GrinderProperties grinderProperties = new GrinderProperties( config.getHome().getDefaultGrinderProperties()); User user = perfTest.getCreatedUser(); // Get all files in the script path String scriptName = perfTest.getScriptName(); FileEntry userDefinedGrinderProperties = fileEntryService.getOne(user, FilenameUtils.concat(FilenameUtils.getPath(scriptName), DEFAULT_GRINDER_PROPERTIES), -1L); if (!config.isSecurityEnabled() && userDefinedGrinderProperties != null) { // Make the property overridden by user property. GrinderProperties userProperties = new GrinderProperties(); userProperties.load(new StringReader(userDefinedGrinderProperties.getContent())); grinderProperties.putAll(userProperties); } grinderProperties.setAssociatedFile(new File(DEFAULT_GRINDER_PROPERTIES)); grinderProperties.setProperty(GRINDER_PROP_SCRIPT, scriptHandler.getScriptExecutePath(scriptName)); grinderProperties.setProperty(GRINDER_PROP_TEST_ID, "test_" + perfTest.getId()); grinderProperties.setInt(GRINDER_PROP_AGENTS, getSafe(perfTest.getAgentCount())); grinderProperties.setInt(GRINDER_PROP_PROCESSES, getSafe(perfTest.getProcesses())); grinderProperties.setInt(GRINDER_PROP_THREAD, getSafe(perfTest.getThreads())); if (perfTest.isThresholdDuration()) { grinderProperties.setLong(GRINDER_PROP_DURATION, getSafe(perfTest.getDuration())); grinderProperties.setInt(GRINDER_PROP_RUNS, 0); } else { grinderProperties.setInt(GRINDER_PROP_RUNS, getSafe(perfTest.getRunCount())); if (grinderProperties.containsKey(GRINDER_PROP_DURATION)) { grinderProperties.remove(GRINDER_PROP_DURATION); } } grinderProperties.setProperty(GRINDER_PROP_ETC_HOSTS, StringUtils.defaultIfBlank(perfTest.getTargetHosts(), "")); grinderProperties.setBoolean(GRINDER_PROP_USE_CONSOLE, true); if (BooleanUtils.isTrue(perfTest.getUseRampUp())) { grinderProperties.setBoolean(GRINDER_PROP_THREAD_RAMPUP, perfTest.getRampUpType() == RampUp.THREAD); grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT, getSafe(perfTest.getRampUpStep())); grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT_INTERVAL, getSafe(perfTest.getRampUpIncrementInterval())); if (perfTest.getRampUpType() == RampUp.PROCESS) { grinderProperties.setInt(GRINDER_PROP_INITIAL_SLEEP_TIME, getSafe(perfTest.getRampUpInitSleepTime())); } else { grinderProperties.setInt(GRINDER_PROP_INITIAL_THREAD_SLEEP_TIME, getSafe(perfTest.getRampUpInitSleepTime())); } grinderProperties.setInt(GRINDER_PROP_INITIAL_PROCESS, getSafe(perfTest.getRampUpInitCount())); } else { grinderProperties.setInt(GRINDER_PROP_PROCESS_INCREMENT, 0); } if (BooleanUtils.isTrue(perfTest.getUseFixedRateRPS())) { grinderProperties.setDouble(GRINDER_PROP_FIXED_RPS_RATE, perfTest.getRps()); } grinderProperties.setInt(GRINDER_PROP_REPORT_TO_CONSOLE, 500); grinderProperties.setProperty(GRINDER_PROP_USER, perfTest.getCreatedUser().getUserId()); grinderProperties.setProperty(GRINDER_PROP_JVM_CLASSPATH, getCustomClassPath(perfTest)); grinderProperties.setInt(GRINDER_PROP_IGNORE_SAMPLE_COUNT, getSafe(perfTest.getIgnoreSampleCount())); grinderProperties.setBoolean(GRINDER_PROP_SECURITY, config.isSecurityEnabled()); // For backward agent compatibility. // If the security is not enabled, pass it as jvm argument. // If enabled, pass it to grinder.param. In this case, I drop the // compatibility. if (StringUtils.isNotBlank(perfTest.getParam())) { String param = perfTest.getParam().replace("'", "\\'").replace(" ", ""); if (config.isSecurityEnabled()) { grinderProperties.setProperty(GRINDER_PROP_PARAM, StringUtils.trimToEmpty(param)); } else { String property = grinderProperties.getProperty(GRINDER_PROP_JVM_ARGUMENTS, ""); property = property + " -Dparam=" + param + " "; grinderProperties.setProperty(GRINDER_PROP_JVM_ARGUMENTS, property); } } LOGGER.info("Grinder Properties : {} ", grinderProperties); return grinderProperties; } catch (Exception e) { throw processException("error while prepare grinder property for " + perfTest.getTestName(), e); } }
From source file:de.tudarmstadt.ukp.clarin.webanno.project.page.ImportUtil.java
/** * copy Project META_INF from the exported project * @param zip the ZIP file.// w ww. j a v a 2 s.c o m * @param aProject the project. * @param aRepository the repository service. * @throws IOException if an I/O error occurs. */ @SuppressWarnings("rawtypes") public static void createProjectMetaInf(ZipFile zip, Project aProject, RepositoryService aRepository) throws IOException { for (Enumeration zipEnumerate = zip.entries(); zipEnumerate.hasMoreElements();) { ZipEntry entry = (ZipEntry) zipEnumerate.nextElement(); // Strip leading "/" that we had in ZIP files prior to 2.0.8 (bug #985) String entryName = normalizeEntryName(entry); if (entryName.startsWith(META_INF)) { File metaInfDir = new File(aRepository.getMetaInfFolder(aProject), FilenameUtils.getPath(entry.getName().replace(META_INF, ""))); // where the file reside in the META-INF/... directory FileUtils.forceMkdir(metaInfDir); FileUtils.copyInputStreamToFile(zip.getInputStream(entry), new File(metaInfDir, FilenameUtils.getName(entry.getName()))); LOG.info("Imported META-INF for project [" + aProject.getName() + "] with id [" + aProject.getId() + "]"); } } }
From source file:de.hybris.platform.webservices.AbstractWebServicesTest.java
/** * Checks for resource folder./* w w w. ja v a2 s .c o m*/ * * @param fileName * the file name * @return true, if successful */ private static boolean hasResourceFolder(final String fileName) { return FilenameUtils.getPath(fileName).equals("") ? false : true; }
From source file:org.abstracthorizon.proximity.storage.remote.CommonsNetFtpRemotePeer.java
public boolean containsItem(String path) throws StorageException { FTPClient client = null;/*from w ww. j a va 2s . com*/ try { client = getFTPClient(); try { if (client.changeWorkingDirectory( concatPaths(getRemoteUrl().getPath(), FilenameUtils.getPath(path)))) { FTPFile[] fileList = client.listFiles(FilenameUtils.getName(path)); if (fileList.length == 1) { return true; } else { return false; } } else { return false; } } catch (IOException ex) { throw new StorageException("Cannot execute FTP operation on remote peer.", ex); } } finally { try { if (client.isConnected()) { client.disconnect(); } } catch (IOException ex) { logger.warn("Could not disconnect FTPClient", ex); } } }
From source file:org.abstracthorizon.proximity.storage.remote.CommonsNetFtpRemotePeer.java
public Item retrieveItem(String path, boolean propsOnly) throws ItemNotFoundException, StorageException { String originatingUrlString = getAbsoluteUrl(path); FTPClient client = null;//from w w w . java 2 s .co m try { client = getFTPClient(); try { if (client.changeWorkingDirectory( concatPaths(getRemoteUrl().getPath(), FilenameUtils.getPath(path)))) { FTPFile[] fileList = client.listFiles(FilenameUtils.getName(path)); if (fileList.length == 1) { FTPFile ftpFile = fileList[0]; ItemProperties properties = constructItemPropertiesFromGetResponse(path, originatingUrlString, ftpFile); Item result = new Item(); if (properties.isFile()) { // TODO: Solve this in a better way File tmpFile = File.createTempFile(FilenameUtils.getName(path), null); tmpFile.deleteOnExit(); FileOutputStream fos = new FileOutputStream(tmpFile); try { client.retrieveFile(FilenameUtils.getName(path), fos); fos.flush(); } finally { fos.close(); } result.setStream(new DeleteOnCloseFileInputStream(tmpFile)); } else { result.setStream(null); } result.setProperties(properties); return result; } else { throw new ItemNotFoundException( "Item " + path + " not found in FTP remote peer of " + getRemoteUrl()); } } else { throw new ItemNotFoundException("Path " + FilenameUtils.getPath(path) + " not found in FTP remote peer of " + getRemoteUrl()); } } catch (IOException ex) { throw new StorageException("Cannot execute FTP operation on remote peer.", ex); } } finally { try { if (client.isConnected()) { client.disconnect(); } } catch (IOException ex) { logger.warn("Could not disconnect FTPClient", ex); } } }
From source file:org.abstracthorizon.proximity.storage.remote.CommonsNetFtpRemotePeer.java
/** * Construct item properties from get response. * //from w w w . jav a 2 s . com * @param path the path * @param originatingUrlString the originating url string * @param remoteFile the remote file * * @return the item properties * * @throws MalformedURLException the malformed URL exception */ protected ItemProperties constructItemPropertiesFromGetResponse(String path, String originatingUrlString, FTPFile remoteFile) throws MalformedURLException { URL originatingUrl = new URL(originatingUrlString); ItemProperties result = new HashMapItemPropertiesImpl(); result.setDirectoryPath( FilenameUtils.separatorsToUnix(FilenameUtils.getPath(FilenameUtils.getFullPath(path)))); result.setDirectory(remoteFile.isDirectory()); result.setFile(remoteFile.isFile()); result.setLastModified(remoteFile.getTimestamp().getTime()); result.setName(FilenameUtils.getName(originatingUrl.getPath())); if (result.isFile()) { result.setSize(remoteFile.getSize()); } else { result.setSize(0); } result.setRemoteUrl(originatingUrl.toString()); return result; }
From source file:org.apache.flex.compiler.internal.tree.mxml.MXMLNodeBase.java
/** * Resolves the path specified in an MXML tag's <code>source</code> * attribute./*from w ww . j ava 2s.c om*/ * * @param builder The {@code MXMLTreeBuilder} object which is building this * MXML tree. * @param attribute The <code>source</code> attribute. * @return A resolved and normalized path to the external file. */ public static String resolveSourceAttributePath(MXMLTreeBuilder builder, IMXMLTagAttributeData attribute, MXMLNodeInfo info) { if (info != null) info.hasSourceAttribute = true; String sourcePath = attribute.getMXMLDialect().trim(attribute.getRawValue()); if (sourcePath.isEmpty() && builder != null) { ICompilerProblem problem = new MXMLEmptyAttributeProblem(attribute); builder.addProblem(problem); return null; } String resolvedPath; if ((new File(sourcePath)).isAbsolute()) { // If the source attribute specifies an absolute path, // it doesn't need to be resolved. resolvedPath = sourcePath; } else { // Otherwise, resolve it relative to the MXML file. String mxmlPath = attribute.getParent().getParent().getPath(); resolvedPath = FilenameUtils.getPrefix(mxmlPath) + FilenameUtils.getPath(mxmlPath); resolvedPath = FilenameUtils.concat(resolvedPath, sourcePath); } String normalizedPath = FilenameNormalization.normalize(resolvedPath); // Make the compilation unit dependent on the external file. if (builder != null) builder.getFileScope().addSourceDependency(normalizedPath); return normalizedPath; }
From source file:org.artifactory.repo.snapshot.NonUniqueSnapshotVersionAdapter.java
@Override protected String adapt(MavenSnapshotVersionAdapterContext context) { String path = context.getRepoPath().getPath(); String fileName = PathUtils.getFileName(path); if (!MavenNaming.isUniqueSnapshotFileName(fileName)) { log.debug("File '{}' is not a unique snapshot version. Returning the original path.", fileName); return path; }// www . j av a 2 s . c o m String pathBaseVersion = context.getModuleInfo().getBaseRevision(); String timestampAndBuildNumber = MavenNaming.getUniqueSnapshotVersionTimestampAndBuildNumber(fileName); if (!fileName.contains(pathBaseVersion + "-" + timestampAndBuildNumber)) { log.debug("File '{}' version is not equals to the path base version '{}'. " + "Returning the original path.", fileName, pathBaseVersion); return path; } // replace the timestamp and build number part with 'SNAPSHOT' string String adaptedFileName = fileName.replace(timestampAndBuildNumber, MavenNaming.SNAPSHOT); return FilenameUtils.getPath(path) + adaptedFileName; }
From source file:org.bdval.MakeSyntheticDataset.java
private void process(final JSAPResult arguments) throws IOException { outputDirectory = arguments.getString("output-directory"); FileUtils.forceMkdir(new File(outputDirectory)); final int numProbesets = arguments.getInt("probeset-number"); final int numSamples = arguments.getInt("sample-number"); final int numPositiveSamples = arguments.getInt("positive-sample-number"); final int numInformativeProbesets = arguments.getInt("number-informative-probesets"); final String outputFilenamePrefix = arguments.getString("dataset-name"); scalePositiveLabel = arguments.getDouble("scale-positive-labels"); meanPositiveLabel = arguments.getDouble("mean-positive-labels"); scaleNegativeLabel = arguments.getDouble("scale-negative-labels"); meanNegativeLabel = arguments.getDouble("mean-negative-labels"); scaleNonInformativeFeature = arguments.getDouble("scale-non-informative"); meanNonInformativeFeature = arguments.getDouble("mean-non-informative"); final double[][] data = new double[numSamples][numProbesets]; final RandomEngine random = new MersenneTwister(); randomAdapter = new RandomAdapter(random); printStats(numProbesets, numSamples, numPositiveSamples, numInformativeProbesets, outputFilenamePrefix, new PrintWriter(System.out)); // pick informative probeset indices, making sure indices are not picked more than once. final IntSet informativeProbesetIndices = generateRandomIndices(numInformativeProbesets, numProbesets, randomAdapter);//from w w w.j a v a 2s.c o m final IntSet positiveSampleIndices = generateRandomIndices(numPositiveSamples, numSamples, randomAdapter); for (final double[] sample : data) { // for each sample: for (int probesetIndex = 0; probesetIndex < sample.length; probesetIndex++) { // for each probeset: sample[probesetIndex] = generateNonInformativeFeatureValue(); } } int sampleIndex = 0; for (final double[] sample : data) { // for each sample: for (final int informativeProbesetIndex : informativeProbesetIndices) { // for each informative probeset: sample[informativeProbesetIndex] = generateInformativeFeatureValue( positiveSampleIndices.contains(sampleIndex)); } sampleIndex++; } final String datasetFilename = FilenameUtils.concat(outputDirectory, FilenameUtils.concat("norm-data", outputFilenamePrefix + ".tmm")); FileUtils.forceMkdir(new File(FilenameUtils.getPath(datasetFilename))); PrintWriter datasetWriter = null; try { datasetWriter = new PrintWriter(datasetFilename); outputDataset(data, informativeProbesetIndices, positiveSampleIndices, datasetWriter); } finally { IOUtils.closeQuietly(datasetWriter); } final IntList sampleIndicesList = outputCids(numSamples, positiveSampleIndices, outputFilenamePrefix); outputTrainingAndTestingCids(positiveSampleIndices, outputFilenamePrefix, sampleIndicesList); Collections.shuffle(sampleIndicesList); final IntList trainingSetSampleList = sampleIndicesList.subList(0, (int) (sampleIndicesList.size() * trainingVsTestingSizeRatio)); final IntList testingSetSampleList = sampleIndicesList.subList( (int) (sampleIndicesList.size() * trainingVsTestingSizeRatio) + 1, sampleIndicesList.size()); outputCids(positiveSampleIndices, outputFilenamePrefix + "Training", trainingSetSampleList); outputCids(positiveSampleIndices, outputFilenamePrefix + "Testing", testingSetSampleList); final IntSet positiveInCompleteSet = new IntLinkedOpenHashSet(); positiveInCompleteSet.addAll(sampleIndicesList); positiveInCompleteSet.retainAll(positiveSampleIndices); System.out.println("positiveInCompleteSet: " + positiveInCompleteSet.size()); // task for full training set: outputTasks(outputFilenamePrefix, numSamples, positiveInCompleteSet, outputFilenamePrefix + ".tasks"); // task for training set only: final IntSet positiveInTrainingSet = new IntLinkedOpenHashSet(); positiveInTrainingSet.addAll(trainingSetSampleList); positiveInTrainingSet.retainAll(positiveSampleIndices); System.out.println("positiveInTrainingSet: " + positiveInTrainingSet.size()); outputTasks(outputFilenamePrefix + "_Training", trainingSetSampleList.size(), positiveInTrainingSet, outputFilenamePrefix + "_Training" + ".tasks"); //task for test set only: final IntSet positiveInTestingSet = new IntLinkedOpenHashSet(); positiveInTestingSet.addAll(testingSetSampleList); positiveInTestingSet.retainAll(positiveSampleIndices); System.out.println("positiveInTestingSet: " + positiveInTestingSet.size()); outputTasks(outputFilenamePrefix + "_Testing", testingSetSampleList.size(), positiveInTestingSet, outputFilenamePrefix + "_Testing" + ".tasks"); final String summaryFilename = FilenameUtils.concat(outputDirectory, outputFilenamePrefix + "-README.txt"); PrintWriter summaryWriter = null; try { summaryWriter = new PrintWriter(summaryFilename); printStats(numProbesets, numSamples, numPositiveSamples, numInformativeProbesets, outputFilenamePrefix, summaryWriter); } finally { IOUtils.closeQuietly(summaryWriter); } }