Example usage for org.apache.commons.lang SystemUtils getUserHome

List of usage examples for org.apache.commons.lang SystemUtils getUserHome

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils getUserHome.

Prototype

public static File getUserHome() 

Source Link

Document

Gets the user home directory as a File.

Usage

From source file:com.apress.prospringintegration.customadapters.inbound.eventdriven.fsmon.DirectoryMonitorClient.java

public static void main(String[] args) throws Throwable {
    File[] files = { new File(new File(SystemUtils.getUserHome(), "Desktop"), "test2"),
            new File(new File(SystemUtils.getUserHome(), "Desktop"), "test1") };

    Executor ex = Executors.newFixedThreadPool(10);

    final LinuxInotifyDirectoryMonitor monitor = new LinuxInotifyDirectoryMonitor();
    monitor.setExecutor(ex);//from  www.  j a v  a 2  s. c  om
    monitor.afterPropertiesSet();

    final DirectoryMonitor.FileAddedListener fileAddedListener = new DirectoryMonitor.FileAddedListener() {
        @Override
        public void fileAdded(File dir, String fn) {
            System.out
                    .println("A new file in " + dir.getAbsolutePath() + " called " + fn + " has been noticed");
        }
    };

    for (File f : files) {
        monitor.monitor(f, fileAddedListener);
    }
}

From source file:com.joshlong.esb.springintegration.modules.net.sftp.Main.java

public static void main(String[] args) throws Throwable {
    boolean testKey = true;
    SFTPSessionFactory factory = testKey
            ? sftpSessionFactory("joshlong.co    m", null, "ubuntu",
                    SystemUtils.getUserHome() + "/jlongec2.pem", null, 22)
            : // this wont work on your machine. get yer own!
            sftpSessionFactory("jlong", "cowbell", "jlong", null, null, 22);

    String suffix = (testKey ? "key" : "pass");
    run(factory, SystemUtils.getUserHome() + "/local_mount_" + suffix, "remote_mount_" + suffix);
}

From source file:com.enonic.cms.core.boot.HomeResolver.java

public HomeResolver() {
    setSystemProperties(System.getProperties());
    setEnvironment(System.getenv());
    setDefaultHome(new File(SystemUtils.getUserHome(), "cms-home"));
}

From source file:edu.kit.dama.staging.util.StagingUtils.java

/**
 * Get the temporary directory all transfers. This directory is located in the
 * user home directory under ~/.lsdf/. Within the temporary directory the
 * transfer can store status information or checkpoint data to be able to
 * resume failed transfers./*from  w  w w .  j  a va2s  .  co  m*/
 *
 * @return The transfers temporary directory
 *
 * @throws IOException If there was not set any TID for this transfer or if
 * there are problems getting the user's home directory
 */
public static String getTempDir() throws IOException {
    File userHome = SystemUtils.getUserHome();
    if (userHome == null || !userHome.isDirectory() || !userHome.canRead() || !userHome.canWrite()) {
        throw new IOException("Invalid user home directory '" + userHome + "'");
    }
    return FilenameUtils.concat(userHome.getCanonicalPath(), ".lsdf");
}

From source file:net.erdfelt.android.sdkfido.FetcherConfig.java

public FetcherConfig() {
    this.fetchTargets = new ArrayList<String>();
    // Setup complex default values
    this.rcDir = new File(SystemUtils.getUserHome(), ".sdkfido");
    this.workDir = new File(rcDir, "work");
    try {//from www .  j a  v  a  2 s.c o  m
        // Try to guess the android platforms directory.
        this.platformsDir = LocalAndroidPlatforms.findLocalJavaSdk();
    } catch (IOException e) {
        // Be quiet about inability to find android platforms directory,
        // as this value can be provided to the system by the user.
    }
    this.outputDir = new File(rcDir, "projects");
}

From source file:de.awtools.basic.file.FindFilesTest.java

