/** * Assumes no security manager exists. */ @Test public void testGetJavaIoTmpDir() { final File dir = SystemUtils.getJavaIoTmpDir(); assertNotNull(dir); assertTrue(dir.exists()); }
public static File getJavaIoTmpDir(ActionContext actionContext){ return SystemUtils.getJavaIoTmpDir(); }
/** * Create an empty {@link ExportPool}. * <p> * Files are stored into the default temporary directory of the Java runtime * environment. */ public ExportPool() { this(new File(SystemUtils.getJavaIoTmpDir(), "pool-" + System.currentTimeMillis())); }
public static File createTempDir(String tmpDirPrefix) { File tmpFile; try { tmpFile = File.createTempFile(tmpDirPrefix, ".tmp", SystemUtils.getJavaIoTmpDir()); } catch (IOException e) { throw new RuntimeException(e); } FileUtils.deleteQuietly(tmpFile); String tmpFilePath = tmpFile.getAbsolutePath(); return new File(tmpFilePath.substring(0, tmpFilePath.length() - 4)); // trim the extension }
public static File createTempDir(String tmpDirPrefix) { File tmpFile; try { tmpFile = File.createTempFile(tmpDirPrefix, ".tmp", SystemUtils.getJavaIoTmpDir()); } catch (IOException e) { throw new RuntimeException(e); } FileUtils.deleteQuietly(tmpFile); String tmpFilePath = tmpFile.getAbsolutePath(); return new File(tmpFilePath.substring(0, tmpFilePath.length() - 4)); // trim the extension }
public static File createTemporaryFolder() { File baseDir = SystemUtils.getJavaIoTmpDir(); String baseName = new StringBuilder(BUFFER_NAME).append(System.currentTimeMillis()).append("-").toString(); for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) { File tempDir = new File(baseDir, baseName + counter); if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException("Failed to create directory within " + TEMP_DIR_ATTEMPTS + " attempts (tried " + baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')'); }
public static File createTemporaryFolder() { File baseDir = SystemUtils.getJavaIoTmpDir(); String baseName = new StringBuilder(BUFFER_NAME).append(System.currentTimeMillis()).append("-").toString(); for (int counter = 0; counter < TEMP_DIR_ATTEMPTS; counter++) { File tempDir = new File(baseDir, baseName + counter); if (tempDir.mkdir()) { return tempDir; } } throw new IllegalStateException("Failed to create directory within " + TEMP_DIR_ATTEMPTS + " attempts (tried " + baseName + "0 to " + baseName + (TEMP_DIR_ATTEMPTS - 1) + ')'); }
private static String getUrlUncached(String dbName, boolean persistToFile) { Validate.notNull(dbName, "dbName parameter must be specified"); String url; if (persistToFile) { // In order to allow access to the db from multiple processes, the FILE_LOCK=NO setting is needed. // This however, does not prevent concurrency issues from multiple writers. // Other options found in the docs that we are not using: MVCC=TRUE;FILE_LOCK=SERIALIZED String dbFileName = new File(SystemUtils.getJavaIoTmpDir(), dbName).getAbsolutePath(); LOG.info("writing db to file:{}", dbFileName); url = String.format("jdbc:h2:file:%s;FILE_LOCK=NO", dbFileName); } else { // use DB_CLOSE_DELAY=-1 to keep the DB open for the duration of the JVM url = String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1", dbName); } LOG.info("setting up in memory db: {}", url); return url; } }
private static String getUrlUncached(String dbName, boolean persistToFile) { Validate.notNull(dbName, "dbName parameter must be specified"); String url; if (persistToFile) { // In order to allow access to the db from multiple processes, the FILE_LOCK=NO setting is needed. // This however, does not prevent concurrency issues from multiple writers. // Other options found in the docs that we are not using: MVCC=TRUE;FILE_LOCK=SERIALIZED String dbFileName = new File(SystemUtils.getJavaIoTmpDir(), dbName).getAbsolutePath(); LOG.info("writing db to file:{}", dbFileName); url = String.format("jdbc:h2:file:%s;FILE_LOCK=NO", dbFileName); } else { // use DB_CLOSE_DELAY=-1 to keep the DB open for the duration of the JVM url = String.format("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1", dbName); } LOG.info("setting up in memory db: {}", url); return url; } }
public static EntityManagerFactory createTempEntityManagerFactory(String persistenceUnitName, String context, Map<String, String> jpaParameters) { Map<String, String> allJpaParameters = new HashMap<String, String>(); allJpaParameters.putAll(jpaParameters); allJpaParameters.putAll(HIBERNATE_H2_CONFIG); File tempDirFile = SystemUtils.getJavaIoTmpDir(); File databaseFile = new File(tempDirFile, context); String h2dataPath = databaseFile.getAbsolutePath() + File.separator + "h2data"; String jdbcUrl = "jdbc:h2:file:" + h2dataPath; allJpaParameters.put(AvailableSettings.JDBC_URL, jdbcUrl); if (log.isTraceEnabled()) { log.trace("will store H2 data in " + h2dataPath); log.trace("allJpaParameters = " + allJpaParameters); } if (log.isDebugEnabled()) { log.debug("jdbc url is\n" + jdbcUrl); } EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnitName, allJpaParameters); return entityManagerFactory; }
public ServletContextBuilder setDefaultMultipartConfig(String location, long maxFileSize, long maxRequestSize, int fileSizeThreshold) { return setDefaultMultipartConfig(new MultipartConfigElement( StringUtils.isEmpty(location) ? SystemUtils.getJavaIoTmpDir().getAbsolutePath() : location, maxFileSize, maxRequestSize, fileSizeThreshold)); }
protected static synchronized void loadResourcesStatic(Connection connection, Optional<String> schema) throws LiquibaseException, IOException { String tmpDirectory = SystemUtils.getJavaIoTmpDir().getAbsolutePath();
protected static synchronized void loadResourcesStatic(Connection connection, Optional<String> schema) throws LiquibaseException, IOException { String tmpDirectory = SystemUtils.getJavaIoTmpDir().getAbsolutePath();
protected String getContent(final ContentWriter out, final String encoding) throws TikaException { File tempFile = null; final String enc = encoding == null ? Constants.UTF_8 : encoding; try (DeferredFileOutputStream dfos = new DeferredFileOutputStream(memorySize, "tika", ".tmp", SystemUtils.getJavaIoTmpDir())) { final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(dfos, enc)); out.accept(writer); writer.flush(); if (!dfos.isInMemory()) { tempFile = dfos.getFile(); } try (Reader reader = new InputStreamReader(getContentStream(dfos), enc)) { return TextUtil.normalizeText(reader).initialCapacity(initialBufferSize).maxAlphanumTermSize(maxAlphanumTermSize) .maxSymbolTermSize(maxSymbolTermSize).duplicateTermRemoved(replaceDuplication).execute(); } } catch (final TikaException e) { throw e; } catch (final Exception e) { throw new ExtractException("Failed to read a content.", e); } finally { if (tempFile != null && tempFile.exists() && !tempFile.delete()) { logger.warn("Failed to delete " + tempFile.getAbsolutePath()); } } }
@Test public void testCreateBufferFileOutNonExisting() throws TaskIOException { FileTaskOutput out = new FileTaskOutput(new File("I dont", "exist")); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(SystemUtils.getJavaIoTmpDir().getAbsolutePath(), tmp.getParent()); }
@Test public void testCreateBufferDirectoryOutNonExisting() throws TaskIOException { DirectoryTaskOutput out = new DirectoryTaskOutput(new File("I dont exist")); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(SystemUtils.getJavaIoTmpDir().getAbsolutePath(), tmp.getParent()); }
@Test public void testCreateBufferFileOrDirectoryOutNonExisting() throws TaskIOException { FileOrDirectoryTaskOutput out = new FileOrDirectoryTaskOutput(new File("I dont exist")); File tmp = IOUtils.createTemporaryBuffer(out); assertTrue(tmp.exists()); assertTrue(tmp.isFile()); assertEquals(SystemUtils.getJavaIoTmpDir().getAbsolutePath(), tmp.getParent()); }
ElasticSearchIdAndVersionStream createElasticSearchIdAndVersionStream(ScrutineerCommandLineOptions options) { try { this.client = new PreBuiltTransportClient(new NodeFactory().createSettings(options)); addTransportClients(options); return new ElasticSearchIdAndVersionStream(new ElasticSearchDownloader(client, options.indexName, options.query, idAndVersionFactory), new ElasticSearchSorter(createSorter()), new IteratorFactory(idAndVersionFactory), SystemUtils.getJavaIoTmpDir().getAbsolutePath()); } catch (Exception e) { throw new RuntimeException(e); } }
String tmpDirectory = SystemUtils.getJavaIoTmpDir().getAbsolutePath(); File jobTempDirectory = new File(tmpDirectory, "kapua-job/" + scopeId.toCompactId()); if (!jobTempDirectory.exists() && !jobTempDirectory.mkdirs()) {
if (multipartConfig != null) { final String location = StringUtils.isEmpty(multipartConfig.location()) ? SystemUtils.getJavaIoTmpDir().getAbsolutePath() : multipartConfig.location(); servletInfo.setMultipartConfig(new MultipartConfigElement(location, multipartConfig.maxFileSize(),