List of usage examples for java.io File toPath
public Path toPath()
From source file:com.themodernway.server.core.io.IO.java
public static final boolean delete(final File file) throws IOException { return delete(file.toPath()); }
From source file:com.themodernway.server.core.io.IO.java
public static final Stream<String> lines(final File file) throws IOException { return IO.lines(file.toPath(), false); }
From source file:RestoreService.java
public static void setAdvancedAttributes(final VOBackupFile voBackupFile, final File file) throws IOException { // advanced attributes // owner/*from w w w . j a v a 2 s . c o m*/ if (StringUtils.isNotBlank(voBackupFile.getOwner())) { try { UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); UserPrincipal userPrincipal = lookupService.lookupPrincipalByName(voBackupFile.getOwner()); Files.setOwner(file.toPath(), userPrincipal); } catch (UserPrincipalNotFoundException e) { logger.warn("Cannot set owner {}", voBackupFile.getOwner()); } } if (Files.getFileStore(file.toPath()).supportsFileAttributeView(DosFileAttributeView.class) && BooleanUtils.isTrue(voBackupFile.getDosAttr())) { Files.setAttribute(file.toPath(), "dos:hidden", BooleanUtils.isTrue(voBackupFile.getDosHidden())); Files.setAttribute(file.toPath(), "dos:archive", BooleanUtils.isTrue(voBackupFile.getDosArchive())); Files.setAttribute(file.toPath(), "dos:readonly", BooleanUtils.isTrue(voBackupFile.getDosReadOnly())); Files.setAttribute(file.toPath(), "dos:system", BooleanUtils.isTrue(voBackupFile.getDosSystem())); } if (Files.getFileStore(file.toPath()).supportsFileAttributeView(PosixFileAttributeView.class) && BooleanUtils.isTrue(voBackupFile.getPosixAttr())) { try { UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); GroupPrincipal groupPrincipal = lookupService .lookupPrincipalByGroupName(voBackupFile.getPosixGroup()); Files.getFileAttributeView(file.toPath(), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS) .setGroup(groupPrincipal); } catch (UserPrincipalNotFoundException e) { logger.warn("Cannot set group {}", voBackupFile.getOwner()); } if (StringUtils.isNotBlank(voBackupFile.getPosixPermitions())) { Set<PosixFilePermission> perms = PosixFilePermissions.fromString(voBackupFile.getPosixPermitions()); Files.setPosixFilePermissions(file.toPath(), perms); } } }
From source file:net.certiv.antlr.project.util.Utils.java
/** * Move all files from the source directory to the destination directory. * // w w w . j ava 2s.c o m * @param source * the source directory * @param dest * the destination directory * @return * @throws IOException */ public static boolean moveAllFiles(File source, File dest) throws IOException { if (source == null || dest == null) throw new IllegalArgumentException("Directory cannot be null"); if (!source.exists() || !source.isDirectory()) throw new IOException("Source directory must exist: " + source.getCanonicalPath()); dest.mkdirs(); if (!dest.exists() || !dest.isDirectory()) throw new IOException("Destination directory must exist: " + dest.getCanonicalPath()); Path srcDir = source.toPath(); Path dstDir = dest.toPath(); DirectoryStream<Path> ds = Files.newDirectoryStream(srcDir); int tot = 0; for (Path src : ds) { Files.copy(src, dstDir.resolve(src.getFileName()), REPLACE_EXISTING); tot++; } Log.info(Utils.class, "Moved " + tot + " files"); return false; }
From source file:io.syndesis.image.Application.java
@SuppressWarnings("PMD.UseProperClassLoader") private static void generate(GenerateProjectRequest request, File targetDir) throws IOException { MavenProperties mavenProperties = new MavenProperties(); ProjectGeneratorProperties generatorProperties = new ProjectGeneratorProperties(mavenProperties); ConnectorCatalogProperties catalogProperties = new ConnectorCatalogProperties(mavenProperties); StepVisitorFactoryRegistry registry = new StepVisitorFactoryRegistry(Arrays.asList()); DefaultProjectGenerator generator = new DefaultProjectGenerator(new ConnectorCatalog(catalogProperties), generatorProperties, registry); Path dir = targetDir.toPath(); Files.createDirectories(dir); Files.write(dir.resolve("pom.xml"), generator.generatePom(request.getIntegration())); dir = dir.resolve("src/main/java/io/syndesis/example"); Files.createDirectories(dir); String resourceFile = "io/syndesis/project/converter/templates/Application.java.mustache"; try (InputStream is = Application.class.getClassLoader().getResourceAsStream(resourceFile)) { Files.write(dir.resolve("Application.java"), readAllBytes(is)); }// w w w.j a v a 2 s .c o m }
From source file:com.themodernway.server.core.io.IO.java
public static final BufferedReader toBufferedReader(final File file) throws IOException { return IO.toBufferedReader(file.toPath()); }
From source file:com.kegare.caveworld.world.WorldProviderDeepCaveworld.java
public static void regenerate(final boolean backup) { final File dir = getDimDir(); final String name = dir.getName().substring(4); final MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); Set<EntityPlayerMP> target = Sets.newHashSet(); for (Object obj : server.getConfigurationManager().playerEntityList.toArray()) { if (obj != null && ((EntityPlayerMP) obj).dimension == CaveworldAPI.getDeepDimension()) { target.add(CaveUtils.respawnPlayer((EntityPlayerMP) obj, 0)); }//from w ww .j a va 2 s. c o m } boolean result = new ForkJoinPool().invoke(new RecursiveTask<Boolean>() { @Override protected Boolean compute() { IChatComponent component; try { component = new ChatComponentText( StatCollector.translateToLocalFormatted("caveworld.regenerate.regenerating", name)); component.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true); server.getConfigurationManager().sendChatMsg(component); if (server.isSinglePlayer()) { Caveworld.network.sendToAll(new RegenerateMessage(backup)); } Caveworld.network.sendToAll(new RegenerateMessage.ProgressNotify(0)); CaveBlocks.caveworld_portal.portalDisabled = true; int dim = CaveworldAPI.getDeepDimension(); WorldServer world = DimensionManager.getWorld(dim); if (world != null) { world.saveAllChunks(true, null); world.flush(); MinecraftForge.EVENT_BUS.post(new WorldEvent.Unload(world)); DimensionManager.setWorld(dim, null); } if (dir != null) { if (backup) { File parent = dir.getParentFile(); final Pattern pattern = Pattern.compile("^" + dir.getName() + "_bak-..*\\.zip$"); File[] files = parent.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return pattern.matcher(name).matches(); } }); if (files != null && files.length >= 5) { Arrays.sort(files, new Comparator<File>() { @Override public int compare(File o1, File o2) { int i = CaveUtils.compareWithNull(o1, o2); if (i == 0 && o1 != null && o2 != null) { try { i = Files.getLastModifiedTime(o1.toPath()) .compareTo(Files.getLastModifiedTime(o2.toPath())); } catch (IOException e) { } } return i; } }); FileUtils.forceDelete(files[0]); } Calendar calendar = Calendar.getInstance(); String year = Integer.toString(calendar.get(Calendar.YEAR)); String month = String.format("%02d", calendar.get(Calendar.MONTH) + 1); String day = String.format("%02d", calendar.get(Calendar.DATE)); String hour = String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY)); String minute = String.format("%02d", calendar.get(Calendar.MINUTE)); String second = String.format("%02d", calendar.get(Calendar.SECOND)); File bak = new File(parent, dir.getName() + "_bak-" + Joiner.on("").join(year, month, day) + "-" + Joiner.on("").join(hour, minute, second) + ".zip"); if (bak.exists()) { FileUtils.deleteQuietly(bak); } component = new ChatComponentText(StatCollector .translateToLocalFormatted("caveworld.regenerate.backingup", name)); component.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true); server.getConfigurationManager().sendChatMsg(component); Caveworld.network.sendToAll(new RegenerateMessage.ProgressNotify(1)); if (CaveUtils.archiveDirZip(dir, bak)) { ClickEvent click = new ClickEvent(ClickEvent.Action.OPEN_FILE, FilenameUtils.normalize(bak.getParentFile().getPath())); component = new ChatComponentText(StatCollector .translateToLocalFormatted("caveworld.regenerate.backedup", name)); component.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true) .setChatClickEvent(click); server.getConfigurationManager().sendChatMsg(component); } else { component = new ChatComponentText(StatCollector .translateToLocalFormatted("caveworld.regenerate.backup.failed", name)); component.getChatStyle().setColor(EnumChatFormatting.RED).setItalic(true); server.getConfigurationManager().sendChatMsg(component); } } FileUtils.deleteDirectory(dir); } if (DimensionManager.shouldLoadSpawn(dim)) { DimensionManager.initDimension(dim); world = DimensionManager.getWorld(dim); if (world != null) { world.saveAllChunks(true, null); world.flush(); } } CaveBlocks.caveworld_portal.portalDisabled = false; component = new ChatComponentText( StatCollector.translateToLocalFormatted("caveworld.regenerate.regenerated", name)); component.getChatStyle().setColor(EnumChatFormatting.GRAY).setItalic(true); server.getConfigurationManager().sendChatMsg(component); Caveworld.network.sendToAll(new RegenerateMessage.ProgressNotify(2)); return true; } catch (Exception e) { component = new ChatComponentText( StatCollector.translateToLocalFormatted("caveworld.regenerate.failed", name)); component.getChatStyle().setColor(EnumChatFormatting.RED).setItalic(true); server.getConfigurationManager().sendChatMsg(component); Caveworld.network.sendToAll(new RegenerateMessage.ProgressNotify(3)); CaveLog.log(Level.ERROR, e, component.getUnformattedText()); } return false; } }); if (result && (Config.hardcore || Config.caveborn)) { for (EntityPlayerMP player : target) { if (!CaveworldAPI.isEntityInCaveworld(player)) { CaveUtils.forceTeleport(player, CaveworldAPI.getDeepDimension()); } } } }
From source file:com.themodernway.server.core.io.IO.java
public static final Stream<String> lines(final File file, final boolean greedy) throws IOException { return IO.lines(file.toPath(), greedy); }
From source file:com.themodernway.server.core.io.IO.java
public static final InputStream toInputStream(final File file, final OpenOption... options) throws IOException { return IO.toInputStream(file.toPath(), options); }
From source file:com.themodernway.server.core.io.IO.java
public static BufferedWriter toBufferedWriter(final File file, final OpenOption... options) throws IOException { return IO.toBufferedWriter(file.toPath(), options); }