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

项目:nitrite-database    文件:Nitrite.java   
/**
 * Closes the db immediately without saving last unsaved changes.
 *
 * [icon="{@docRoot}/note.png"]
 * NOTE: This operation is called from the JVM shutdown hook to
 * avoid database corruption.
 * */
void closeImmediately() {
    if (store != null) {
        try {
            store.closeImmediately();
            context.shutdown();
        } catch (NonWritableChannelException error) {
            if (!context.isReadOnly()) {
                log.error("Error while closing nitrite store.", error);
            }
        } catch (Throwable t) {
            log.error("Error while closing nitrite store.", t);
        } finally {
            store = null;
            log.info("Nitrite database has been closed by JVM shutdown hook without saving last unsaved changes.");
        }
    } else {
        log.error("Underlying store is null. Nitrite has not been initialized properly.");
    }
}
项目:OpenJSharp    文件:FileChannelImpl.java   
public long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
项目:OpenJSharp    文件:FileChannelImpl.java   
public int write(ByteBuffer src, long position) throws IOException {
    if (src == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!writable)
        throw new NonWritableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return writeInternal(src, position);
        }
    } else {
        return writeInternal(src, 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 long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
项目:OpenJSharp    文件:FileChannelImpl.java   
public int write(ByteBuffer src, long position) throws IOException {
    if (src == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!writable)
        throw new NonWritableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return writeInternal(src, position);
        }
    } else {
        return writeInternal(src, position);
    }
}
项目:jdk8u-jdk    文件:FileChannelImpl.java   
public long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
项目:jdk8u-jdk    文件:FileChannelImpl.java   
public int write(ByteBuffer src, long position) throws IOException {
    if (src == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!writable)
        throw new NonWritableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return writeInternal(src, position);
        }
    } else {
        return writeInternal(src, position);
    }
}
项目:openjdk-jdk10    文件:FileChannelImpl.java   
public long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
项目:openjdk-jdk10    文件:FileChannelImpl.java   
public int write(ByteBuffer src, long position) throws IOException {
    if (src == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!writable)
        throw new NonWritableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return writeInternal(src, position);
        }
    } else {
        return writeInternal(src, position);
    }
}
项目:dble    文件:FileNio.java   
@Override
public synchronized int write(ByteBuffer src) throws IOException {
    try {
        int len;
        if (fileLength < pos + src.remaining()) {
            int length = (int) (fileLength - pos);
            int limit = src.limit();
            src.limit(length);
            len = channel.write(src);
            src.limit(limit);
            pos += len;
            return len;
        } else {
            len = channel.write(src);
            pos += len;
            return len;
        }
    } catch (NonWritableChannelException e) {
        throw new IOException("read only");
    }
}
项目:openjdk9    文件:FileChannelImpl.java   
public long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
项目:openjdk9    文件:FileChannelImpl.java   
public int write(ByteBuffer src, long position) throws IOException {
    if (src == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!writable)
        throw new NonWritableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return writeInternal(src, position);
        }
    } else {
        return writeInternal(src, position);
    }
}
项目:jdk8u_jdk    文件:FileChannelImpl.java   
public long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
项目:jdk8u_jdk    文件:FileChannelImpl.java   
public int write(ByteBuffer src, long position) throws IOException {
    if (src == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!writable)
        throw new NonWritableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return writeInternal(src, position);
        }
    } else {
        return writeInternal(src, position);
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:FileChannelImpl.java   
public long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
项目:lookaside_java-1.8.0-openjdk    文件:FileChannelImpl.java   
public int write(ByteBuffer src, long position) throws IOException {
    if (src == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!writable)
        throw new NonWritableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return writeInternal(src, position);
        }
    } else {
        return writeInternal(src, position);
    }
}
项目:pravega    文件:FileSystemStorage.java   
private <T> T throwException(String segmentName, Exception e) throws StreamSegmentException {
    if (e instanceof NoSuchFileException || e instanceof FileNotFoundException) {
        throw new StreamSegmentNotExistsException(segmentName);
    }

    if (e instanceof FileAlreadyExistsException) {
        throw new StreamSegmentExistsException(segmentName);
    }

    if (e instanceof IndexOutOfBoundsException) {
        throw new IllegalArgumentException(e.getMessage());
    }

    if (e instanceof AccessControlException
            || e instanceof AccessDeniedException
            || e instanceof NonWritableChannelException) {
        throw new StreamSegmentSealedException(segmentName, e);
    }

    throw Lombok.sneakyThrow(e);
}
项目:javify    文件:FileChannelImpl.java   
public int write (ByteBuffer src, long position)
  throws IOException
{
  if (position < 0)
    throw new IllegalArgumentException ("position: " + position);

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

  if ((mode & WRITE) == 0)
     throw new NonWritableChannelException ();

  int result;
  long oldPosition;

  oldPosition = implPosition ();
  seek (position);
  result = write(src);
  seek (oldPosition);

  return result;
}
项目: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();
}
项目:javify    文件:FileChannelImpl.java   
public FileChannel truncate (long size)
  throws IOException
{
  if (size < 0)
    throw new IllegalArgumentException ("size: " + size);

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

  if ((mode & WRITE) == 0)
     throw new NonWritableChannelException ();

  if (size < size ())
    implTruncate (size);

  return this;
}
项目:JMPQ3    文件:MpqTests.java   
private void insertAndDelete(File mpq, String filename) throws IOException {
    JMpqEditor mpqEditor = new JMpqEditor(mpq, MPQOpenOption.FORCE_V0);
    Assert.assertFalse(mpqEditor.hasFile(filename));
    try {
        String hashBefore = TestHelper.md5(mpq);
        mpqEditor.insertFile(filename, getFile(filename), true);
        mpqEditor.deleteFile(filename);
        mpqEditor.insertFile(filename, getFile(filename), false);
        mpqEditor.close();

        String hashAfter = TestHelper.md5(mpq);
        // If this fails, the mpq is not changed by the insert file command and something went wrong
        Assert.assertNotEquals(hashBefore, hashAfter);

        mpqEditor = new JMpqEditor(mpq, MPQOpenOption.FORCE_V0);
        Assert.assertTrue(mpqEditor.hasFile(filename));

        mpqEditor.deleteFile(filename);
        mpqEditor.close();
        mpqEditor = new JMpqEditor(mpq, MPQOpenOption.READ_ONLY, MPQOpenOption.FORCE_V0);
        Assert.assertFalse(mpqEditor.hasFile(filename));
        mpqEditor.close();
    } catch (NonWritableChannelException ignored) {
    }
}
项目:jvm-stm    文件:FileChannelImpl.java   
public int write (ByteBuffer src, long position)
  throws IOException
{
  if (position < 0)
    throw new IllegalArgumentException ("position: " + position);

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

  if ((mode & WRITE) == 0)
     throw new NonWritableChannelException ();

  int result;
  long oldPosition;

  oldPosition = implPosition ();
  seek (position);
  result = write(src);
  seek (oldPosition);

  return result;
}
项目: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();
}
项目:jvm-stm    文件:FileChannelImpl.java   
public FileChannel truncate (long size)
  throws IOException
{
  if (size < 0)
    throw new IllegalArgumentException ("size: " + size);

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

  if ((mode & WRITE) == 0)
     throw new NonWritableChannelException ();

  if (size < size ())
    implTruncate (size);

  return this;
}
项目:evosuite    文件:EvoFileChannel.java   
@Override
public FileChannel truncate(long size) throws IOException {
    throwExceptionIfClosed();

    if(size < 0){
        throw new MockIllegalArgumentException();
    }

    if(!isOpenForWrite){
        throw new NonWritableChannelException();
    }

    long currentSize = size();
    if(size < currentSize){
        NativeMockedIO.setLength(path, position, size); 
    }

    return this;
}
项目:infobip-open-jdk-8    文件:FileChannelImpl.java   
public long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
项目:infobip-open-jdk-8    文件:FileChannelImpl.java   
public int write(ByteBuffer src, long position) throws IOException {
    if (src == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!writable)
        throw new NonWritableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return writeInternal(src, position);
        }
    } else {
        return writeInternal(src, position);
    }
}
项目:jdk8u-dev-jdk    文件:FileChannelImpl.java   
public long transferFrom(ReadableByteChannel src,
                         long position, long count)
    throws IOException
{
    ensureOpen();
    if (!src.isOpen())
        throw new ClosedChannelException();
    if (!writable)
        throw new NonWritableChannelException();
    if ((position < 0) || (count < 0))
        throw new IllegalArgumentException();
    if (position > size())
        return 0;
    if (src instanceof FileChannelImpl)
       return transferFromFileChannel((FileChannelImpl)src,
                                      position, count);

    return transferFromArbitraryChannel(src, position, count);
}
项目:jdk8u-dev-jdk    文件:FileChannelImpl.java   
public int write(ByteBuffer src, long position) throws IOException {
    if (src == null)
        throw new NullPointerException();
    if (position < 0)
        throw new IllegalArgumentException("Negative position");
    if (!writable)
        throw new NonWritableChannelException();
    ensureOpen();
    if (nd.needsPositionLock()) {
        synchronized (positionLock) {
            return writeInternal(src, position);
        }
    } else {
        return writeInternal(src, position);
    }
}
项目:In-the-Box-Fork    文件:NonWritableChannelExceptionTest.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 = "NonWritableChannelException",
        args = {}
    )
})
public void testSerializationSelf() throws Exception {

    SerializationTest.verifySelf(new NonWritableChannelException());
}
项目:In-the-Box-Fork    文件:NonWritableChannelExceptionTest.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 = "NonWritableChannelException",
        args = {}
    )
})
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this, new NonWritableChannelException());
}
项目:In-the-Box-Fork    文件:OldFileChannelTest.java   
/**
 * @tests java.nio.channels.FileChannel#write(ByteBuffer[])
 */
