List of usage examples for java.io File renameTo
public boolean renameTo(File dest)
From source file:gallery.service.sitemap.SitemapServiceImpl.java
@Override @Transactional(readOnly = true)/* w w w. j a v a 2s .co m*/ public void createSitemap() { if (generating) { logger.info("xml is allready generating ..."); return; } try { logger.info("start generate xml"); generating = true; long time = System.currentTimeMillis(); File base = new File(path_tmp); try { if (base.exists()) { Index index = new Index(10000, base, gallery.web.Config.SITE_NAME); Sitemap sitemap = index.getChild(); List<Pages> pages = pages_service.getByPropertiesValueOrdered(SITEMAP_NAMES, SITEMAP_WHERE, new Object[] { null, Boolean.TRUE }, null, null); LinkedList<Long> pages_unhandled = new LinkedList<Long>(); int k = 0; while (k < pages.size()) { Pages p = pages.get(k); if (!p.getLast()) { pages_unhandled.add(p.getId()); sitemap.addRecord("index.htm?id_pages_nav=" + p.getId(), "daily", "0.8"); } else { //check type if (p.getType().equals(gallery.web.controller.pages.types.WallpaperGalleryType.TYPE)) { Long id_pages = p.getId(); List ids = wallpaper_service.getSingleProperty("id", SITEMAP_WHERE, new Object[] { id_pages, Boolean.TRUE }, 0, 0, null, null); int j = 0; for (int i = 0; i < ids.size(); i = i + gallery.web.controller.pages.types.WallpaperGalleryType.CATEGORY_WALLPAPERS) { sitemap.addRecord( "index.htm?id_pages_nav=" + id_pages + "&page_number=" + j, "daily", "0.9"); j++; } for (Object id_wallpaper : ids) { sitemap.addRecord("index.htm?id_pages_nav=" + id_pages + "&id_photo_nav=" + id_wallpaper, "daily", "0.7"); } } else { sitemap.addRecord("index.htm?id_pages_nav=" + p.getId(), "daily", "0.9"); } } k++; if ((k >= pages.size()) && (!pages_unhandled.isEmpty())) { pages = pages_service.getByPropertiesValueOrdered(SITEMAP_NAMES, SITEMAP_WHERE, new Object[] { pages_unhandled.removeFirst(), Boolean.TRUE }, null, null); k = 0; } } sitemap.close(); //moving to web content clearSitemap(); File f = new File(path_tmp); File[] files = f.listFiles(); for (File file : files) { String name = file.getName(); if ((name.startsWith(core.sitemap.model.Config.SITEMAP_PREFIX) || name.startsWith(core.sitemap.model.Config.INDEX_PREFIX)) && name.endsWith(core.sitemap.model.Config.XML_SUFFIX)) { File new_file = new File(path, file.getName()); file.renameTo(new_file); } } } } catch (IOException ex) { logger.error("error while generating sitemap", ex); } time = System.currentTimeMillis() - time; logger.info("end generate xml. generated in: " + time); } finally { generating = false; } }
From source file:fr.ippon.wip.portlet.WIPConfigurationPortlet.java
/** * Process the user action: a configuration can be deleted, selected or * saved.// w w w . j a v a 2 s .com */ @Override public void processAction(ActionRequest request, ActionResponse response) throws PortletException, IOException { PortletSession session = request.getPortletSession(); if (fileUploadPortlet.isMultipartContent(request)) { try { List<DiskFileItem> fileItems = fileUploadPortlet.parseRequest(request); for (DiskFileItem fileItem : fileItems) { // TODO : ??? String newName = FilenameUtils.concat(deployPath, fileItem.getName()); File file = fileItem.getStoreLocation(); file.renameTo(new File(newName)); } request.setAttribute(Attributes.PAGE.name(), Pages.EXISTING_CONFIG.name()); } catch (FileUploadException e) { e.printStackTrace(); } return; } String page = request.getParameter(Attributes.PAGE.name()); if (!StringUtils.isEmpty(page)) { session.setAttribute(Attributes.PAGE.name(), Pages.valueOf(page)); return; } String configName = request.getParameter(Attributes.ACTION_SELECT_CONFIGURATION.name()); if (!StringUtils.isEmpty(configName) && configurationDAO.exists(configName)) { session.setAttribute(Attributes.CONFIGURATION_NAME.name(), configName); session.setAttribute(Attributes.PAGE.name(), Pages.GENERAL_SETTINGS); return; } configName = request.getParameter(Attributes.ACTION_DELETE_CONFIGURATION.name()); if (!StringUtils.isEmpty(configName)) { if (WIPUtil.getConfiguration(request).getName().equals(configName)) session.setAttribute(Attributes.CONFIGURATION_NAME.name(), AbstractConfigurationDAO.DEFAULT_CONFIG_NAME); configurationDAO.delete(configurationDAO.read(configName)); return; } configName = request.getParameter(Attributes.ACTION_SAVE_CONFIGURATION_AS.name()); if (!StringUtils.isEmpty(configName)) { WIPConfiguration configuration = WIPUtil.getConfiguration(request); WIPConfiguration newConfiguration = (WIPConfiguration) configuration.clone(); newConfiguration.setName(configName); newConfiguration = configurationDAO.create(newConfiguration); session.setAttribute(Attributes.CONFIGURATION_NAME.name(), newConfiguration.getName()); session.setAttribute(Attributes.PAGE.name(), Pages.GENERAL_SETTINGS); return; } if (request.getParameter("form") != null) { switch (Integer.valueOf(request.getParameter("form"))) { case 1: handleGeneralSettings(request, response); break; case 2: handleClipping(request, response); break; case 3: handleHtmlRewriting(request, response); break; case 4: handleCSSRewriting(request, response); break; case 5: handleJSRewriting(request, response); break; case 6: handleCaching(request, response); break; case 7: handleLTPAAuthentication(request, response); break; } } }
From source file:com.trellmor.berrymotes.sync.SubredditEmoteDownloader.java
private boolean downloadEmote(EmoteImage emote) throws IOException, URISyntaxException, InterruptedException { checkInterrupted();//ww w . ja v a 2 s. c o m mEmoteDownloader.checkStorageAvailable(); File file = new File(mBaseDir, emote.getImage()); if (!file.exists()) { Log.debug("Downloading emote " + emote.getImage()); file.getParentFile().mkdirs(); mEmoteDownloader.checkCanDownload(); HttpGet request = new HttpGet(); request.setURI(new URI(EmoteDownloader.HOST + emote.getImage())); HttpResponse response = mEmoteDownloader.getHttpClient().execute(request); if (response.getStatusLine().getStatusCode() != 200) { throw new DownloadException("Download failed for \"" + emote.getImage() + "\" code: " + String.valueOf(response.getStatusLine().getStatusCode())); } HttpEntity entity = response.getEntity(); if (entity == null) { throw new DownloadException("Download failed for \"" + emote.getImage() + "\""); } mEmoteDownloader.checkStorageAvailable(); InputStream is = entity.getContent(); try { File tmpFile = new File(file.getAbsolutePath() + ".tmp"); if (tmpFile.exists()) tmpFile.delete(); StreamUtils.saveStreamToFile(is, tmpFile); tmpFile.renameTo(file); Log.debug("Downloaded emote " + emote.getImage()); } finally { StreamUtils.closeStream(is); } } return file.exists(); }
From source file:aiai.ai.station.StationService.java
private void updateMetadataFile() { final File metadataFile = new File(globals.stationDir, Consts.METADATA_YAML_FILE_NAME); if (metadataFile.exists()) { log.info("Metadata file exists. Make backup"); File yamlFileBak = new File(globals.stationDir, Consts.METADATA_YAML_FILE_NAME + ".bak"); //noinspection ResultOfMethodCallIgnored yamlFileBak.delete();/*from w ww . ja va 2s. co m*/ if (metadataFile.exists()) { //noinspection ResultOfMethodCallIgnored metadataFile.renameTo(yamlFileBak); } } try { FileUtils.write(metadataFile, MetadataUtils.toString(metadata), Charsets.UTF_8, false); } catch (IOException e) { log.error("Error", e); throw new IllegalStateException("Error while writing to file: " + metadataFile.getPath(), e); } }
From source file:com.facebook.infrastructure.io.SSTable.java
public void closeRename(BloomFilter bf) throws IOException { close(bf);//from w ww . java 2s .c om String tmpDataFile = dataFile_; String dataFileName = dataFile_.replace("-" + temporaryFile_, ""); File dataFile = new File(dataFile_); dataFile.renameTo(new File(dataFileName)); dataFile_ = dataFileName; /* Now repair the in memory index associated with the old name */ List<KeyPositionInfo> keyPositionInfos = SSTable.indexMetadataMap_.remove(tmpDataFile); SSTable.indexMetadataMap_.put(dataFile_, keyPositionInfos); }
From source file:com.gmt2001.datastore.IniStore.java
@Override public void RenameFile(String fNameSource, String fNameDest) { fNameSource = validatefName(fNameSource); fNameDest = validatefName(fNameDest); SaveFile(fNameSource, files.get(fNameSource)); if (!FileExists(fNameSource)) { return;/*from w w w. j av a2 s . c o m*/ } SaveFile(fNameDest, files.get(fNameDest)); if (FileExists(fNameDest)) { RemoveFile(fNameDest); } File sourceFile = new File("./" + inifolder + "/" + fNameSource + ".ini"); File destFile = new File("./" + inifolder + "/" + fNameDest + ".ini"); sourceFile.renameTo(destFile); files.remove(fNameSource); LoadFile(fNameDest, false); }
From source file:com.asakusafw.operation.tools.hadoop.fs.CleanTest.java
/** * test case for symlink to file.// w w w . j a v a 2 s.com * @throws Exception if failed to execute */ @Test public void symlink_self() throws Exception { File f1 = touch("a/file1", 50); File f2 = touch("b/file2", 50); File f3 = link("c/link", f1, 50); Assume.assumeThat(f1.delete(), is(true)); f3.renameTo(f1); Clean c = createService(100); c.run(args(0, "-r", path("*"))); assertThat(f2.toString(), f2.exists(), is(false)); }
From source file:net.gleamynode.oil.impl.wal.store.FileLogStore.java
public void finishCompaction(boolean success) { newStore.close();// w ww .j av a 2 s . c o m close(); File newFile = newStore.file; newStore = null; if (success) { if (file.exists() && !file.delete()) { throw new OilException("failed to delete: " + file); } if (!newFile.renameTo(file)) { throw new OilException("failed to rename: " + newFile + " -> " + file); } open(); } else { if (!newFile.delete()) { throw new OilException("failed to delete: " + newFile); } } }
From source file:com.ariatemplates.attester.maven.ArtifactExtractor.java
private boolean renameDirectory(File tempDirectory, File outputDirectory) throws InterruptedException { for (int remainingAttempts = 20; remainingAttempts > 0; remainingAttempts--) { if (outputDirectory.exists()) { // the output directory was created in the mean time // (probably by another build running in parallel) getLog().info("Another process probably extracted the artifact at the same time."); return true; } else if (tempDirectory.renameTo(outputDirectory)) { getLog().info("Renaming the folder succeeded!"); return true; }/* w w w . ja va2 s . c o m*/ // sleep a bit and retry, the failure may be temporary (file opened // by an anti-virus program...) getLog().warn("Renaming the folder failed! Will try again in 250ms..."); Thread.sleep(250); } return false; }
From source file:com.redhat.red.koji.build.Options.java
public boolean parseArgs(final String[] args) throws CmdLineException { final int cols = (System.getenv("COLUMNS") == null ? 100 : Integer.valueOf(System.getenv("COLUMNS"))); final ParserProperties props = ParserProperties.defaults().withUsageWidth(cols); final CmdLineParser parser = new CmdLineParser(this, props); boolean canStart = true; parser.parseArgument(args);// www .j ava2s . c om if (isHelp()) { printUsage(parser, null); canStart = false; } if (isWriteConfig()) { File config = getConfigFile(); Logger logger = LoggerFactory.getLogger(getClass()); logger.info("Writing default configuration file to: {}", config); if (config.isDirectory()) { config = new File(config, "buildfinder.conf"); } if (config.exists()) { File backup = new File(config.getPath() + ".bak"); logger.info("Backing up existing configuration to: {}", backup); config.renameTo(backup); } if (config.getParentFile() != null) { config.getParentFile().mkdirs(); } try (InputStream in = Thread.currentThread().getContextClassLoader() .getResourceAsStream(DEFAULT_CONFIG_RESOURCE); OutputStream out = new FileOutputStream(config)) { if (in == null) { logger.error("Cannot find default configuration in the classpath: {}", DEFAULT_CONFIG_FILE); } else { IOUtils.copy(in, out); } } catch (IOException e) { logger.error("Failed to write config file: " + config, e); } finally { canStart = false; } } return canStart; }