@BeforeClass
public static void beforeClass() throws Exception {
    TMP_DIR = new File(SystemUtils.getUserHome(), BUILD_TMP_DIR);
    try {/*  w  w w.  j ava 2s .c  om*/
        FileUtils.forceMkdir(TMP_DIR);
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    AWToolsFileUtils.createFilePath(TMP_DIR.getPath(), TEST_FILE);

    File file1 = new File(TMP_DIR, "findmy.txt");
    File file2 = new File(TMP_DIR, "test/winkler/findmy.txt");
    File file3 = new File(TMP_DIR, "test/winkler/arbeit/findmy.txt");

    file1.createNewFile();
    file2.createNewFile();
    file3.createNewFile();
}

From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParserTest.java

@Test
public void testSetMultipleOptions() throws CmdLineParseException {
    FetcherConfig config = new FetcherConfig();

    File expectedDir = new File(SystemUtils.getUserHome(), FilenameUtils.separatorsToSystem(".sdkfido/work"));

    Assert.assertThat("Config.dryRun", config.isDryRun(), is(false));
    Assert.assertThat("Config.workDir", config.getWorkDir(), is(expectedDir));

    File otherWork = testingdir.getFile("work");

    StringWriter capture = new StringWriter();
    ConfigCmdLineParser parser = new ConfigCmdLineParser(this, config);
    parser.setOut(capture);/*from w w  w.  ja va 2s .co m*/
    String[] args = { "--dryRun", "true", "--workDir", otherWork.getAbsolutePath() };
    parser.parse(args);

    Assert.assertThat("Config.dryRun", config.isDryRun(), is(true));
    Assert.assertThat("Config.workDir", config.getWorkDir(), is(otherWork));
}

From source file:edu.kit.dama.staging.util.StagingUtils.java

/**
 * Get the temporary directory of the transfer associated with the provided
 * transfer container. This directory is located in the user home directory
 * under ~/.lsdf/&lt;TID&gt;, where &lt;TID&gt; stands for the transfer ID of this
 * transfer. To avoid problems with invalid pathnames, the TID gets UTF-8
 * URL-encoded. Within the temporary directory the transfer can store status
 * information or checkpoint data to be able to resume failed transfers.
 *
 * @param pContainer The transfer container for which the temp dir should be
 * returned./*from   ww  w . j  a  va2  s . com*/
 *
 * @return The transfer's temporary directory
 *
 * @throws IOException If there was not set any TID for this transfer or if
 * there are problems getting the users home directory
 */
public static String getTempDir(TransferTaskContainer pContainer) throws IOException {
    if (pContainer != null) {
        LOGGER.debug("Determining transfer tmp directory.");
        File userHome = SystemUtils.getUserHome();
        if (!isAccessibleDirectory(userHome)) {
            //user home not usable (maybe no home directory available). Try system temp dir...
            userHome = SystemUtils.getJavaIoTmpDir();
            if (!isAccessibleDirectory(userHome)) {
                throw new IOException("Failed to obtain valid temp directory. UserHome ("
                        + SystemUtils.getUserHome() + ") and TmpDir (" + userHome + ") are not usable.");
            } else {
                LOGGER.debug("Using tmp directory.");
            }
        } else {
            LOGGER.debug("Using user home directory.");
        }

        return FilenameUtils.concat(FilenameUtils.concat(userHome.getCanonicalPath(), ".lsdf"),
                URLEncoder.encode(pContainer.getUniqueTransferIdentifier(), "UTF-8"));
    } else {
        throw new IOException(
                "Failed to obtain temporary transfer directory. Transfer container must not be 'null'");
    }
}

From source file:net.erdfelt.android.sdkfido.configer.ConfigCmdLineParserTest.java

@Test
public void testSetDeepOption() throws CmdLineParseException {
    FetcherConfig config = new FetcherConfig();

    File expectedDir = new File(SystemUtils.getUserHome(), FilenameUtils.separatorsToSystem(".sdkfido/work"));

    Assert.assertThat("Config.dryRun", config.isDryRun(), is(false));
    Assert.assertThat("Config.workDir", config.getWorkDir(), is(expectedDir));
    Assert.assertThat("Config.maven.groupId", config.getMaven().getGroupId(), is("com.android.sdk"));

    File otherWork = testingdir.getFile("work");

    StringWriter capture = new StringWriter();
    ConfigCmdLineParser parser = new ConfigCmdLineParser(this, config);
    parser.setOut(capture);//from  w w  w .j a  va2 s .  com
    String[] args = { "--dryRun", "true", "--workDir", otherWork.getAbsolutePath(), "--maven.groupId",
            "com.android.sdk.testee" };
    parser.parse(args);

    Assert.assertThat("Config.dryRun", config.isDryRun(), is(true));
    Assert.assertThat("Config.workDir", config.getWorkDir(), is(otherWork));
    Assert.assertThat("Config.maven.groupId", config.getMaven().getGroupId(), is("com.android.sdk.testee"));
}

From source file:com.joshlong.esb.springintegration.modules.nativefs.NativeFileSystemMonitor.java

public void psvm() throws Throwable {

    File desktop = new File(new File(SystemUtils.getUserHome(), "Desktop"), "test");
    NativeFileSystemMonitor nativeFileSystemMonitor = new NativeFileSystemMonitor(desktop);
    nativeFileSystemMonitor.setAutoCreateDirectory(true);
    nativeFileSystemMonitor.setMaxQueueValue(1000);
    nativeFileSystemMonitor.init();/* w ww .j av  a2  s .  c o  m*/
    nativeFileSystemMonitor.monitor(new FileAddedListener() {
        public void fileAdded(File dir, String fn) {
            System.out.println("Added" + fn);
        }
    });
}