Package com.sk89q.worldedit.util.io

Examples of com.sk89q.worldedit.util.io.Closer


    }

    @Override
    public LocalSession load(UUID id) throws IOException {
        File file = getPath(id);
        Closer closer = Closer.create();
        try {
            FileReader fr = closer.register(new FileReader(file));
            BufferedReader br = closer.register(new BufferedReader(fr));
            return gson.fromJson(br, LocalSession.class);
        } catch (JsonParseException e) {
            throw new IOException(e);
        } catch (FileNotFoundException e) {
            return new LocalSession();
        } finally {
            try {
                closer.close();
            } catch (IOException ignored) {
            }
        }
    }
View Full Code Here


    @Override
    public void save(UUID id, LocalSession session) throws IOException {
        File finalFile = getPath(id);
        File tempFile = new File(finalFile.getParentFile(), finalFile.getName() + ".tmp");
        Closer closer = Closer.create();

        try {
            FileWriter fr = closer.register(new FileWriter(tempFile));
            BufferedWriter bw = closer.register(new BufferedWriter(fr));
            gson.toJson(session, bw);
        } catch (JsonIOException e) {
            throw new IOException(e);
        } finally {
            try {
                closer.close();
            } catch (IOException ignored) {
            }
        }

        if (finalFile.exists()) {
View Full Code Here

        if (format == null) {
            player.printError("Unknown schematic format: " + formatName);
            return;
        }

        Closer closer = Closer.create();
        try {
            String filePath = f.getCanonicalPath();
            String dirPath = dir.getCanonicalPath();

            if (!filePath.substring(0, dirPath.length()).equals(dirPath)) {
                player.printError("Clipboard file could not read or it does not exist.");
            } else {
                FileInputStream fis = closer.register(new FileInputStream(f));
                BufferedInputStream bis = closer.register(new BufferedInputStream(fis));
                ClipboardReader reader = format.getReader(bis);

                WorldData worldData = player.getWorld().getWorldData();
                Clipboard clipboard = reader.read(player.getWorld().getWorldData());
                session.setClipboard(new ClipboardHolder(clipboard, worldData));

                log.info(player.getName() + " loaded " + filePath);
                player.print(filename + " loaded. Paste it with //paste");
            }
        } catch (IOException e) {
            player.printError("Schematic could not read or it does not exist: " + e.getMessage());
            log.log(Level.WARNING, "Failed to load a saved clipboard", e);
        } finally {
            try {
                closer.close();
            } catch (IOException ignored) {
            }
        }
    }
View Full Code Here

            Operations.completeLegacy(result.copyTo(target));
        } else {
            target = clipboard;
        }

        Closer closer = Closer.create();
        try {
            // Create parent directories
            File parent = f.getParentFile();
            if (parent != null && !parent.exists()) {
                if (!parent.mkdirs()) {
                    throw new CommandException("Could not create folder for schematics!");
                }
            }

            FileOutputStream fos = closer.register(new FileOutputStream(f));
            BufferedOutputStream bos = closer.register(new BufferedOutputStream(fos));
            ClipboardWriter writer = closer.register(format.getWriter(bos));
            writer.write(target, holder.getWorldData());
            log.info(player.getName() + " saved " + f.getCanonicalPath());
            player.print(filename + " saved.");
        } catch (IOException e) {
            player.printError("Schematic could not written: " + e.getMessage());
            log.log(Level.WARNING, "Failed to write a saved clipboard", e);
        } finally {
            try {
                closer.close();
            } catch (IOException ignored) {
            }
        }
    }
View Full Code Here

     *
     * @param file the file
     * @throws IOException thrown on I/O error
     */
    public void addFromJar(File file) throws IOException {
        Closer closer = Closer.create();
        JarFile jar = closer.register(new JarFile(file));
        try {
            Enumeration entries = jar.entries();
            while (entries.hasMoreElements()) {
                JarEntry jarEntry = (JarEntry) entries.nextElement();

                String className = jarEntry.getName().replaceAll("[/\\\\]+", ".");

                if (!className.startsWith(SEARCH_PACKAGE_DOT) || jarEntry.isDirectory()) continue;

                int beginIndex = 0;
                int endIndex = className.length() - CLASS_SUFFIX.length();
                className = className.substring(beginIndex, endIndex);
                adapterCandidates.add(className);
            }
        } finally {
            closer.close();
        }
    }
View Full Code Here

TOP

Related Classes of com.sk89q.worldedit.util.io.Closer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.