Examples of Closeable


Examples of java.io.Closeable

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

public class StreamsTestCase extends TestCase {
    public void testSimpleClose() throws Exception {
        Closeable closeable = mock(Closeable.class);
        Streams.close(closeable);
        verify(closeable).close();
    }
View Full Code Here

Examples of java.io.Closeable

        Streams.close(closeable);
        verify(closeable).close();
    }

    public void testCloseWithNullParameter() throws Exception {
        Closeable closeable = mock(Closeable.class);
        Streams.close(closeable, null);
        verify(closeable).close();
    }
View Full Code Here

Examples of java.io.Closeable

            s = new Socket();
            s.connect(endpoint,3000);
            out = new SocketOutputStream(s);
        }

        closables.add(new Closeable() {
            public void close() throws IOException {
                s.close();
            }
        });
View Full Code Here

Examples of java.io.Closeable

        setName("sockmon");
        setDaemon(true);
    }

    private static Closeable wrapSocket(final Socket socket) {
        return new Closeable() {
            @Override
            public void close()
                    throws IOException {
                socket.close();
            }
View Full Code Here

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

Examples of java.io.Closeable

    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

Examples of java.io.Closeable

    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

Examples of java.io.Closeable

        // 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

Examples of java.io.Closeable

    @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

Examples of java.io.Closeable

        // 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
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.