Java Code Examples for org.apache.commons.io.FileUtils#getTempDirectoryPath()

The following examples show how to use org.apache.commons.io.FileUtils#getTempDirectoryPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaestroAgent.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor
 * @param maestroURL maestro_broker URL
 * @param peerInfo maestro peer information
 * @throws MaestroException if unable to create agent instance
 */
public MaestroAgent(final String maestroURL, final PeerInfo peerInfo) throws MaestroException {
    super(maestroURL, peerInfo);

    final AbstractConfiguration config = ConfigurationWrapper.getConfig();
    String pathStr = config.getString("agent.ext.path.override", null);

    if (pathStr == null){
        pathStr = Constants.HOME_DIR + "ext" + File.separator + "requests";
    }

    File defaultExtPointFile = new File(pathStr);
    if (defaultExtPointFile.exists()) {
        extensionPoints.add(new ExtensionPoint(defaultExtPointFile, false));
    }
    else  {
        logger.warn("The extension point at {} does not exist", defaultExtPointFile.getPath());
    }

    final String defaultSourceDir = FileUtils.getTempDirectoryPath() + File.separator + "maestro-agent-work";

    sourceRoot = config.getString("maestro.agent.source.root", defaultSourceDir);
    groovyHandler = new GroovyHandler(super.getClient());
}
 
Example 2
Source File: CompressArchiveUtil.java    From docker-java with Apache License 2.0 6 votes vote down vote up
public static File archiveTARFiles(File base, Iterable<File> files, String archiveNameWithOutExtension)
        throws IOException {
    File tarFile = new File(FileUtils.getTempDirectoryPath(), archiveNameWithOutExtension + ".tar");
    tarFile.deleteOnExit();
    try (TarArchiveOutputStream tos = new TarArchiveOutputStream(new GZIPOutputStream(new BufferedOutputStream(
            new FileOutputStream(tarFile))))) {
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        for (File file : files) {
            // relativize with method using Path otherwise method with File resolves the symlinks
            // and this is not want we want. If the file is a symlink, the relativized path should
            // keep the symlink name and not the target it points to.
            addFileToTar(tos, file.toPath(), relativize(base.toPath(), file.toPath()));
        }
    }

    return tarFile;
}
 
Example 3
Source File: CompressArchiveUtil.java    From docker-java with Apache License 2.0 6 votes vote down vote up
public static File archiveTARFiles(File base, Iterable<File> files, String archiveNameWithOutExtension) throws IOException {
    File tarFile = new File(FileUtils.getTempDirectoryPath(), archiveNameWithOutExtension + ".tar");
    TarArchiveOutputStream tos = new TarArchiveOutputStream(new FileOutputStream(tarFile));
    try {
        tos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
        for (File file : files) {
            TarArchiveEntry tarEntry = new TarArchiveEntry(file);
            tarEntry.setName(relativize(base, file));

            tos.putArchiveEntry(tarEntry);

            if (!file.isDirectory()) {
                FileUtils.copyFile(file, tos);
            }
            tos.closeArchiveEntry();
        }
    } finally {
        tos.close();
    }

    return tarFile;
}
 
Example 4
Source File: JarslinkActivatorTest.java    From sofa-jarslink with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
    PluginContext pluginContext = Mockito.mock(PluginContext.class);
    PluginActivator pluginActivator = new JarslinkActivator();
    pluginActivator.start(pluginContext);

    String tempPath = FileUtils.getTempDirectoryPath() + File.separator
                      + Constants.JARSLINK_IDENTITY;
    Assert.assertTrue(tempPath.equals(EnvironmentUtils
        .getProperty(Constants.JARSLINK_WORKING_DIR)));
}
 
Example 5
Source File: BaseTest.java    From sofa-jarslink with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    String workingDir = FileUtils.getTempDirectoryPath() + File.separator
                        + Constants.JARSLINK_IDENTITY;
    File dirFile = new File(workingDir);

    FileUtils.deleteQuietly(dirFile);

    dirFile.mkdir();
    dirFile.deleteOnExit();

    EnvironmentUtils.setProperty(Constants.JARSLINK_WORKING_DIR, workingDir);
}
 
Example 6
Source File: FileKeyStoreTest.java    From mxisd with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public KeyStore create() throws IOException {
    String path = FileUtils.getTempDirectoryPath() +
            "/mxisd-test-key-store-" +
            UUID.randomUUID().toString().replace("-", "");
    FileUtils.forceDeleteOnExit(new File(path));
    return new FileKeyStore(path);
}
 
