Java 类java.nio.channels.NonReadableChannelException 实例源码

项目:OpenJSharp    文件:FileChannelImpl.java   
public int read(ByteBuffer dst, long position) throws IOException {
    if (dst == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!readable)
        throw new NonReadableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return readInternal(dst, position);
        }
    } else {
        return readInternal(dst, position);
    }
}
项目:OpenJSharp    文件:FileChannelImpl.java   
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
项目:OpenJSharp    文件:FileChannelImpl.java   
public int read(ByteBuffer dst, long position) throws IOException {
    if (dst == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!readable)
        throw new NonReadableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return readInternal(dst, position);
        }
    } else {
        return readInternal(dst, position);
    }
}
项目:jdk8u-jdk    文件:FileChannelImpl.java   
public int read(ByteBuffer dst, long position) throws IOException {
    if (dst == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!readable)
        throw new NonReadableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return readInternal(dst, position);
        }
    } else {
        return readInternal(dst, position);
    }
}
项目:openjdk-jdk10    文件:FileChannelImpl.java   
public int read(ByteBuffer dst, long position) throws IOException {
    if (dst == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!readable)
        throw new NonReadableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return readInternal(dst, position);
        }
    } else {
        return readInternal(dst, position);
    }
}
项目:openjdk-jdk10    文件:Transfer.java   
@Test
public void xferTest09() throws Exception { // for bug 6984545
    File source = File.createTempFile("source", null);
    source.deleteOnExit();

    File target = File.createTempFile("target", null);
    target.deleteOnExit();

    FileChannel fc1 = new FileOutputStream(source).getChannel();
    FileChannel fc2 = new RandomAccessFile(target, "rw").getChannel();
    try {
        fc2.transferFrom(fc1, 0L, 0);
        throw new RuntimeException("NonReadableChannelException expected");
    } catch (NonReadableChannelException expected) {
    } finally {
        fc1.close();
        fc2.close();
    }
}
项目:openjdk9    文件:FileChannelImpl.java   
public int read(ByteBuffer dst, long position) throws IOException {
    if (dst == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!readable)
        throw new NonReadableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return readInternal(dst, position);
        }
    } else {
        return readInternal(dst, position);
    }
}
项目:jdk8u_jdk    文件:FileChannelImpl.java   
public int read(ByteBuffer dst, long position) throws IOException {
    if (dst == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!readable)
        throw new NonReadableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return readInternal(dst, position);
        }
    } else {
        return readInternal(dst, position);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:FileChannelImpl.java   
public int read(ByteBuffer dst, long position) throws IOException {
    if (dst == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!readable)
        throw new NonReadableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return readInternal(dst, position);
        }
    } else {
        return readInternal(dst, position);
    }
}
项目:javify    文件:FileChannelImpl.java   
private void lockCheck(long position, long size, boolean shared)
  throws IOException
{
  if (position < 0
      || size < 0)
    throw new IllegalArgumentException ("position: " + position
                                        + ", size: " + size);

  if (!isOpen ())
    throw new ClosedChannelException();

  if (shared && ((mode & READ) == 0))
    throw new NonReadableChannelException();

  if (!shared && ((mode & WRITE) == 0))
    throw new NonWritableChannelException();
}
项目:jvm-stm    文件:FileChannelImpl.java   
private void lockCheck(long position, long size, boolean shared)
  throws IOException
{
  if (position < 0
      || size < 0)
    throw new IllegalArgumentException ("position: " + position
              + ", size: " + size);

  if (!isOpen ())
    throw new ClosedChannelException();

  if (shared && ((mode & READ) == 0))
    throw new NonReadableChannelException();

  if (!shared && ((mode & WRITE) == 0))
    throw new NonWritableChannelException();
}
项目:infobip-open-jdk-8    文件:FileChannelImpl.java   
public int read(ByteBuffer dst, long position) throws IOException {
    if (dst == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!readable)
        throw new NonReadableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return readInternal(dst, position);
        }
    } else {
        return readInternal(dst, position);
    }
}
项目:jdk8u-dev-jdk    文件:FileChannelImpl.java   
public int read(ByteBuffer dst, long position) throws IOException {
    if (dst == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!readable)
        throw new NonReadableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return readInternal(dst, position);
        }
    } else {
        return readInternal(dst, position);
    }
}
项目:In-the-Box-Fork    文件:NonReadableChannelExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "!SerializationSelf",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "NonReadableChannelException",
        args = {}
    )
})
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new NonReadableChannelException());
}
项目:In-the-Box-Fork    文件:NonReadableChannelExceptionTest.java   
/**
 * @tests serialization/deserialization compatibility with RI.
 */
