Java Code Examples for org.apache.commons.io.FilenameUtils.concat()

The following are Jave code examples for showing how to use concat() of the org.apache.commons.io.FilenameUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: AccessConverter   File: AccessConverter.java   View Source Code Vote up 6 votes
private static File getOutputFile(String extension) {
    outputFilename = args.HasOption("output-file") ? 
            args.GetOption("output-file") : 
            FilenameUtils.getBaseName(args.GetOption("access-file")) + "." + extension;
    
    File outFile = new File(FilenameUtils.concat(FilenameUtils.getFullPath(args.GetOption("access-file")), outputFilename));
    if(outFile.exists()) {
        try {
            outFile.delete();
        } catch(SecurityException e) {
            Error(String.format("Could not delete existing output file '%s'", outputFilename));
            return null;
        }
    }
    
    return outFile;
}
 
Example 2
Project: monarch   File: ClusterConfigurationService.java   View Source Code Vote up 6 votes
public ClusterConfigurationService(Cache cache) throws IOException {
  this.cache = (GemFireCacheImpl) cache;
  Properties properties = cache.getDistributedSystem().getProperties();
  // resolve the cluster config dir
  String clusterConfigRootDir = properties.getProperty(CLUSTER_CONFIGURATION_DIR);

  if (StringUtils.isBlank(clusterConfigRootDir)) {
    clusterConfigRootDir = System.getProperty("user.dir");
  } else {
    File diskDir = new File(clusterConfigRootDir);
    if (!diskDir.exists() && !diskDir.mkdirs()) {
      throw new IOException("Cannot create directory : " + clusterConfigRootDir);
    }
    clusterConfigRootDir = diskDir.getCanonicalPath();
  }

  // resolve the file paths
  String configDiskDirName =
      CLUSTER_CONFIG_DISK_DIR_PREFIX + cache.getDistributedSystem().getName();

  configDirPath = FilenameUtils.concat(clusterConfigRootDir, CLUSTER_CONFIG_ARTIFACTS_DIR_NAME);
  configDiskDirPath = FilenameUtils.concat(clusterConfigRootDir, configDiskDirName);
  sharedConfigLockingService = getSharedConfigLockService(cache.getDistributedSystem());
  status.set(SharedConfigurationStatus.NOT_STARTED);
}
 
Example 3
Project: Word2VecfJava   File: CNNSentenceClassification.java   View Source Code Vote up 6 votes
public static DataSetIterator getDataSetIterator(String DATA_PATH, boolean isTraining, WordVectors wordVectors, int minibatchSize,
                                                  int maxSentenceLength, Random rng ){
    String path = FilenameUtils.concat(DATA_PATH, (isTraining ? "aclImdb/train/" : "aclImdb/test/"));
    String positiveBaseDir = FilenameUtils.concat(path, "pos");
    String negativeBaseDir = FilenameUtils.concat(path, "neg");

    File filePositive = new File(positiveBaseDir);
    File fileNegative = new File(negativeBaseDir);

    Map<String,List<File>> reviewFilesMap = new HashMap<>();
    reviewFilesMap.put("Positive", Arrays.asList(filePositive.listFiles()));
    reviewFilesMap.put("Negative", Arrays.asList(fileNegative.listFiles()));

    LabeledSentenceProvider sentenceProvider = new FileLabeledSentenceProvider(reviewFilesMap, rng);

    return new CnnSentenceDataSetIterator.Builder()
            .sentenceProvider(sentenceProvider)
            .wordVectors(wordVectors)
            .minibatchSize(minibatchSize)
            .maxSentenceLength(maxSentenceLength)
            .useNormalizedWordVectors(false)
            .build();
}
 
Example 4
Project: NeuralNetworksLite   File: SentimentExampleIterator.java   View Source Code Vote up 6 votes
/**
 * @param dataDirectory the directory of the IMDB review data set
 * @param wordVectors WordVectors object
 * @param batchSize Size of each minibatch for training
 * @param truncateLength If reviews exceed
 * @param train If true: return the training data. If false: return the testing data.
 */
