Package java.nio.channels

Examples of java.nio.channels.SeekableByteChannel


    super.close();
  }

  private SeekableByteChannel openByteChannelAtCurrentPosition() {
    try {
      SeekableByteChannel channel = Files.newByteChannel(logfile, StandardOpenOption.READ);
      Optional<Long> previousPosition = store.getPosition(tailMetadata);
      if (previousPosition.isPresent()) {
        long storePosition = previousPosition.get();

        if (storePosition < channel.size()) {
          LOG.warn("Found {} with size {} and position {}, resetting to 0", logfile, channel.size(), storePosition);
          savePosition(0);
        } else {
          channel.position(previousPosition.get());
        }
      }
      return channel;
    } catch (IOException e) {
      throw Throwables.propagate(e);
View Full Code Here


  @Test
  public void testOpenChannelsClosed() throws IOException {
    Path p = fs.getPath("/foo");
    FileChannel fc = FileChannel.open(p, READ, WRITE, CREATE);
    SeekableByteChannel sbc = Files.newByteChannel(p, READ);
    AsynchronousFileChannel afc = AsynchronousFileChannel.open(p, READ, WRITE);

    assertTrue(fc.isOpen());
    assertTrue(sbc.isOpen());
    assertTrue(afc.isOpen());

    fs.close();

    assertFalse(fc.isOpen());
    assertFalse(sbc.isOpen());
    assertFalse(afc.isOpen());

    try {
      fc.size();
      fail();
    } catch (ClosedChannelException expected) {
    }

    try {
      sbc.size();
      fail();
    } catch (ClosedChannelException expected) {
    }

    try {
View Full Code Here

TOP

Related Classes of java.nio.channels.SeekableByteChannel

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.