本文整理匯總了Java中java.nio.channels.NonWritableChannelException類的典型用法代碼示例。如果您正苦於以下問題:Java NonWritableChannelException類的具體用法?Java NonWritableChannelException怎麽用?Java NonWritableChannelException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
NonWritableChannelException類屬於java.nio.channels包,在下文中一共展示了NonWritableChannelException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: closeImmediately
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
/**
* 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.");
}
}
示例2: transferFrom
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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);
}
示例3: write
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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);
}
}
示例4: transferTo
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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);
}
示例5: write
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
@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");
}
}
示例6: throwException
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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);
}
示例7: write
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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;
}
示例8: lockCheck
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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();
}
示例9: truncate
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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;
}
示例10: insertAndDelete
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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) {
}
}
示例11: write
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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;
}
示例12: lockCheck
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
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();
}
示例13: truncate
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
@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;
}
示例14: testSerializationSelf
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
/**
* @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());
}
示例15: testSerializationCompatibility
import java.nio.channels.NonWritableChannelException; //導入依賴的package包/類
/**
* @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());
}