java.nio.channels.NonReadableChannelException Java Examples
The following examples show how to use
java.nio.channels.NonReadableChannelException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FileChannelImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #2
Source File: FileChannelImpl.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #3
Source File: FileChannelUtility.java From database with GNU General Public License v2.0 | 6 votes |
/** * Schedule a read on the channel. If the operation was previously * schedule and is done (normal completion), then return immediately. If * the operation was previously schedule and was cancelled, then throws * out a CancellationException. If the operation was previously schedule * and failed, then the future is cleared and the operation is * rescheduled. This is done in order to allow us to complete a high * level read on the channel when the backing channel may have been * closed by an interrupt in another thread due to Java IO channel * semantics (e.g., driven by query termination during reads). * * @param channel The channel. * * @throws IllegalArgumentException * @throws NonReadableChannelException * @throws CancellationException * @throws InterruptedException */ private void read(final AsynchronousFileChannel channel) throws IllegalArgumentException, NonReadableChannelException, CancellationException, InterruptedException { if (isDone()) { // Check for re-scheduling of the read(). try { /* * Note: It is either unlikely or impossible to have an * InterruptedException thrown out here since we know that * the Future isDone(). */ m_fut.get(); // throws CancellationException, ExecutionException, InterruptedException. } catch (ExecutionException ex) { /* * This read() had failed. We clear future so we can re-do * the read. */ m_fut = null; } } if(!isDone()) { // ensure buffer is ready m_buffer.reset(); m_fut = channel.read(m_buffer, m_addr); // throws IllegalArgumentException, NonReadableChannelException } }
Example #4
Source File: FileChannelImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #5
Source File: FileChannelImpl.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #6
Source File: FileChannelImpl.java From hottub with GNU General Public License v2.0 | 6 votes |
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); } }
Example #7
Source File: FileChannelImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example #8
Source File: Transfer.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@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(); } }
Example #9
Source File: FileChannelImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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); } }
Example #10
Source File: FileChannelImpl.java From Bytecoder with Apache License 2.0 | 6 votes |
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(); if (direct) Util.checkChannelPositionAligned(position, alignment); ensureOpen(); if (nd.needsPositionLock()) { synchronized (positionLock) { return readInternal(dst, position); } } else { return readInternal(dst, position); } }
Example #11
Source File: FileChannelImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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); } }
Example #12
Source File: FileChannelImpl.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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); } }
Example #13
Source File: FileChannelImpl.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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); } }
Example #14
Source File: FileChannelImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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); } }
Example #15
Source File: FileChannelImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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); }
Example #16
Source File: FileLocks.java From tutorials with MIT License | 5 votes |
/** * Trying to get a shared lock on a write-only FileChannel won't work. */ static void getReadLockFromOutputStream() throws IOException { Path path = Files.createTempFile("foo", "txt"); try (FileOutputStream fis = new FileOutputStream(path.toFile()); FileLock lock = fis.getChannel() .lock(0, Long.MAX_VALUE, true)) { LOG.debug("This won't happen"); } catch (NonReadableChannelException e) { LOG.error("The channel obtained through a FileOutputStream isn't readable. " + "You can't obtain an shared lock on it!"); throw e; } }
Example #17
Source File: NonReadableChannelExceptionTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * @tests {@link java.nio.channels.NonReadableChannelException#NonReadableChannelException()} */ public void test_Constructor() { NonReadableChannelException e = new NonReadableChannelException(); assertNull(e.getMessage()); assertNull(e.getLocalizedMessage()); assertNull(e.getCause()); }
Example #18
Source File: FileChannelTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_transferToJJLWritableByteChannel_NonReadable() throws Exception { writableByteChannel = DatagramChannel.open(); try { writeOnlyFileChannel.transferTo(0, 10, writableByteChannel); fail(); } catch (NonReadableChannelException expected) { } }
Example #19
Source File: FileChannelTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * @tests java.nio.channels.FileChannel#transferFrom(ReadableByteChannel,long,long) */ public void test_transferFromLReadableByteChannelJJ_SourceNonReadable() throws Exception { try { readWriteFileChannel.transferFrom(writeOnlyFileChannel, 0, 0); fail("should throw NonReadableChannelException."); } catch (NonReadableChannelException e) { // expected } // not throws NonReadableChannelException first if position beyond file // size. readWriteFileChannel.transferFrom(writeOnlyFileChannel, 10, 10); }
Example #20
Source File: FileChannelTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_readLByteBufferJ_WriteOnly() throws Exception { ByteBuffer readBuffer = ByteBuffer.allocate(CAPACITY); try { writeOnlyFileChannel.read(readBuffer, 0); fail(); } catch (NonReadableChannelException expected) { } }
Example #21
Source File: FileChannelImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #22
Source File: FileChannelImpl.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #23
Source File: FileChannelImpl.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
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); }
Example #24
Source File: FileChannelImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
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); }
Example #25
Source File: FileChannelImpl.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #26
Source File: FileChannelImpl.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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); }
Example #27
Source File: FileChannelImpl.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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); }
Example #28
Source File: FileChannelImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
private void checkMode(MapMode mode, int prot, boolean isSync) { if (prot == MAP_INVALID) { throw new UnsupportedOperationException(); } if ((mode != MapMode.READ_ONLY) && mode != ExtendedMapMode.READ_ONLY_SYNC && !writable) throw new NonWritableChannelException(); if (!readable) throw new NonReadableChannelException(); // reject SYNC request if writeback is not enabled for this platform if (isSync && !Unsafe.isWritebackEnabled()) { throw new UnsupportedOperationException(); } }
Example #29
Source File: FileChannelImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
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); }
Example #30
Source File: FileChannelImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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); }