Package java.io

Examples of java.io.Closeable


  public static void zip(File directory, File zipfile) throws IOException {
      URI base = directory.toURI();
      Deque<File> queue = new LinkedList<File>();
      queue.push(directory);
      OutputStream out = new FileOutputStream(zipfile);
      Closeable res = out;
      try {
        ZipOutputStream zout = new ZipOutputStream(out);
        res = zout;
        while (!queue.isEmpty()) {
          directory = queue.pop();
          for (File kid : directory.listFiles()) {
            String name = base.relativize(kid.toURI()).getPath();
            if (kid.isDirectory()) {
              queue.push(kid);
              name = name.endsWith("/") ? name : name + "/";
              zout.putNextEntry(new ZipEntry(name));
            } else {
              zout.putNextEntry(new ZipEntry(name));
              copy(kid, zout);
              zout.closeEntry();
            }
          }
        }
      } finally {
        res.close();
      }
    }
View Full Code Here


    IOUtils.closeQuietly(null);
  }

  @Test
  public void closeQuietlyWhenExceptionThrown() throws IOException {
    Closeable stream = mock(Closeable.class);
    doThrow(new IOException()).when(stream).close();
    IOUtils.closeQuietly(stream);
  }
View Full Code Here

    IOUtils.closeQuietly(stream);
  }

  @Test
  public void closeQuietly() throws IOException {
    Closeable stream = mock(Closeable.class);
    IOUtils.closeQuietly(stream);
    verify(stream, times(1)).close();
  }
View Full Code Here

        // Selector keys() set may change while we are iterating.
        while (true) {
            try {
                for (SelectionKey key : selector.keys()) {
                    try {
                        Closeable asyncKey = (Closeable) key.attachment();
                        if (asyncKey != null) {
          asyncKey.close();
                        }
                    } catch (IOException ignore) { }
                }
            } catch (ConcurrentModificationException e) {
                continue;
View Full Code Here

    @Override
    @Nonnull
    public Closeable addObserver(final Observer observer) {
        observer.contentChanged(root, null);
        observers.addObserver(observer);
        return new Closeable() {
            @Override
            public void close() {
                observers.removeObserver(observer);
            }
        };
View Full Code Here

        // shell's error stream!!
//        if (ios.length > 3) {
//            throw new RuntimeException("> 3 CommandIOs not implemented yet");
//        }
        StreamBindings streamBindings = new StreamBindings();
        Closeable in = ios[Command.STD_IN].findBaseStream();
        if (in instanceof FileInputStream) {
            streamBindings.setIn((FileInputStream) in);
        } else {
            streamBindings.setIn(createSocketForInput(in));
        }
        Closeable out = ios[Command.STD_OUT].findBaseStream();
        if (out instanceof FileOutputStream) {
            streamBindings.setOut((FileOutputStream) out);
        } else {
            streamBindings.setOut(createSocketForOutput(out));
        }
        Closeable err = ios[Command.STD_ERR].findBaseStream();
        if (err instanceof FileOutputStream) {
            streamBindings.setErr((FileOutputStream) err);
        } else {
            streamBindings.setErr(createSocketForOutput(err));
        }
View Full Code Here

    public void close() throws IOException {
        Throwable throwable = thrown;

        // close closeables in LIFO order
        while (!stack.isEmpty()) {
            Closeable closeable = stack.pop();
            try {
                closeable.close();
            } catch (Throwable e) {
                if (throwable == null) {
                    throwable = e;
                } else {
                    suppressor.suppress(closeable, throwable, e);
View Full Code Here

      assemblyNode.setTarget(virtualFile);
   }

   public void add(final String path, final File root) throws IOException {
      VirtualFile mountPoint = mountRoot.getChild(path);
      Closeable handle = VFS.mountReal(root, mountPoint);
      mountHandles.add(handle);
      add(path, mountPoint);
   }
View Full Code Here

      add(path, temp);
   }

   public void addZip(final String path, final File zipFile) throws IOException {
      VirtualFile mountPoint = mountRoot.getChild(path);
      Closeable handle = VFS.mountZip(zipFile, mountPoint, getTempFileProvider());
      mountHandles.add(handle);
      add(path, mountPoint);
   }
View Full Code Here

                }
                return null;
            }
        }

        Closeable handle;
        try {

            // If the file exists
            if (file.exists()) {

                // Mount Exploded dir
                if (file.isDirectory()) {
                    handle = VFS.mountReal(file.getPhysicalFile(), file);
                }
                // Mount EJB JAR
                else if (file.getName().endsWith(EXTENSION_JAR)) {
                    if (provider == null) {
                        provider = TempFileProvider.create("jbossejbmodulescanner", ses);
                    }
                    handle = VFS.mountZip(file.getPhysicalFile(), file, provider);
                }
                // No conditions met
                else {
                    // So it's obvious if we've got something we didn't properly mount
                    ROOT_LOGGER.skippingUnknownFileType(file);
                    return null;
                }

            }
            // Not a real file
            else {
                ROOT_LOGGER.fileNotFound(file);
                return null;
            }

            try {
                /*
                * Directories and real JARs are handled the same way in VFS, so just do
                * one check and skip logic to test isDirectory or not
                */

                // Look for META-INF/ejb-jar.xml
                final VirtualFile ejbJarXml = file.getChild(PATH_EJB_JAR_XML);
                if (ejbJarXml.exists()) {
                    if (ROOT_LOGGER.isTraceEnabled()) {
                        ROOT_LOGGER.tracef("Found descriptor %s in %s", ejbJarXml.getPathNameRelativeTo(file), file);
                    }
                    return getModuleNameFromEjbJar(file, ejbJarXml);
                }

                // Look for at least one .class with an EJB annotation
                if (containsEjbComponentClass(file)) {
                    return getModuleNameFromFileName(file);
                }

                // Return
                return null;
            } finally {
                try {
                    handle.close();
                } catch (final IOException e) {
                    // Ignore
                    ROOT_LOGGER.cannotCloseFile(e, file);
                }
            }
View Full Code Here

TOP

Related Classes of java.io.Closeable

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.