List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:isl.FIMS.servlet.export.ExportSchema.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j a v a 2 s . c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.initVars(request); String username = getUsername(request); boolean isGuest = this.getRights(username).equals("guest"); if (!isGuest) { try { String filePath = this.export_import_Folder; java.util.Date date = new java.util.Date(); Timestamp t = new Timestamp(date.getTime()); String currentDir = filePath + t.toString().replaceAll(":", "").replaceAll("\\s", ""); File saveDir = new File(currentDir); saveDir.mkdir(); Config conf = new Config("ExportSchema"); String type = request.getParameter("type"); request.setCharacterEncoding("UTF-8"); ServletOutputStream outStream = response.getOutputStream(); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=\"" + "Schema_" + type + ".zip\""); File schemaFile = new File(this.schemaFolder + type + ".xsd"); FileUtils.copyFile(schemaFile, new File(currentDir + System.getProperty("file.separator") + type + ".xsd")); Utils.copySchemaReferences(this.schemaFolder + type + ".xsd", currentDir); File f = new File(currentDir + System.getProperty("file.separator") + "zip"); f.mkdir(); String zip = f.getAbsolutePath() + System.getProperty("file.separator") + "Schema_" + type + ".zip"; Utils.createZip(zip, currentDir); Utils.downloadZip(outStream, new File(zip)); Utils.deleteDir(currentDir); } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:com.chingo247.structureapi.util.ConfigUpdater.java
public void checkAndUpdate() throws Exception { if (currentConfigFile.exists()) { String newConfigVersion = ConfigProvider.getVersion(configFileToCheck); String currentConfigVersion = null; boolean needsUpdating = false; try {/*w w w .j a va2 s. com*/ currentConfigVersion = ConfigProvider.getVersion(currentConfigFile); } catch (Exception ex) { YAMLProcessor processor = new YAMLProcessor(currentConfigFile, false); if (processor.getProperty("version") != null) { throw new Exception( "An error occurred while loading the config file, if the config file is missing expected values, try removing the file. When the file is removed, a new (default) config will be generated"); } else { needsUpdating = true; } } if (needsUpdating || (currentConfigVersion == null || (VersionUtil.compare(currentConfigVersion, newConfigVersion) == -1))) { int count = 1; String baseName = FilenameUtils.getBaseName(currentConfigFile.getName()); File oldFile = new File(currentConfigFile.getParent(), baseName + "(" + count + ").old.yml"); while (oldFile.exists()) { count++; oldFile = new File(currentConfigFile.getParent(), baseName + "(" + count + ").old.yml"); } String reason; if (needsUpdating || (currentConfigVersion == null)) { reason = "No 'version' value found in config"; } else { reason = "Older 'version' value found in config.yml"; } onUpdate(reason); FileUtils.copyFile(currentConfigFile, oldFile); FileUtils.copyFile(configFileToCheck, currentConfigFile); } } else { FileUtils.copyFile(configFileToCheck, currentConfigFile); } }
From source file:codegen.CodeGeneratorTest.java
private void copy(String source, String dest) throws IOException { File fileToCopy = new File(source).getAbsoluteFile(); assertTrue("File " + fileToCopy.toString() + " doesn't exist", fileToCopy.exists()); File destination = new File(dest).getAbsoluteFile(); destination.getParentFile().mkdirs(); FileUtils.copyFile(fileToCopy, destination); }
From source file:com.gitblit.tests.LdapAuthenticationTest.java
@Before public void init() throws Exception { ds.clear();//from w ww .j a v a2 s.c o m ds.importFromLDIF(true, new LDIFReader(new FileInputStream(RESOURCE_DIR + "sampledata.ldif"))); usersConf = folder.newFile("users.conf"); FileUtils.copyFile(new File(RESOURCE_DIR + "users.conf"), usersConf); settings = getSettings(); ldap = newLdapAuthentication(settings); auth = newAuthenticationManager(settings); }
From source file:dk.deck.resolver.ArtifactResolverLocal.java
private void copyArtifact(File workdir, Artifact artifact) throws IOException { String path = localRepository + "/" + getArtifactItemPath(artifact); File localFile = new File(path); if (!localFile.exists()) { throw new IllegalStateException("File " + path + " does not exists "); }// w ww.j av a2 s . co m File output = new File(workdir.getAbsolutePath() + "/" + artifact.getFileName()); FileUtils.copyFile(localFile, output); }
From source file:com.necl.service.HandlerFileUpload.java
public void handleFileToCopy(String source, String target, String fileName) throws Exception { // source = "D:/file/New.xlsx"; // target ="D:/file/test/"; //name of source file File sourceFile = new File(source); //String name = sourceFile.getName(); File targetFile = new File(target + fileName); //System.out.println("Copying file : " + sourceFile.getName() +" from Java Program"); //copy file from one location to other FileUtils.copyFile(sourceFile, targetFile); System.out.println("Copy " + sourceFile + " to " + targetFile); System.out.println("copying of file from Java program is completed"); }
From source file:eu.qualimaster.dataManagement.storage.hdfs.HdfsUtils.java
/** * Stores the data file to the DFS (alternative). * //from w ww . j a v a 2s .c om * @return the target path if successful, <b>null</b> else * @throws IOException in case that I/O fails */ public static String storeToDfs(File dataFile) throws IOException { String dataPath = null; if (!DataManagementConfiguration.isEmpty(DataManagementConfiguration.getDfsPath())) { File targetPath = new File(DataManagementConfiguration.getDfsPath(), dataFile.getName()); FileUtils.copyFile(dataFile, targetPath); dataPath = targetPath.getAbsolutePath().toString(); } return dataPath; }
From source file:com.indoqa.osgi.embedded.test.integration.OSGiEmbeddedIntegrationTest.java
@Test public void installAndUninstallBundle() throws IOException { DateService[] dateServices = this.dateServiceProvider.getDateServices(); assertEquals(0, dateServices.length); File bundle = new File(DIR_BUNDLES + FILE_NAME_SAMPLE_BUNDLE); FileUtils.copyFile(new File(DIR_SAMPLE_BUNDLE + FILE_NAME_SAMPLE_BUNDLE), bundle); this.sleep(1000); dateServices = this.dateServiceProvider.getDateServices(); assertEquals(1, dateServices.length); bundle.delete();/*from www .j a va 2 s . c o m*/ this.sleep(1000); dateServices = this.dateServiceProvider.getDateServices(); assertEquals(0, dateServices.length); }
From source file:com.mmj.app.biz.service.impl.FileServiceImpl.java
@Override public Result saveFileByName(String fileName, IFileHandle... ihandle) { if (StringUtils.isEmpty(fileName)) { return Result.failed(); }// w w w . ja va2 s . co m File file = new File(UPLOAD_TMP_PATH + fileName); if (file == null || file.isFile()) { try { String path = ihandle[0].parse(UPLOAD_BASE_PATH, fileName); FileUtils.copyFile(file, new File(path)); return Result.success(null, STATIC_BASE_IMG + fileName); } catch (Exception e) { logger.error(e.getMessage()); return Result.failed(); } } return Result.failed(); }
From source file:ch.admin.suis.msghandler.common.CompleteMultiReceiver1Test.java
@Override void initialize() throws IOException { List<File> files = getAllFilesFromDir(new File(BASE_PATH_SETUP + "/case1")); for (File f : files) { FileUtils.copyFile(f, new File(BASE_PATH_MH + "/transApp2/outbox", f.getName())); }/*from www.j av a2s . c o m*/ }