Example 7
Source File: IndexBasedEntityCheckerTest.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
@BeforeClass
public static void createIndex() {
    // Generate a temporary folder
    indexDir = FileUtils.getTempDirectoryPath() + File.separator + System.currentTimeMillis();
    (new File(indexDir)).mkdir();
    Indexer indexer = Indexer.create(indexDir);
    for (int i = 0; i < CORRECT_URIS.length; ++i) {
        indexer.index(CORRECT_URIS[i]);
    }
    indexer.close();
}
 
Example 8
Source File: EngineTestUtils.java    From p3-batchrefine with Apache License 2.0 5 votes vote down vote up
public static File outputDirectory() {
    final File tempDir = new File(FileUtils.getTempDirectoryPath(), RandomStringUtils.randomAlphanumeric(4));
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            FileUtils.deleteQuietly(tempDir);
        }
    });

    return tempDir;
}
 
Example 9
Source File: InputFileTest.java    From ambari-logsearch with Apache License 2.0 4 votes vote down vote up
private File createFile(String filename) throws IOException {
  File newFile = new File(FileUtils.getTempDirectoryPath() + TEST_DIR_NAME + filename);
  FileUtils.writeStringToFile(newFile, TEST_LOG_FILE_CONTENT, Charset.defaultCharset());
  return newFile;
}
 
Example 10
Source File: MiniBrokerConfiguration.java    From maestro-java with Apache License 2.0 4 votes vote down vote up
/**
 * Configure the provider
 * @param provider the provider to configure
 */
public void configure(ActiveMqProvider provider) {
    logger.info("Configuring the provider");
    provider.setUri(CONNECTOR);


    /*
      Configure the broker to use the Maven's target directory (ie.:
      ${basedir}/target/test-classes) as the data directory for the
      broker. Therefore, it is cleaned whenever 'mvn clean' is run.
     */
    BrokerService brokerService = provider.getBroker();
    String path;
    URL url = this.getClass().getResource("/");

    /*
      Check if we are running it in within the jar, in which case we
      won't be able to use its location ...
     */

    if (url == null) {
        /*
         ... and, if that's the case, we use the OS temporary directory
         for the data directory
         */
        path = FileUtils.getTempDirectoryPath();
    }
    else {
        path = url.getPath();
    }

    brokerService.setDataDirectory(path);
    brokerService.setPersistent(false);

    try {
        logger.info("Adding MQTT connector");
        TransportConnector mqttConnector = new TransportConnector();

        mqttConnector.setUri(new URI("mqtt://localhost:1883"));
        mqttConnector.setName("mqtt");
        brokerService.addConnector(mqttConnector);


        logger.info("Adding AMQP connector");
        TransportConnector amqpConnector = new TransportConnector();
        amqpConnector.setUri(new URI("amqp://localhost:5672"));
        amqpConnector.setName("amqp");
        brokerService.addConnector(amqpConnector);

        TransportConnector defaultConnector = new TransportConnector();

        defaultConnector.setUri(new URI(CONNECTOR));
        defaultConnector.setName("default");
        brokerService.addConnector(defaultConnector);
    } catch (Exception e) {
        throw new RuntimeException("Unable to add a connector for the "
                + "service: " + e.getMessage(), e);
    }
}
 
Example 11
Source File: TusFileUploadService.java    From tus-java-server with MIT License 4 votes vote down vote up
public TusFileUploadService() {
    String storagePath = FileUtils.getTempDirectoryPath() + File.separator + "tus";
    this.uploadStorageService = new DiskStorageService(idFactory, storagePath);
    this.uploadLockingService = new DiskLockingService(idFactory, storagePath);
    initFeatures();
}
 
Example 12
Source File: RestFileManager.java    From sdk-rest with MIT License 4 votes vote down vote up
/**
 * Will create a unique sub folder in the temp directory. This is done so that we can name the file with the original file
 * name without having to worry about file name collisions. The bh rest apis will name the attached file what the system File
 * created in this method is named, which is why we are not using a randomly generated file name here.
 * 
 * Will create a file in tempDir\\uniqueSubFolder\\filename.type
 * 
 * 
 * @param multipartFile
 * @return
 * @throws IOException
 */
