Example usage for org.apache.commons.io FileUtils touch

List of usage examples for org.apache.commons.io FileUtils touch

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils touch.

Prototype

public static void touch(File file) throws IOException 

Source Link

Document

Implements the same behaviour as the "touch" utility on Unix.

Usage

From source file:org.wso2.carbon.identity.user.store.configuration.deployer.internal.UserStoreConfigComponent.java

/**
 * This method invoked when the bundle get activated, it touches the super-tenants user store
 * configuration with latest time stamp. This invokes undeploy and deploy method
 *//*from  www . j  a  v  a  2s . com*/
private void triggerDeployerForSuperTenantSecondaryUserStores() {

    String repositoryPath = CarbonUtils.getCarbonRepository();
    int repoLength = repositoryPath.length();

    /**
     * This operation is done to make sure if the getCarbonRepository method doesn't return a
     * file path with File.Separator at the end, this will add it
     * If repositoryPath is ,<CARBON_HOME>/repository/deployment this method will add
     * File.separator at the end. If not this will exit
     */
    String fSeperator = repositoryPath.substring(repoLength - 1, repoLength);
    if (!fSeperator.equals(File.separator)) {
        repositoryPath += File.separator;
    }
    String superTenantUserStorePath = repositoryPath + "userstores" + File.separator;

    File folder = new File(superTenantUserStorePath);
    File[] listOfFiles = folder.listFiles();

    if (listOfFiles != null) {
        for (File file : listOfFiles) {
            if (file != null) {
                String ext = FilenameUtils.getExtension(file.getAbsolutePath());
                if (isValidExtension(ext)) {
                    try {
                        FileUtils.touch(new File(file.getAbsolutePath()));
                    } catch (IOException e) {
                        String errMsg = "Error occurred while trying to touch " + file.getName()
                                + ". Passwords will continue to remain in plaintext";
                        log.error(errMsg, e);
                        // continuing here since user stores are still functional
                        // except the passwords are in plain text
                    }
                }
            }
        }
    }
}

From source file:org.wso2.carbon.integration.common.extensions.axis2server.Axis2ServerManager.java

private File copyResourceToFileSystem(String resourceName, String fileName) throws IOException {
    File file = new File(System.getProperty("basedir") + File.separator + "target" + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);/*from www .ja  va2s.  com*/
    }

    OutputStream os = null;
    InputStream is = null;

    try {
        FileUtils.touch(file);
        os = FileUtils.openOutputStream(file);

        if (resourceName.contains(".aar")) {
            is = new FileInputStream(FrameworkPathUtil.getSystemResourceLocation() + File.separator
                    + "artifacts" + File.separator + "AXIS2" + File.separator + "aar" + File.separator
                    + resourceName);
        } else {
            is = new FileInputStream(FrameworkPathUtil.getSystemResourceLocation() + File.separator
                    + "artifacts" + File.separator + "AXIS2" + File.separator + "config" + File.separator
                    + resourceName);
        }
        if (is != null) {
            byte[] data = new byte[1024];
            int len;
            while ((len = is.read(data)) != -1) {
                os.write(data, 0, len);
            }
        }

    } finally {
        if (os != null) {
            try {
                os.flush();
                os.close();
            } catch (IOException e) {
                log.warn("Unable to close the stream");
            }
        }
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                log.warn("Unable to close the stream");
            }
        }
    }
    return file;
}

From source file:org.wso2.carbon.integration.common.extensions.axis2server.Axis2ServerManager.java

private File copyServiceToFileSystem(String resourceName, String fileName) throws IOException {
    File file = new File(System.getProperty("basedir") + File.separator + "target" + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);/*  w w w .  j a v  a 2  s .  c o  m*/
    }
    OutputStream os = null;
    InputStream is = null;
    try {
        FileUtils.touch(file);
        os = FileUtils.openOutputStream(file);
        is = new FileInputStream(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts"
                + File.separator + "AXIS2" + File.separator + "config" + File.separator + resourceName);
        if (is != null) {
            byte[] data = new byte[1024];
            int len;
            while ((len = is.read(data)) != -1) {
                os.write(data, 0, len);
            }
        }
    } finally {
        if (os != null) {
            try {
                os.flush();
                os.close();
            } catch (IOException e) {
                log.warn("Unable to close the stream");
            }
        }
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                log.warn("Unable to close the stream");
            }
        }
    }
    return file;
}

