Example usage for org.apache.commons.lang3 SystemUtils getJavaIoTmpDir

List of usage examples for org.apache.commons.lang3 SystemUtils getJavaIoTmpDir

Introduction

In this page you can find the example usage for org.apache.commons.lang3 SystemUtils getJavaIoTmpDir.

Prototype

public static File getJavaIoTmpDir() 

Source Link

Document

Gets the Java IO temporary directory as a File .

Usage

From source file:com.gs.obevo.util.FileUtilsCobra.java

public static File createTempDir(String tmpDirPrefix) {
    File tmpFile;/* www .j a  v  a  2 s  .  c  o  m*/
    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
}

From source file:com.qwazr.server.ServletContextBuilder.java

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));
}

From source file:com.qwazr.server.ServletContextBuilder.java

public ServletContextBuilder servlet(final String name, final Class<? extends Servlet> servletClass,
        final GenericFactory instanceFactory, final String... urlPatterns) {

    final ServletInfo servletInfo;

    // WebServlet annotation
    final WebServlet webServlet = AnnotationsUtils.getFirstAnnotation(servletClass, WebServlet.class);
    if (webServlet != null) {

        servletInfo = servletInfo(StringUtils.isEmpty(name) ? webServlet.name() : name, servletClass,
                instanceFactory);/*  w w  w. j a  v a 2 s  . com*/
        servletInfo.setLoadOnStartup(webServlet.loadOnStartup());
        servletInfo.setAsyncSupported(webServlet.asyncSupported());

        servletInfo.addMappings(webServlet.value());
        servletInfo.addMappings(webServlet.urlPatterns());

        for (WebInitParam webInitParam : webServlet.initParams())
            servletInfo.addInitParam(webInitParam.name(), webInitParam.value());

    } else
        servletInfo = servletInfo(StringUtils.isEmpty(name) ? servletClass.getName() : name, servletClass,
                instanceFactory);

    if (urlPatterns != null && urlPatterns.length > 0)
        servletInfo.addMappings(urlPatterns);

    // ServletSecurity
    final ServletSecurity servletSecurity = AnnotationsUtils.getFirstAnnotation(servletClass,
            ServletSecurity.class);
    if (servletSecurity != null) {

        final ServletSecurityInfo servletSecurityInfo = new ServletSecurityInfo();

        // HttpConstraint
        final HttpConstraint httpConstraint = servletSecurity.value();
        servletSecurityInfo.setEmptyRoleSemantic(get(httpConstraint.value()));
        servletSecurityInfo.addRolesAllowed(httpConstraint.rolesAllowed());
        servletSecurityInfo.setTransportGuaranteeType(get(httpConstraint.transportGuarantee()));

        // HttpMethodConstraints
        for (final HttpMethodConstraint httpMethodConstraints : servletSecurity.httpMethodConstraints()) {

            final HttpMethodSecurityInfo httpMethodSecurityInfo = new HttpMethodSecurityInfo();
            httpMethodSecurityInfo.setMethod(httpMethodConstraints.value());
            httpMethodSecurityInfo.setEmptyRoleSemantic(get(httpMethodConstraints.emptyRoleSemantic()));
            httpMethodSecurityInfo.addRolesAllowed(httpMethodConstraints.rolesAllowed());
            httpMethodSecurityInfo.setTransportGuaranteeType(get(httpMethodConstraints.transportGuarantee()));

            servletSecurityInfo.addHttpMethodSecurityInfo(httpMethodSecurityInfo);
        }

        servletInfo.setServletSecurityInfo(servletSecurityInfo);
    }

    final MultipartConfig multipartConfig = AnnotationsUtils.getFirstAnnotation(servletClass,
            MultipartConfig.class);
    if (multipartConfig != null) {
        final String location = StringUtils.isEmpty(multipartConfig.location())
                ? SystemUtils.getJavaIoTmpDir().getAbsolutePath()
                : multipartConfig.location();
        servletInfo.setMultipartConfig(new MultipartConfigElement(location, multipartConfig.maxFileSize(),
                multipartConfig.maxRequestSize(), multipartConfig.fileSizeThreshold()));
    }

    addServlet(servletInfo);
    return this;
}

From source file:ch.ivyteam.ivy.maven.InstallEngineMojo.java

File getDownloadDirectory() {
    return SystemUtils.getJavaIoTmpDir();
}

From source file:org.eclipse.recommenders.utils.ChecksTest.java

@Test(expected = IllegalArgumentException.class)
public void testEnsureIsFile_WithDir() {
    ensureIsFile(SystemUtils.getJavaIoTmpDir());
}

From source file:org.h819.commons.file.MyFileUtils.java