public SentimentExampleIterator(String dataDirectory, WordVectors wordVectors, int batchSize, int truncateLength, boolean train) throws IOException {
	this.batchSize = batchSize;
	this.vectorSize = wordVectors.getWordVector(wordVectors.vocab().wordAtIndex(0)).length;


	File p = new File(FilenameUtils.concat(dataDirectory, "aclImdb/" + (train ? "train" : "test") + "/pos/") + "/");
	File n = new File(FilenameUtils.concat(dataDirectory, "aclImdb/" + (train ? "train" : "test") + "/neg/") + "/");
	positiveFiles = p.listFiles();
	negativeFiles = n.listFiles();

	this.wordVectors = wordVectors;
	this.truncateLength = truncateLength;

	tokenizerFactory = new DefaultTokenizerFactory();
	tokenizerFactory.setTokenPreProcessor(new CommonPreprocessor());
}
 
Example 5
Project: generator-thundr-gae-react   File: AttachmentService.java   View Source Code Vote up 5 votes
/**
 * Get a signed url to view an attachment. The url will last 24 hours. The file name portion of the id is url escaped internally.
 *
 * @param id The id of the attachment.
 * @return Url
 */
public String getDownloadUrl(String id) {
    String filename = FilenameUtils.getName(id);
    String path = FilenameUtils.getFullPath(id);
    String escapedFullPath = FilenameUtils.concat(path, UrlEscapers.urlFragmentEscaper().escape(filename));
    return cloudStorage.generateSignedUrl(gcsDefaultBucket, escapedFullPath, DEFAULT_LINK_EXPIRY_DURATION);
}
 
