当前位置: 首页>>代码示例>>Java>>正文


Java FileUtils.copyDirectoryToDirectory方法代码示例

本文整理汇总了Java中org.apache.commons.io.FileUtils.copyDirectoryToDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java FileUtils.copyDirectoryToDirectory方法的具体用法?Java FileUtils.copyDirectoryToDirectory怎么用?Java FileUtils.copyDirectoryToDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.io.FileUtils的用法示例。


在下文中一共展示了FileUtils.copyDirectoryToDirectory方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: moveDirectory

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void moveDirectory(String source, String destination) {
    File sourceFile = new File(source);
    File destFile = new File(destination);
    try {
        if (sourceFile.exists()) {
            FileUtils.copyDirectoryToDirectory(sourceFile, destFile.getParentFile());
            FileUtils.deleteDirectory(sourceFile);
        }
    } catch (IOException ex) {
        Logger.getLogger(FileOptions.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:13,代码来源:FileOptions.java

示例2: should_list_existing_repo_from_git_workspace

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void should_list_existing_repo_from_git_workspace() throws Throwable {
    // given: copy exit git to workspace
    ClassLoader classLoader = TestBase.class.getClassLoader();
    URL resource = classLoader.getResource("hello.git");
    File path = new File(resource.getFile());
    FileUtils.copyDirectoryToDirectory(path, gitWorkspace.toFile());

    // when: load repos from git workspace
    List<Repository> repos = gitService.repos();
    Assert.assertEquals(1, repos.size());

    // then:
    Repository helloRepo = repos.get(0);
    Map<String, Ref> tags = helloRepo.getTags();
    Assert.assertEquals(1, tags.size());
    Assert.assertTrue(tags.keySet().contains("v1.0"));
    Assert.assertEquals("hello.git", helloRepo.getDirectory().getName());

    for (Repository repo : repos) {
        repo.close();
    }
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:24,代码来源:GitServiceTest.java

示例3: should_remove_sync_task_if_create_session_failure

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void should_remove_sync_task_if_create_session_failure() throws Throwable {
    // given: remove stub url
    wireMockRule.resetAll();

    // and copy exist git to workspace
    ClassLoader classLoader = TestBase.class.getClassLoader();
    URL resource = classLoader.getResource("hello.git");
    File path = new File(resource.getFile());
    FileUtils.copyDirectoryToDirectory(path, gitWorkspace.toFile());

    // and: register agent to sync service
    AgentPath agent = agents.get(0);
    syncService.register(agent);

    // when: execute sync task
    syncService.syncTask();

    // then: sync task for agent should be removed
    Assert.assertNull(syncService.getSyncTask(agent));
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:22,代码来源:SyncServiceTest.java

示例4: writeResume

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public File writeResume(String json, String theme) throws Exception {
        if (json == null) {
            json = readJSONFromFile();
        }
        String html = generateResumeHTML(json, theme);
        File location = runtime.getOutputHtmlFile();
        if (!location.exists()) {
            location.getParentFile().mkdirs();
        }
        ;
        FileWriter writer = new FileWriter(location, false);
        writer.write(html);
        writer.close();
        //System.out.println(html);

        System.out.println("Success! You can find your resume at " + runtime.getOutputHtmlFile().getAbsolutePath());
//        createPDF(runtime.getOutputHtmlFile().getAbsolutePath());
        if (!newResourceFolder.getAbsolutePath().toString().equals(Paths.get(runtime.getOutputDirectory().getAbsolutePath().toString(), "resources").toString())) {
            FileUtils.copyDirectoryToDirectory(newResourceFolder, runtime.getOutputDirectory());
        }

        File outputFile;
        if (runtime.getWebRequestType() == WEBREQUEST_TYPE.PDF) {
            createPDF(runtime.getOutputHtmlFile().getAbsolutePath(), runtime);
            outputFile = runtime.getOutputHtmlFile("output.pdf");
        } else {
            createInlineHTML(runtime);
            outputFile = runtime.getOutputHtmlFile("resume_inline.html");
        }
        System.out.println("Output File: " + outputFile.getAbsolutePath());
        return outputFile;
    }
 
开发者ID:chenshuiluke,项目名称:jresume,代码行数:33,代码来源:ResumeGenerator.java

示例5: copyFolder

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * 复制目录
 * @author Rocye
 * @param srcPath 	复制的源文件夹路径
 * @param destPath 	复制的目标文件夹路径
 * @param isCopyRoot 是否复制根目录 true为复制根目录 false为不复制根目录,只复制根目录下的所有文件以及文件夹
 * @return true OR false
 * @version 2017-02-28
 */
public static boolean copyFolder(String srcPath, String destPath, boolean isCopyRoot) {
	try {
		if(isCopyRoot){
			FileUtils.copyDirectoryToDirectory(new File(srcPath), new File(destPath));
		}else{
			FileUtils.copyDirectory(new File(srcPath), new File(destPath));
		}
		return true;
	} catch (IOException e) {
		e.printStackTrace();
		logger.error("调用ApacheCommon复制文件夹时:" + e.toString());
		return false;
	}
}
 
开发者ID:rocye,项目名称:wx-idk,代码行数:24,代码来源:FileIo.java

示例6: should_init_sync_event_when_agent_registered

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void should_init_sync_event_when_agent_registered() throws Throwable {
    // given: copy exist git to workspace
    ClassLoader classLoader = TestBase.class.getClassLoader();
    URL resource = classLoader.getResource("hello.git");
    File path = new File(resource.getFile());
    FileUtils.copyDirectoryToDirectory(path, gitWorkspace.toFile());

    // when: register agent to sync service
    syncService.load();
    syncService.register(agents.get(0));
    syncService.register(agents.get(1));

    // then: verify the sync event been initialized into both agents

    // check sync queue for first agent
    Sync sync = syncService.get(agents.get(0));
    Assert.assertEquals(1, sync.queueSize());

    SyncEvent createEvent = sync.dequeue();
    Assert.assertEquals("http://localhost:8080/git/hello.git", createEvent.getGitUrl());
    Assert.assertEquals("v1.0", createEvent.getRepo().getTag());
    Assert.assertEquals(SyncType.CREATE, createEvent.getSyncType());

    // check sync queue for second agent
    sync = syncService.get(agents.get(1));
    Assert.assertEquals(1, sync.queueSize());

    createEvent = sync.dequeue();
    Assert.assertEquals("http://localhost:8080/git/hello.git", createEvent.getGitUrl());
    Assert.assertEquals("v1.0", createEvent.getRepo().getTag());
    Assert.assertEquals(SyncType.CREATE, createEvent.getSyncType());
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:34,代码来源:SyncServiceTest.java

示例7: should_remove_sync_task_if_create_session_failure_on_callback

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void should_remove_sync_task_if_create_session_failure_on_callback() throws Throwable {
    // given: copy exist git to workspace
    ClassLoader classLoader = TestBase.class.getClassLoader();
    URL resource = classLoader.getResource("hello.git");
    File path = new File(resource.getFile());
    FileUtils.copyDirectoryToDirectory(path, gitWorkspace.toFile());

    // and: register agent to sync service
    AgentPath agent = agents.get(0);
    syncService.register(agent);

    // when: execute sync task
    syncService.syncTask();

    // then: the create session cmd should be send
    CountMatchingStrategy strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 1);
    verify(strategy, postRequestedFor(urlEqualTo("/cmd/queue/send?priority=10&retry=5")));

    // when: mock create session failure
    Cmd mockSessionCallback = new Cmd(agent.getZone(), agent.getName(), CmdType.CREATE_SESSION, null);
    mockSessionCallback.setStatus(CmdStatus.EXCEPTION);
    mockSessionCallback.setSessionId(createSessionCmdResponse.getSessionId());
    syncService.onCallback(mockSessionCallback);

    // then: sync task for agent should be removed
    Assert.assertNull(syncService.getSyncTask(agent));
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:29,代码来源:SyncServiceTest.java

示例8: copyDirectory

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
public static void copyDirectory(String source, String destination) {
    File sourceFile = new File(source);
    File destFile = new File(destination);
    try {
        if (sourceFile.exists()) {
            FileUtils.copyDirectoryToDirectory(sourceFile, destFile);
        }
    } catch (IOException ex) {
        Logger.getLogger(FileOptions.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:12,代码来源:FileOptions.java

示例9: writeZip

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
/**
 * Write the files and directories.
 *
 * @param files List of strings representing the files and dirs to bundle into the zip.
 * @param output Zip filename as a string.
 */
public static void writeZip(List<String> files, String output, String target) throws IOException {
  // Clear the zipFiles folder.
  final File targetDir = new File(target);
  FileUtils.deleteQuietly(targetDir);

  // Create the subdirectories if our target is under a nested dir.
  final File dest = Paths.get(output).toFile();
  if (dest.getParentFile() != null) {
    dest.getParentFile().mkdirs();
  }

  try (
      final FileOutputStream fos = new FileOutputStream(dest);
      final ZipOutputStream zos = new ZipOutputStream(fos)
  ) {

    // Copy all files to the target directory.
    for (String f : files) {
      final Path path = Paths.get(f);
      final File src = path.toFile();
      final File destDir = new File(target);
      if (Files.isDirectory(path)) {
        FileUtils.copyDirectoryToDirectory(src,destDir);
      } else {
        FileUtils.copyFileToDirectory(src,destDir);
      }
    }

    // Zip all files recursively.
    Files.walk(Paths.get(target))
        .filter(path -> !Files.isDirectory(path))
        .forEach(path -> {
          try {
            putEntry(zos, path, target);
          } catch (IOException e) {
            throw new UncheckedIOException(e);
          }
        });

    // Clear the zipFiles folder.
    FileUtils.deleteQuietly(targetDir);

  }
  return;
}
 
开发者ID:tsiq,项目名称:magic-beanstalk,代码行数:52,代码来源:ZipUtil.java

示例10: should_execute_sync_event_callback

import org.apache.commons.io.FileUtils; //导入方法依赖的package包/类
@Test
public void should_execute_sync_event_callback() throws Throwable {
    // given: copy exist git to workspace
    ClassLoader classLoader = TestBase.class.getClassLoader();
    URL resource = classLoader.getResource("hello.git");
    File path = new File(resource.getFile());
    FileUtils.copyDirectoryToDirectory(path, gitWorkspace.toFile());

    // and: register agent to sync service
    AgentPath agent = agents.get(0);
    syncService.load();
    syncService.register(agent);
    Assert.assertEquals(1, syncService.get(agent).queueSize());

    // when: execute sync task
    syncService.syncTask();

    // then: the create session cmd should be send
    CountMatchingStrategy strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 1);
    verify(strategy, postRequestedFor(urlEqualTo("/cmd/queue/send?priority=10&retry=5")));

    // when: mock create session cmd been callback
    Cmd mockSessionCallback = new Cmd(agent.getZone(), agent.getName(), CmdType.CREATE_SESSION, null);
    mockSessionCallback.setStatus(CmdStatus.SENT);
    mockSessionCallback.setSessionId(createSessionCmdResponse.getSessionId());
    syncService.onCallback(mockSessionCallback);

    // then: send run shell cmd for sync event and sync task queue size not changed
    strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 1);
    verify(strategy, postRequestedFor(urlEqualTo("/cmd/send")));
    Assert.assertEquals(2, syncService.getSyncTask(agent).getSyncQueue().size());

    // when: mock cmd been executed
    Cmd mockRunShellSuccess = new Cmd(agent.getZone(), agent.getName(), CmdType.RUN_SHELL, "git pull xxx");
    mockRunShellSuccess.setSessionId(mockSessionCallback.getSessionId());
    mockRunShellSuccess.setStatus(CmdStatus.LOGGED);
    mockRunShellSuccess.setCmdResult(new CmdResult(0));
    syncService.onCallback(mockRunShellSuccess);

    // then: should send list repos cmd and sync task queue size should be 1
    strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 2);
    verify(strategy, postRequestedFor(urlEqualTo("/cmd/send")));
    Assert.assertEquals(1, syncService.getSyncTask(agent).getSyncQueue().size());

    // when: mock list cmd been executed
    Cmd mockListRepoSuccess =
        new Cmd(agent.getZone(), agent.getName(), CmdType.RUN_SHELL, "export FLOW_SYNC_LIST=$(ls)");
    mockListRepoSuccess.setSessionId(mockSessionCallback.getSessionId());
    mockListRepoSuccess.setStatus(CmdStatus.LOGGED);
    mockListRepoSuccess.setCmdResult(new CmdResult(0));
    mockListRepoSuccess.getCmdResult().getOutput().put(SyncEvent.FLOW_SYNC_LIST, "A[v1]\nB[v2]");
    syncService.onCallback(mockListRepoSuccess);

    // then: agent repo list size should be 2
    Assert.assertEquals(2, syncService.get(agent).getRepos().size());
    Assert.assertTrue(syncService.get(agent).getRepos().contains(new SyncRepo("A", "v1")));
    Assert.assertTrue(syncService.get(agent).getRepos().contains(new SyncRepo("B", "v2")));

    // then: should send delete session cmd and sync task queue size should be zero
    strategy = new CountMatchingStrategy(CountMatchingStrategy.EQUAL_TO, 3);
    verify(strategy, postRequestedFor(urlEqualTo("/cmd/send")));
    Assert.assertEquals(0, syncService.getSyncTask(agent).getSyncQueue().size());

    // when: mock delete session cmd
    Cmd mockDeleteSession = new Cmd(agent.getZone(), agent.getName(), CmdType.DELETE_SESSION, null);
    mockDeleteSession.setSessionId(mockRunShellSuccess.getSessionId());
    mockDeleteSession.setStatus(CmdStatus.SENT);
    syncService.onCallback(mockDeleteSession);

    // then: sync task of agent should be deleted
    Assert.assertNull(syncService.getSyncTask(agent));
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:73,代码来源:SyncServiceTest.java


注:本文中的org.apache.commons.io.FileUtils.copyDirectoryToDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。