/**
 * ? classpath ? jar ?//from  w w w  . ja  v a  2s  .com
 * jar  java 
 *
 * @param resourceName ? jar ??
 *                     ?
 *                     "/license.dat"  jar 
 *                     "/abc/license.dat"  jar /abc/ 
 * @return ???
 */
public static File copyResourceFileFromJarLibToTmpDir(String resourceName) {
    // ??
    //  { "/license.dat", "/pdfdecrypt.exe", "/SkinMagic.dll" };
    // { "/STCAIYUN.TTF" };
    InputStream is = MyFileUtils.class.getResourceAsStream(resourceName);

    if (is == null) {
        logger.info(resourceName + " not exist in jar liberary.");
        return null;
    }
    //??
    // java_jar_source_temp ???
    String tempfilepath = SystemUtils.getJavaIoTmpDir() + File.separator + MyConstants.JarTempDir
            + File.separator + resourceName;

    File resourceFile = new File(tempfilepath);

    logger.info("resource copy to :" + tempfilepath);

    try {
        // ???
        FileUtils.copyInputStreamToFile(is, resourceFile);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        IOUtils.closeQuietly(is);
        return null;
    }

    IOUtils.closeQuietly(is);
    return resourceFile;
}

From source file:org.h819.commons.file.MyPDFUtilss.java

/**
 *  STCAIYUN.TTF?? jar? classpath/*  w w  w . j av a2s.  co  m*/
 * ? pdf ??? pdf ?
 * ??????
 *
 * @return
 * @throws IOException
 */
private static Font getPdfFont() {

    //
    String fontName = "/STCAIYUN.TTF";
    String fontPath = SystemUtils.getJavaIoTmpDir() + File.separator + MyConstants.JarTempDir + File.separator
            + fontName;

    //?????
    if (!Files.exists(Paths.get(fontPath))) {
        MyFileUtils.copyResourceFileFromJarLibToTmpDir(fontName);
    }
    return FontFactory.getFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
}

From source file:org.h819.commons.file.MyPDFUtilss.java

/**
 * pdfdecrypt.exe //from w  ww.  j a  v a  2 s  .c  o m
 *
 * @return
 * @throws IOException
 */
private static String getPdfPdfdecryptExec() {

    //?????
    String exec1 = "/pdfdecrypt.exe";
    String exec2 = "/license.dat";

    String tempPath = SystemUtils.getJavaIoTmpDir() + File.separator + MyConstants.JarTempDir + File.separator;

    String exec1Path = tempPath + exec1;
    String exec2Path = tempPath + exec2;

    //?????
    if (!Files.exists(Paths.get(exec1Path)))
        MyFileUtils.copyResourceFileFromJarLibToTmpDir(exec1);

    if (!Files.exists(Paths.get(exec2Path)))
        MyFileUtils.copyResourceFileFromJarLibToTmpDir(exec2);

    return exec1Path;
}

From source file:org.openestate.is24.restapi.utils.ExportPool.java

/**
 * Create an empty {@link ExportPool}.//from w ww. j a v a 2 s.  c  o m
 * <p>
 * Files are stored into the default temporary directory of the Java runtime
 * environment.
 */
public ExportPool() {
    this(new File(SystemUtils.getJavaIoTmpDir(), "pool-" + System.currentTimeMillis()));
}

From source file:org.pgptool.gui.tempfolderfordecrypted.impl.DecryptedTempFolderImpl.java

@Override
public void afterPropertiesSet() throws Exception {
    String defaultValue1 = configsBasePathResolver.getConfigsBasePath() + File.separator + "decrypted";
    String defaultValue2 = SystemUtils.getJavaIoTmpDir().getAbsolutePath() + File.separator + "decrypted";
    tempFolderBasePath = appProps.find(CONFIG_DECRYPTED_TEMP_FOLDER, defaultValue1);

    if (ensureDirExists(tempFolderBasePath)) {
        return;/*from w w  w. jav a2 s.  c o  m*/
    }

    if (ensureDirExists(defaultValue1)) {
        UiUtils.messageBox(
                Messages.get("decrypt.temp.folder.changedDueToFailure", tempFolderBasePath, defaultValue1),
                Messages.get("term.attention"), MessageSeverity.WARNING);
        setTempFolderBasePath(defaultValue1);
    } else if (ensureDirExists(defaultValue2)) {
        UiUtils.messageBox(
                Messages.get("decrypt.temp.folder.changedDueToFailure", tempFolderBasePath, defaultValue2),
                Messages.get("term.attention"), MessageSeverity.WARNING);
        setTempFolderBasePath(defaultValue2);
    } else {
        UiUtils.messageBox(Messages.get("decrypt.temp.folder.failure"), Messages.get("term.attention"),
                MessageSeverity.WARNING);
        tempFolderBasePath = "./";
    }
}