@TestTargetNew(
    level = TestLevel.PARTIAL_COMPLETE,
    notes = "Verifies NonWritableChannelException",
    method = "write",
    args = {java.nio.ByteBuffer[].class}
)
public void test_write$LByteBuffer_ReadOnly() throws Exception {
    ByteBuffer[] writeBuffers = new ByteBuffer[2];
    writeBuffers[0] = ByteBuffer.allocate(CAPACITY);
    writeBuffers[1] = ByteBuffer.allocate(CAPACITY);

    try {
        readOnlyFileChannel.write(writeBuffers);
        fail("should throw NonWritableChannelException");
    } catch (NonWritableChannelException e) {
        // expected
    }
}
项目:eightyfs    文件:ByteArrayFChannel.java   
@Override
public int write( ByteBuffer src ) throws IOException {
    if( !isOpen() ) {
        throw new ClosedChannelException();
    }

    if( !options.contains( WRITE ) ) {
        throw new NonWritableChannelException();
    }

    synchronized( this ) {
        int len = src.remaining();
        // the cast below is ok because a DynamicByteArray can only hold Integer.MAX bytes (for now)
        //int incr = todo use it
        bytes.write( (int) position, src.array(), src.position(), len /*, 0 */); //store.getUsableSpace() );
        //store.changeSize( -incr );
        position += len;
        src.position( src.limit() );
        watchEventListener.signal( ENTRY_MODIFY );
        FileTime now = FileTime.from( Clock.systemUTC().instant() );
        attis.setTimes( now, now, null );

        return len;
    }
}
项目:eightyfs    文件:ByteArrayFChannel.java   
@Override
public FileChannel truncate( long size ) throws IOException {
    if( !isOpen() ) {
        throw new ClosedChannelException();
    }

    if( !options.contains( WRITE ) ) {
        throw new NonWritableChannelException();
    }

    if ( options.contains( APPEND )) {
        throw new FileSystemException( "can't truncate in append mode" );
    }

    if( size < 0 ) {
        throw new IllegalArgumentException( "size must be non negative" );
    }

    bytes.truncate( (int) size );
    watchEventListener.signal( ENTRY_MODIFY );
    return this;
}
项目:memoryfs    文件:ByteArrayChannel.java   
@Override
    public int write( ByteBuffer src ) throws IOException {
        if( !isOpen() ) {
            throw new ClosedChannelException();
        }

        if( !options.contains( WRITE ) ) {
            throw new NonWritableChannelException();
        }

        synchronized( this ) {
            int len = src.remaining();
            // the cast below is ok because a DynamicByteArray can only hold Integer.MAX bytes (for now)
            int incr = bytes.write( (int) position, src.array(), src.position(), len, store.getUsableSpace() );
            store.changeSize( -incr );
            position += len;
            src.position( src.limit() );
//            watchEventListener.signal( ENTRY_MODIFY );
            attis.setLastAccessTime();
            attis.setLastModifiedTime();
            return len;
        }
    }