@TestTargets({
    @TestTargetNew(
        level = TestLevel.COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "!SerializationGolden",
        args = {}
    ),
    @TestTargetNew(
        level = TestLevel.PARTIAL_COMPLETE,
        notes = "Verifies serialization/deserialization compatibility.",
        method = "NonReadableChannelException",
        args = {}
    )
})
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new NonReadableChannelException());
}
项目:eightyfs    文件:ByteArrayFChannel.java   
@Override
public int read( ByteBuffer dst ) throws IOException {
    if( !isOpen() ) {
        throw new ClosedChannelException();
    }

    if( !options.contains( READ ) ) {
        throw new NonReadableChannelException();
    }

    int actual = bytes.read( dst, (int) position );

    if( actual < 1 ) {
        return -1;
    }

    position += actual;

    attis.setTimes( null, FileTime.from( Clock.systemUTC().instant() ), null );
    return (int) actual;
}
项目:memoryfs    文件:ByteArrayChannel.java   
@Override
public int read( ByteBuffer dst ) throws IOException {
    if( !isOpen() ) {
        throw new ClosedChannelException();
    }

    if( !options.contains( READ ) ) {
        throw new NonReadableChannelException();
    }

    long len = Math.min( bytes.size() - position, dst.remaining() );

    if( len < 1 ) {
        return -1;
    }

    dst.put( bytes.getBuffer(), (int) position, (int) len );

    position += len;

    attis.setLastAccessTime();
    return (int) len;
}
项目:JamVM-PH    文件:FileChannelImpl.java   
private void lockCheck(long position, long size, boolean shared)
  throws IOException
{
  if (position < 0
      || size < 0)
    throw new IllegalArgumentException ("position: " + position
              + ", size: " + size);

  if (!isOpen ())
    throw new ClosedChannelException();

  if (shared && ((mode & READ) == 0))
    throw new NonReadableChannelException();

  if (!shared && ((mode & WRITE) == 0))
    throw new NonWritableChannelException();
}
项目:classpath    文件:FileChannelImpl.java   
private void lockCheck(long position, long size, boolean shared)
  throws IOException
{
  if (position < 0
      || size < 0)
    throw new IllegalArgumentException ("position: " + position
                                        + ", size: " + size);

  if (!isOpen ())
    throw new ClosedChannelException();

  if (shared && ((mode & READ) == 0))
    throw new NonReadableChannelException();

  if (!shared && ((mode & WRITE) == 0))
    throw new NonWritableChannelException();
}
项目:virt    文件:Stream.java   
@Override
public int read(ByteBuffer buffer) throws IOException {
    if (!isOpen()) throw new ClosedChannelException();
    if (!isReadable()) throw new NonReadableChannelException();
    if (isEOF()) return -1;

    try {
        int ret = receive(buffer);

        switch (ret) {
        case 0:
            finish();
            return -1;

        case -2:
            throw new UnsupportedOperationException("non-blocking I/O stream not yet supported");

        default:
            return ret;
        }
    } catch (LibvirtException e) {
        throw new IOException("could not read from stream", e);
    }
}
项目:OpenJSharp    文件:FileChannelImpl.java   
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    long n;

    // Attempt a direct transfer, if the kernel supports it
    if ((n = transferToDirectly(position, icount, target)) >= 0)
        return n;

    // Attempt a mapped transfer, but only to trusted channel types
    if ((n = transferToTrustedChannel(position, icount, target)) >= 0)
        return n;

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
项目:OpenJSharp    文件:FileChannelImpl.java   
private long transferFromFileChannel(FileChannelImpl src,
                                     long position, long count)
    throws IOException
{
    if (!src.readable)
        throw new NonReadableChannelException();
    return transferFromArbitraryChannel(src, position, count);
}
项目:jdk8u-jdk    文件:FileChannelImpl.java   
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    long n;

    // Attempt a direct transfer, if the kernel supports it
    if ((n = transferToDirectly(position, icount, target)) >= 0)
        return n;

    // Attempt a mapped transfer, but only to trusted channel types
    if ((n = transferToTrustedChannel(position, icount, target)) >= 0)
        return n;

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
项目:openjdk-jdk10    文件:FileChannelImpl.java   
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    long n;

    // Attempt a direct transfer, if the kernel supports it
    if ((n = transferToDirectly(position, icount, target)) >= 0)
        return n;

    // Attempt a mapped transfer, but only to trusted channel types
    if ((n = transferToTrustedChannel(position, icount, target)) >= 0)
        return n;

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
项目:openjdk9    文件:FileChannelImpl.java   
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    long n;

    // Attempt a direct transfer, if the kernel supports it
    if ((n = transferToDirectly(position, icount, target)) >= 0)
        return n;

    // Attempt a mapped transfer, but only to trusted channel types
    if ((n = transferToTrustedChannel(position, icount, target)) >= 0)
        return n;

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
项目:jdk8u_jdk    文件:FileChannelImpl.java   
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    long n;

    // Attempt a direct transfer, if the kernel supports it
    if ((n = transferToDirectly(position, icount, target)) >= 0)
        return n;

    // Attempt a mapped transfer, but only to trusted channel types
    if ((n = transferToTrustedChannel(position, icount, target)) >= 0)
        return n;

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
项目:lookaside_java-1.8.0-openjdk    文件:FileChannelImpl.java   
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    long n;

    // Attempt a direct transfer, if the kernel supports it
    if ((n = transferToDirectly(position, icount, target)) >= 0)
        return n;

    // Attempt a mapped transfer, but only to trusted channel types
    if ((n = transferToTrustedChannel(position, icount, target)) >= 0)
        return n;

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
项目:javify    文件:FileChannelImpl.java   
public MappedByteBuffer map (FileChannel.MapMode mode,
                             long position, long size)
  throws IOException
{
  char nmode = 0;
  if (mode == MapMode.READ_ONLY)
    {
      nmode = 'r';
      if ((this.mode & READ) == 0)
        throw new NonReadableChannelException();
    }
  else if (mode == MapMode.READ_WRITE || mode == MapMode.PRIVATE)
    {
      nmode = mode == MapMode.READ_WRITE ? '+' : 'c';
      if ((this.mode & WRITE) != WRITE)
        throw new NonWritableChannelException();
      if ((this.mode & READ) != READ)
        throw new NonReadableChannelException();
    }
  else
    throw new IllegalArgumentException ("mode: " + mode);

  if (position < 0 || size < 0 || size > Integer.MAX_VALUE)
    throw new IllegalArgumentException ("position: " + position
                                        + ", size: " + size);
  return ch.map(nmode, position, (int) size);
}
项目:javify    文件:FileChannelImpl.java   
public long transferTo (long position, long count,
                        WritableByteChannel target)
  throws IOException
{
  if (position < 0
      || count < 0)
    throw new IllegalArgumentException ("position: " + position
                                        + ", count: " + count);

  if (!isOpen ())
    throw new ClosedChannelException ();

  if ((mode & READ) == 0)
     throw new NonReadableChannelException ();

  final int pageSize = 65536;
  long total = 0;

  while (count > 0)
    {
      int transferred
        = smallTransferTo (position, (int)Math.min (count, pageSize),
                           target);
      if (transferred < 0)
        break;
      total += transferred;
      position += transferred;
      count -= transferred;
    }

  return total;
}
项目:jvm-stm    文件:FileChannelImpl.java   
public MappedByteBuffer map (FileChannel.MapMode mode,
               long position, long size)
   throws IOException
 {
   char nmode = 0;
   if (mode == MapMode.READ_ONLY)
     {
nmode = 'r';
if ((this.mode & READ) == 0)
  throw new NonReadableChannelException();
     }
   else if (mode == MapMode.READ_WRITE || mode == MapMode.PRIVATE)
     {
nmode = mode == MapMode.READ_WRITE ? '+' : 'c';
if ((this.mode & WRITE) != WRITE)
  throw new NonWritableChannelException();
if ((this.mode & READ) != READ)
  throw new NonReadableChannelException();
     }
   else
     throw new IllegalArgumentException ("mode: " + mode);

   if (position < 0 || size < 0 || size > Integer.MAX_VALUE)
     throw new IllegalArgumentException ("position: " + position
                  + ", size: " + size);
   return ch.map(nmode, position, (int) size);
 }