From source file:org.wso2.carbon.integration.common.utils.FileManager.java

public static File copyResourceToFileSystem(String sourcePath, String targetPath, String fileName)
        throws IOException {
    File file = new File(targetPath + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);//  www.j  a v a2  s  .c  o m
    }
    OutputStream os = null;
    InputStream is = null;

    try {
        FileUtils.touch(file);
        os = FileUtils.openOutputStream(file);
        is = new FileInputStream(sourcePath);

        if (is != null) {
            byte[] data = new byte[1024];
            int len;
            while ((len = is.read(data)) != -1) {
                os.write(data, 0, len);
            }
        }
    } finally {
        if (os != null) {
            try {
                os.flush();
                os.close();
            } catch (IOException e) {
                log.warn("Unable to close steam");
            }
        }
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                log.warn("Unable to close steam");
            }
        }
    }
    return file;
}

From source file:org.wso2.esb.integration.common.extensions.axis2server.Axis2ServerManager.java

private File copyResourceToFileSystem(String resourceName, String fileName) throws IOException {
    File file = new File(System.getProperty("basedir") + File.separator + "target" + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);//  ww w. j  av a2 s.c  om
    }
    FileUtils.touch(file);
    OutputStream os = FileUtils.openOutputStream(file);
    InputStream is;
    if (resourceName.contains(".aar")) {
        is = new FileInputStream(ExtensionUtils.getSystemResourceLocation() + File.separator + "artifacts"
                + File.separator + "AXIS2" + File.separator + "aar" + File.separator + resourceName);
    } else {
        is = new FileInputStream(ExtensionUtils.getSystemResourceLocation() + File.separator + "artifacts"
                + File.separator + "AXIS2" + File.separator + "config" + File.separator + resourceName);
    }
    if (is != null) {
        byte[] data = new byte[1024];
        int len;
        while ((len = is.read(data)) != -1) {
            os.write(data, 0, len);
        }
    }
    os.flush();
    os.close();
    is.close();
    return file;
}

From source file:org.wso2.esb.integration.common.extensions.axis2server.Axis2ServerManager.java

private File copyServiceToFileSystem(String resourceName, String fileName) throws IOException {
    File file = new File(System.getProperty("basedir") + File.separator + "target" + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);//from   ww w.j a  v a2s  .c  om
    }
    FileUtils.touch(file);
    OutputStream os = FileUtils.openOutputStream(file);
    InputStream is = new FileInputStream(
            ExtensionUtils.getSystemResourceLocation() + File.separator + "artifacts" + File.separator + "AXIS2"
                    + File.separator + "config" + File.separator + resourceName);
    if (is != null) {
        byte[] data = new byte[1024];
        int len;
        while ((len = is.read(data)) != -1) {
            os.write(data, 0, len);
        }
        os.flush();
        os.close();
        is.close();
    }
    return file;
}

From source file:org.wso2.esb.integration.common.utils.common.FileManager.java

public static File copyResourceToFileSystem(String sourcePath, String targetPath, String fileName)
        throws IOException {

    File file = new File(targetPath + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);/*from   www  .  j  a va2  s  . c  o  m*/
    }

    FileUtils.touch(file);
    OutputStream os = FileUtils.openOutputStream(file);

    InputStream is = new FileInputStream(sourcePath);

    if (is != null) {
        byte[] data = new byte[1024];
        int len;
        while ((len = is.read(data)) != -1) {
            os.write(data, 0, len);
        }
        os.flush();
        os.close();
        is.close();
    }
    return file;
}

From source file:org.wso2.esb.integration.common.utils.servers.axis2.SampleAxis2Server.java