Example 6
Project: laozhongyi   File: GeneratedFileManager.java   View Source Code Vote up 5 votes
public static void mkdirForHyperParameterConfig() {
    final String homeDir = System.getProperty("user.home");
    final String logDir = "hyper" + new LocalDateTime().toString();
    mHyperParameterConfigDirPath = FilenameUtils.concat(homeDir, logDir);
    try {
        FileUtils.forceMkdir(new File(mHyperParameterConfigDirPath));
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 7
Project: laozhongyi   File: GeneratedFileManager.java   View Source Code Vote up 5 votes
public static void mkdirForLog() {
    final String homeDir = System.getProperty("user.home");
    final String logDir = "log" + new LocalDateTime().toString();
    mLogDirPath = FilenameUtils.concat(homeDir, logDir);
    try {
        FileUtils.forceMkdir(new File(mLogDirPath));
    } catch (final IOException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 8
Project: spring2ts   File: BaseClientBuilder.java   View Source Code Vote up 5 votes
protected void copyResources(String baseClassPath, File destDir, String... relativePaths) throws IOException {
    for (String relativePath : relativePaths) {
        String path = FilenameUtils.concat(baseClassPath, relativePath);
        path = path.replace('\\', '/');
        String fileName = path.contains("/") ? StringUtils.substringAfterLast(path, "/") : path;
        copyResource(new ClassPathResource(path), new File(destDir, fileName));
    }
}
 
Example 9
Project: monarch   File: ZipUtilsJUnitTest.java   View Source Code Vote up 5 votes
@Test
public void testZipUtils() throws Exception {
  File zipFile = new File(zipFolder, "target.zip");
  assertFalse(zipFile.exists());
  assertFalse(zipFile.isFile());

  ZipUtils.zipDirectory(sourceFolder.getCanonicalPath(), zipFile.getCanonicalPath());
  assertTrue(zipFile.exists());
  assertTrue(zipFile.isFile());

  File destinationFolder = new File(
      FilenameUtils.concat(temporaryFolder.getRoot().getCanonicalPath(), destinationFolderName));
  assertFalse(destinationFolder.exists());
  assertFalse(destinationFolder.isFile());

  ZipUtils.unzip(zipFile.getCanonicalPath(), destinationFolder.getCanonicalPath());
  assertTrue(destinationFolder.exists());
  assertTrue(destinationFolder.isDirectory());

  File[] destinationSubDirs = destinationFolder.listFiles();
  assertNotNull(destinationSubDirs);
  assertEquals(2, destinationSubDirs.length);

  File destinationClusterTextFile =
      new File(FilenameUtils.concat(destinationFolder.getCanonicalPath(),
          clusterFolderName + File.separator + clusterTextFileName));
  assertTrue(destinationClusterTextFile.exists());
  assertTrue(destinationClusterTextFile.isFile());

  File destinationGroupTextFile =
      new File(FilenameUtils.concat(destinationFolder.getCanonicalPath(),
          groupFolderName + File.separator + groupTextFileName));
  assertTrue(destinationGroupTextFile.exists());
  assertTrue(destinationGroupTextFile.isFile());

  assertTrue(clusterText.equals(FileUtils.readFileToString(destinationClusterTextFile)));
  assertTrue(groupText.equals(FileUtils.readFileToString(destinationGroupTextFile)));
}
 
Example 10
Project: buenojo   File: ImageResourceService.java   View Source Code Vote up 4 votes
private String absolutePathForFilename(String filename){
	return FilenameUtils.concat(env.getImageResourceAbsolutePath(), filename);
}
 
Example 11
Project: buenojo   File: ImageResourceService.java   View Source Code Vote up 4 votes
private String relativePathForFilename(String filename){
	return FilenameUtils.concat(env.getImageResourceRelativePath(), filename);
}
 
Example 12
Project: WebPLP   File: PLPProject.java   View Source Code Vote up 4 votes
/**
 * Loads a PLP6 project. The given file must be a directory, and have a structure as
 * specified by {@link #save()}
 * 
 * @param projectDirectory
 *            The directory of the project to load. This file must be a DIRECTORY, and
 *            have a structure as specified by {@link #save()}
 * @return A {@link PLPProject} representative of the information stored in the given
 *         directory.
 * @throws IOException
 */
private static PLPProject loadCurrent(File projectDirectory) throws IOException
{
	validateProjectDirectory(projectDirectory);
	File projectFile = validateAndFilizeProjectFile(projectDirectory);
	
	if (!projectFile.exists())
		throw new IllegalArgumentException("Project file not found.");
		
	String fileString = FileUtils.readFileToString(projectFile);
	JSONObject projectDetails = new JSONObject(fileString);
	String name = projectDetails.optString(NAME_KEY);
	//String type = projectDetails.optString(NAME_KEY);
	String type = projectDetails.optString(TYPE_KEY);
	String sourceDirectoryName = projectDetails.optString(SOURCE_NAME_KEY, "src");
	String lstAsmFiles = projectDetails.optString(SOURCE_FILES);
	String[] listFiles = lstAsmFiles.split(",");
	
	Path projectPath = projectDirectory.toPath();
	Path sourcePath = projectPath.resolve(sourceDirectoryName);
	File sourceDirectory = sourcePath.toFile();
	
	//PLPProject project = new PLPProject(name, type);
	PLPProject project = new PLPProject(name, type, projectPath.toString());
	
	for (String fileName : listFiles)
	{
		String fullPath = FilenameUtils.concat(sourceDirectory.getAbsolutePath(), fileName);
		String sourceName = FilenameUtils.removeExtension(fileName);
		
		SimpleASMFile sourceFile = new SimpleASMFile(project, fileName, AsmFileContent(fullPath));
		project.add(sourceFile);
	}
	
	/*for (File file : sourceDirectory.listFiles())
	{
		String sourceName = file.getName();
		
		sourceName = FilenameUtils.removeExtension(sourceName);
		
		//While associating asmfile to the project, we need to pass the content of the file also, otherwise when 
		//user tries to open the respective file from project explorer, Editor pane will show empty file - Harsha
		SimpleASMFile sourceFile = new SimpleASMFile(project, sourceName, AsmFileContent(file.getAbsolutePath()));
		//SimpleASMFile sourceFile = new SimpleASMFile(project, sourceName);
		project.add(sourceFile);
	}*/
	
	return project;
}
 
Example 13
Project: Word2VecfJava   File: DL4JCNNSentClassifyExample.java   View Source Code Vote up 4 votes
public static void main (String[] args) throws IOException {
    log.info("download and extract data...");
    CNNSentenceClassification.aclImdbDownloader(DATA_URL, DATA_PATH);

    // basic configuration
    int batchSize = 32;
    int vectorSize = 300;               //Size of the word vectors. 300 in the Google News model
    int nEpochs = 1;                    //Number of epochs (full passes of training data) to train on
    int truncateReviewsToLength = 256;  //Truncate reviews with length (# words) greater than this
    int cnnLayerFeatureMaps = 100;      //Number of feature maps / channels / depth for each CNN layer
    PoolingType globalPoolingType = PoolingType.MAX;
    Random rng = new Random(12345); //For shuffling repeatability

    log.info("construct cnn model...");
    ComputationGraph net = CNNSentenceClassification.buildCNNGraph(vectorSize, cnnLayerFeatureMaps, globalPoolingType);
    log.info("number of parameters by layer:");
    for (Layer l : net.getLayers()) {
        log.info("\t" + l.conf().getLayer().getLayerName() + "\t" + l.numParams());
    }

    // Load word vectors and get the DataSetIterators for training and testing
    log.info("loading word vectors and creating DataSetIterators...");
    WordVectors wordVectors = WordVectorSerializer.loadStaticModel(new File(WORD_VECTORS_PATH));
    DataSetIterator trainIter = CNNSentenceClassification.getDataSetIterator(DATA_PATH, true, wordVectors, batchSize,
            truncateReviewsToLength, rng);
    DataSetIterator testIter = CNNSentenceClassification.getDataSetIterator(DATA_PATH, false, wordVectors, batchSize,
            truncateReviewsToLength, rng);

    log.info("starting training...");
    for (int i = 0; i < nEpochs; i++) {
        net.fit(trainIter);
        log.info("Epoch " + i + " complete. Starting evaluation:");
        //Run evaluation. This is on 25k reviews, so can take some time
        Evaluation evaluation = net.evaluate(testIter);
        log.info(evaluation.stats());
    }

    // after training: load a single sentence and generate a prediction
    String pathFirstNegativeFile = FilenameUtils.concat(DATA_PATH, "aclImdb/test/neg/0_2.txt");
    String contentsFirstNegative = FileUtils.readFileToString(new File(pathFirstNegativeFile));
    INDArray featuresFirstNegative = ((CnnSentenceDataSetIterator)testIter).loadSingleSentence(contentsFirstNegative);
    INDArray predictionsFirstNegative = net.outputSingle(featuresFirstNegative);
    List<String> labels = testIter.getLabels();
    log.info("\n\nPredictions for first negative review:");
    for( int i=0; i<labels.size(); i++ ){
        log.info("P(" + labels.get(i) + ") = " + predictionsFirstNegative.getDouble(i));
    }
}
 
Example 14
Project: buenojo   File: ImageResourceService.java   View Source Code Vote up 2 votes
private String getAbsolutePath(String relativePath){

		return FilenameUtils.concat(env.getGameResourcesBasePath(), relativePath);
	}
 
Example 15
Project: buenojo   File: BuenOjoEnvironment.java   View Source Code Vote up 2 votes
public String getImageResourceAbsolutePath(){
	
	return FilenameUtils.concat(getGameResourcesAbsolutePath(), BuenOjoFileUtils.IMAGE_RESOURCE_DIR);
}