Examples of Closer


Examples of com.google.common.io.Closer

        }

        private Object readCompressedObject(File cacheFile, Class<?> type) {
            // The file is there, load it
            try {
                Closer closer = Closer.create();
                try {
                    InputStream in = closer.register(new FileInputStream(cacheFile));
                    InputStream gzin = closer.register(new GZIPInputStream(in));
                    ObjectInputStream oin = closer.register(new CustomClassLoaderObjectInputStream(gzin, classLoader));
                    return type.cast(oin.readObject());
                } catch (Throwable th) {
                    throw closer.rethrow(th);
                } finally {
                    closer.close();
                }
            } catch (IOException ex) {
                logger.warn("ignoring cache file {} due to read error: {}",
                            cacheFile.getName(), ex.toString());
                logger.info("This error can be caused by a corrupted cache file.");
View Full Code Here

Examples of com.google.common.io.Closer

            return makeDataSource();
        }
        try {
            logger.info("sampling {} of {}",
                        subsampleFraction, source.getName());
            Closer closer = Closer.create();
            RatingWriter subsampleWriter = closer.register(RatingWriters.csv(subsampleFile));
            try {
                mode.doSample(source, subsampleWriter, subsampleFraction, getProject().getRandom());
            } catch (Throwable th) {
                throw closer.rethrow(th);
            } finally {
                closer.close();
            }
        } catch (IOException e) {
            throw new TaskExecutionException("Error writing output file", e);
        }
        return makeDataSource();
View Full Code Here

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

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

    @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

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

        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

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

            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

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

     *
     * @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

Examples of net.sourceforge.purrpackage.recording.Closer

    String encoding;
    FileFinder finder;

    public void read(String sourceFileName, Callback callback) throws Exception {

        Closer c = new Closer();
        final Source source = finder.getSource(sourceFileName);
        if (source == null) {
            throw new SourceReaderException("Could not find source file for "
                    + sourceFileName);
        }
        c.register(new Closeable() {

            @Override
            public void close() throws IOException {
                source.close();
            }
        });

        BufferedReader br = null;
        try {
            br = readerFor(source);
            c.register(br);
        } catch (UnsupportedEncodingException e) {
            throw new SourceReaderException("Encoding problem for source file "
                    + sourceFileName + ": " + e.getMessage());
        } catch (Throwable t) {
            throw new SourceReaderException(
                    "Could not create reader for source file " + sourceFileName
                            + ": " + t.toString());
        }

        try {
            String lineStr;
            while ((lineStr = br.readLine()) != null) {
                callback.lineRead(lineStr);
            }
        } catch (Exception e) {
            c.doNotThrow();
            throw new SourceReaderException("Could not read " + sourceFileName
                    + ": " + e.toString());
        } finally {
            c.closeAll();
        }
    }
View Full Code Here

Examples of org.apache.camel.guice.support.Closer

     */
    public static void close(Injector injector,
            Class<? extends Annotation> scopeAnnotationToClose,
            CloseErrors errors) throws CloseFailedException {
        Set<Closer> closers = getInstancesOf(injector, Closer.class);
        Closer closer = CompositeCloser.newInstance(closers);
        if (closer == null) {
            return;
        }

        Set<Entry<Key<?>, Binding<?>>> entries = injector.getBindings()
View Full Code Here

Examples of org.apache.curator.x.rpc.connections.Closer

            if ( !lock.acquire(maxWaitMs, TimeUnit.MILLISECONDS) )
            {
                return new OptionalLockProjection();
            }

            Closer closer = new Closer()
            {
                @Override
                public void close()
                {
                    if ( lock.isAcquiredInThisProcess() )
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.