项目:memoryfs    文件:ByteArrayChannel.java   
@Override
  public FileChannel truncate( long size ) throws IOException {
      if( !isOpen() ) {
          throw new ClosedChannelException();
      }

      if( !options.contains( WRITE ) ) {
          throw new NonWritableChannelException();
      }

      if ( options.contains( APPEND )) {
          throw new FileSystemException( "can't truncate in append mode" );
      }

      if( size < 0 ) {
          throw new IllegalArgumentException( "size must be non negative" );
      }

      bytes.truncate( (int) size );
//      watchEventListener.signal( ENTRY_MODIFY );
      return this;
  }
项目:JamVM-PH    文件:FileChannelImpl.java   
public int write (ByteBuffer src, long position)
  throws IOException
{
  if (position < 0)
    throw new IllegalArgumentException ("position: " + position);

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

  if ((mode & WRITE) == 0)
     throw new NonWritableChannelException ();

  int result;
  long oldPosition;

  oldPosition = implPosition ();
  seek (position);
  result = write(src);
  seek (oldPosition);

  return result;
}
项目: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();
}
项目:JamVM-PH    文件:FileChannelImpl.java   
public FileChannel truncate (long size)
  throws IOException
{
  if (size < 0)
    throw new IllegalArgumentException ("size: " + size);

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

  if ((mode & WRITE) == 0)
     throw new NonWritableChannelException ();

  if (size < size ())
    implTruncate (size);

  return this;
}