private File copyResourceToFileSystem(String resourceName, String fileName) throws IOException {
    File file = new File(System.getProperty("basedir") + File.separator + "target" + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);/*from   w  w  w .j  a v  a  2 s  .c  o  m*/
    }

    FileUtils.touch(file);
    OutputStream os = FileUtils.openOutputStream(file);
    InputStream is;
    if (resourceName.contains(".aar")) {
        is = new FileInputStream(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts"
                + File.separator + "AXIS2" + File.separator + "aar" + File.separator + resourceName);
    } else {
        is = new FileInputStream(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts"
                + File.separator + "AXIS2" + File.separator + "config" + File.separator + resourceName);
    }

    if (is != null) {
        byte[] data = new byte[1024];
        int len;
        while ((len = is.read(data)) != -1) {
            os.write(data, 0, len);
        }
        os.flush();
        os.close();
        is.close();
    }
    return file;
}

From source file:org.wso2.esb.integration.common.utils.servers.axis2.SampleAxis2Server.java

private File copyServiceToFileSystem(String resourceName, String fileName) throws IOException {
    File file = new File(System.getProperty("basedir") + File.separator + "target" + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);/*w  ww . ja v a 2  s.  com*/
    }

    FileUtils.touch(file);
    OutputStream os = FileUtils.openOutputStream(file);

    InputStream is = new FileInputStream(
            FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts" + File.separator
                    + "AXIS2" + File.separator + "config" + File.separator + resourceName);
    if (is != null) {
        byte[] data = new byte[1024];
        int len;
        while ((len = is.read(data)) != -1) {
            os.write(data, 0, len);
        }
        os.flush();
        os.close();
        is.close();
    }
    return file;
}

From source file:playRepository.GitRepositoryTest.java

@Test
public void getMetaDataFromPath() throws Exception {
    // Given/*from ww w  .  j  a v a  2s .  com*/
    final String userName = "yobi";
    final String projectName = "mytest";
    final String branchName = "branch";
    final String lightWeightTagName = "tag1";
    final String annotatedTagName = "tag2";
    String wcPath = GitRepository.getRepoPrefix() + userName + "/" + projectName;

    Repository repository = GitRepository.buildGitRepository(userName, projectName + "/");
    repository.create();
    Git git = new Git(repository);
    FileUtils.touch(new File(wcPath + "/hello"));
    FileUtils.touch(new File(wcPath + "/dir/world"));
    git.add().addFilepattern("hello").call();
    git.add().addFilepattern("dir").call();
    git.commit().setAuthor("yobi", "yobi@yobi.io").setMessage("test").call();
    git.branchCreate().setName(branchName).call();
    git.tag().setName(lightWeightTagName).setAnnotated(false).call();
    git.tag().setName(annotatedTagName).setAnnotated(true).setMessage("annotated tag").call();
    repository.close();

    running(support.Helpers.makeTestApplication(), new Runnable() {
        @Override
        public void run() {
            try {
                // When
                GitRepository gitRepository = new GitRepository(userName, projectName + "/");
                ObjectNode notExistBranch = gitRepository.getMetaDataFromPath("not_exist_branch", "");
                ObjectNode root = gitRepository.getMetaDataFromPath("");
                ObjectNode dir = gitRepository.getMetaDataFromPath("dir");
                ObjectNode file = gitRepository.getMetaDataFromPath("hello");
                ObjectNode branch = gitRepository.getMetaDataFromPath(branchName, "");
                ObjectNode lightWeightTag = gitRepository.getMetaDataFromPath(lightWeightTagName, "");
                ObjectNode annotatedTag = gitRepository.getMetaDataFromPath(annotatedTagName, "");

                // Then
                assertThat(notExistBranch).isNull();
                assertThat(root.get("type").getTextValue()).isEqualTo("folder");
                assertThat(root.get("data").get("hello").get("type").getTextValue()).isEqualTo("file");
                assertThat(root.get("data").get("dir").get("type").getTextValue()).isEqualTo("folder");
                assertThat(dir.get("type").getTextValue()).isEqualTo("folder");
                assertThat(dir.get("data").get("world").get("type").getTextValue()).isEqualTo("file");
                assertThat(file.get("type").getTextValue()).isEqualTo("file");
                assertThat(branch.toString()).isEqualTo(root.toString());
                assertThat(lightWeightTag.toString()).isEqualTo(root.toString());
                assertThat(annotatedTag.toString()).isEqualTo(root.toString());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    });
}