项目:jvm-stm    文件:FileChannelImpl.java   
public long transferTo (long position, long count, 
          WritableByteChannel target)
   throws IOException
 {
   if (position < 0
       || count < 0)
     throw new IllegalArgumentException ("position: " + position
                  + ", count: " + count);

   if (!isOpen ())
     throw new ClosedChannelException ();

   if ((mode & READ) == 0)
      throw new NonReadableChannelException ();

   final int pageSize = 65536;
   long total = 0;

   while (count > 0)
     {
int transferred 
  = smallTransferTo (position, (int)Math.min (count, pageSize), 
             target);
if (transferred < 0)
  break;
total += transferred;
position += transferred;
count -= transferred;
     }

   return total;
 }
项目:j2objc    文件:FileChannelImpl.java   
private FileLock basicLock(long position, long size, boolean shared, boolean wait) throws IOException {
    int accessMode = (mode & O_ACCMODE);
    if (accessMode == O_RDONLY) {
        if (!shared) {
            throw new NonWritableChannelException();
        }
    } else if (accessMode == O_WRONLY) {
        if (shared) {
            throw new NonReadableChannelException();
        }
    }

    if (position < 0 || size < 0) {
        throw new IllegalArgumentException("position=" + position + " size=" + size);
    }

    FileLock pendingLock = new FileLockImpl(this, position, size, shared);
    addLock(pendingLock);

    StructFlock flock = new StructFlock();
    flock.l_type = (short) (shared ? F_RDLCK : F_WRLCK);
    flock.l_whence = (short) SEEK_SET;
    flock.l_start = position;
    flock.l_len = translateLockLength(size);

    boolean success = false;
    try {
        success = (Libcore.os.fcntlFlock(fd, wait ? F_SETLKW64 : F_SETLK64, flock) != -1);
    } catch (ErrnoException errnoException) {
        throw errnoException.rethrowAsIOException();
    } finally {
        if (!success) {
            removeLock(pendingLock);
        }
    }
    return success ? pendingLock : null;
}
项目:j2objc    文件:FileChannelImpl.java   
public final MappedByteBuffer map(MapMode mapMode, long position, long size) throws IOException {
    checkOpen();
    if (mapMode == null) {
        throw new NullPointerException("mapMode == null");
    }
    if (position < 0 || size < 0 || size > Integer.MAX_VALUE) {
        throw new IllegalArgumentException("position=" + position + " size=" + size);
    }
    int accessMode = (mode & O_ACCMODE);
    if (accessMode == O_RDONLY) {
        if (mapMode != MapMode.READ_ONLY) {
            throw new NonWritableChannelException();
        }
    } else if (accessMode == O_WRONLY) {
        throw new NonReadableChannelException();
    }
    if (position + size > size()) {
        // We can't defer to FileChannel.truncate because that will only make a file shorter,
        // and we only care about making our backing file longer here.
        try {
            Libcore.os.ftruncate(fd, position + size);
        } catch (ErrnoException ftruncateException) {
            // EINVAL can be thrown if we're dealing with non-regular
            // files, for example, character devices such as /dev/zero.
            // In those cases, we ignore the failed truncation and
            // continue on.
            try {
                if (S_ISREG(Libcore.os.fstat(fd).st_mode) || ftruncateException.errno != EINVAL) {
                    throw ftruncateException.rethrowAsIOException();
                }
            } catch (ErrnoException fstatException) {
                throw fstatException.rethrowAsIOException();
            }
        }
    }
    long alignment = position - position % Libcore.os.sysconf(_SC_PAGE_SIZE);
    int offset = (int) (position - alignment);
    MemoryBlock block = MemoryBlock.mmap(fd, alignment, size + offset, mapMode);
    return new DirectByteBuffer(block, (int) size, offset, (mapMode == MapMode.READ_ONLY), mapMode);
}
项目:evosuite    文件:EvoFileChannel.java   
private int read(ByteBuffer[] dsts, int offset, int length, AtomicInteger posToUpdate)
        throws IOException {
    if(!isOpenForRead){
        throw new NonReadableChannelException();
    }

    throwExceptionIfClosed();

    int counter = 0;

    synchronized(readWriteMonitor){
        for(int j=offset; j<length; j++){
            ByteBuffer dst = dsts[j];
            int r = dst.remaining();
            for(int i=0; i<r; i++){
                int b = NativeMockedIO.read(path, posToUpdate);
                if(b < 0){ //end of stream
                    return -1;
                }

                if(closed){
                    throw new AsynchronousCloseException();
                }

                if(Thread.currentThread().isInterrupted()){
                    close();
                    throw new ClosedByInterruptException();
                }

                dst.put((byte)b);
                counter++;
            }
        }
    }

    return counter;     
}
项目:infobip-open-jdk-8    文件:FileChannelImpl.java   
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    long n;

    // Attempt a direct transfer, if the kernel supports it
    if ((n = transferToDirectly(position, icount, target)) >= 0)
        return n;

    // Attempt a mapped transfer, but only to trusted channel types
    if ((n = transferToTrustedChannel(position, icount, target)) >= 0)
        return n;

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
项目:jdk8u-dev-jdk    文件:FileChannelImpl.java   
public long transferTo(long position, long count,
                       WritableByteChannel target)
    throws IOException
{
    ensureOpen();
    if (!target.isOpen())
        throw new ClosedChannelException();
    if (!readable)
        throw new NonReadableChannelException();
    if (target instanceof FileChannelImpl &&
        !((FileChannelImpl)target).writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    long sz = size();
    if (position > sz)
        return 0;
    int icount = (int)Math.min(count, Integer.MAX_VALUE);
    if ((sz - position) < icount)
        icount = (int)(sz - position);

    long n;

    // Attempt a direct transfer, if the kernel supports it
    if ((n = transferToDirectly(position, icount, target)) >= 0)
        return n;

    // Attempt a mapped transfer, but only to trusted channel types
    if ((n = transferToTrustedChannel(position, icount, target)) >= 0)
        return n;

    // Slow path for untrusted targets
    return transferToArbitraryChannel(position, icount, target);
}
项目:ephemeralfs    文件:EphemeralFsFileChannel.java   
private void assertReadable() throws NonReadableChannelException, IOException {
    if(iNode.isDir()) {
        throw new IOException("Is a directory");
    }
    if(!canRead) {
        throw new NonReadableChannelException();
    }
}
项目:In-the-Box-Fork    文件:WriteOnlyFileChannel.java   
public long transferTo(long position, long count, WritableByteChannel target)
        throws IOException {
    openCheck();
    if (!target.isOpen()) {
        throw new ClosedChannelException();
    }
    throw new NonReadableChannelException();
}
项目:In-the-Box-Fork    文件:WriteOnlyFileChannel.java   
public long read(ByteBuffer[] buffers, int offset, int length)
        throws IOException {
    if (offset < 0 || length < 0 || offset + length > buffers.length) {
        throw new IndexOutOfBoundsException();
    }
    openCheck();
    throw new NonReadableChannelException();
}
项目:In-the-Box-Fork    文件:WriteOnlyFileChannel.java   
public int read(ByteBuffer buffer, long position) throws IOException {
    if (null == buffer) {
        throw new NullPointerException();
    }
    if (position < 0) {
        throw new IllegalArgumentException();
    }
    throw new NonReadableChannelException();
}