public MultiValueMap<String, Object> addFileToMultiValueMap(MultipartFile multipartFile) throws IOException {

    String newFolderPath = FileUtils.getTempDirectoryPath() + "/" + System.currentTimeMillis();

    File newFolder = new File(newFolderPath);

    FileUtils.forceMkdir(newFolder);

    String originalFileName = multipartFile.getOriginalFilename();
    String filePath = newFolderPath + "/" + originalFileName;
    File file = new File(filePath);

    FileCopyUtils.copy(multipartFile.getBytes(), file);

    return addFileToMultiValueMap(file);

}
 
Example 13
Source File: TestStandardBullhornApiRestFile.java    From sdk-rest with MIT License 4 votes vote down vote up
private File getFile() throws IOException {
	MultipartFile multipartFile = getResume();
	String newFolderPath = FileUtils.getTempDirectoryPath() + "/" + System.currentTimeMillis();

	File newFolder = new File(newFolderPath);

	FileUtils.forceMkdir(newFolder);

	String originalFileName = multipartFile.getOriginalFilename();
	String filePath = newFolderPath + "/" + originalFileName;
	File file = new File(filePath);

	FileCopyUtils.copy(multipartFile.getBytes(), file);

	return file;

}
 
Example 14
Source File: PositionStoringLuceneIndexCreatorTest.java    From Palmetto with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void test() throws CorruptIndexException, IOException {
    File indexDir = new File(
            FileUtils.getTempDirectoryPath() + File.separator + "temp_index" + Long.toString(System.nanoTime()));
    Assert.assertTrue(indexDir.mkdir());
    Iterator<IndexableDocument> docIterator = Arrays.asList(DOCUMENTS).iterator();
    // create the index
    PositionStoringLuceneIndexCreator creator = new PositionStoringLuceneIndexCreator(
            Palmetto.DEFAULT_TEXT_INDEX_FIELD_NAME, Palmetto.DEFAULT_DOCUMENT_LENGTH_INDEX_FIELD_NAME);
    Assert.assertTrue(creator.createIndex(indexDir, docIterator));
    LuceneIndexHistogramCreator hCreator = new LuceneIndexHistogramCreator(
            Palmetto.DEFAULT_DOCUMENT_LENGTH_INDEX_FIELD_NAME);
    hCreator.createLuceneIndexHistogram(indexDir.getAbsolutePath());

    // test the created index
    // create an adapter
    WindowSupportingLuceneCorpusAdapter adapter = null;
    try {
        adapter = WindowSupportingLuceneCorpusAdapter.create(indexDir.getAbsolutePath(),
                Palmetto.DEFAULT_TEXT_INDEX_FIELD_NAME, Palmetto.DEFAULT_DOCUMENT_LENGTH_INDEX_FIELD_NAME);
        // query the test words
        IntIntOpenHashMap docLengths = new IntIntOpenHashMap();
        IntObjectOpenHashMap<IntArrayList[]> wordPositions = adapter.requestWordPositionsInDocuments(TEST_WORDS,
                docLengths);
        // compare the result with the expected counts
        int positionInDoc;
        IntArrayList[] positionsInDocs;
        for (int i = 0; i < EXPECTED_WORD_POSITIONS.length; ++i) {
            positionsInDocs = wordPositions.get(i);
            for (int j = 0; j < positionsInDocs.length; ++j) {
                if (EXPECTED_WORD_POSITIONS[i][j] < 0) {
                    Assert.assertNull("Expected null because the word \"" + TEST_WORDS[j]
                            + "\" shouldn't be found inside document " + i + ". But got a position list instead.",
                            positionsInDocs[j]);
                } else {
                    Assert.assertEquals(1, positionsInDocs[j].elementsCount);
                    positionInDoc = positionsInDocs[j].buffer[0];
                    Assert.assertEquals("Expected the word \"" + TEST_WORDS[j] + "\" in document " + i
                            + " at position " + EXPECTED_WORD_POSITIONS[i][j] + " but got position " + positionInDoc
                            + " form the index.", EXPECTED_WORD_POSITIONS[i][j], positionInDoc);
                }
            }
        }

        // test the window based counting
        BooleanSlidingWindowFrequencyDeterminer determiner = new BooleanSlidingWindowFrequencyDeterminer(adapter,
                WINDOW_SIZE);
        CountedSubsets subsets = determiner.determineCounts(new String[][] { TEST_WORDS },
                new SegmentationDefinition[] { new SegmentationDefinition(new int[0], new int[0][0], null) })[0];
        Assert.assertArrayEquals(EXPECTED_COUNTS, subsets.counts);
    } finally {
        if (adapter != null) {
            adapter.close();
        }
    }
}