@Override public boolean isOpen() { return ch.isOpen(); } }
@Override public boolean isEndOfInput() throws Exception { return !(offset < endOffset && in.isOpen()); }
@Override public boolean isOpen() { return channel.isOpen(); }
@Override public boolean isEndOfInput() throws Exception { return !(offset < endOffset && in.isOpen()); }
@Override public boolean isWriteShutdown() { return !fileChannel.isOpen(); }
@Override public void close() throws IOException { if(channel.isOpen()) { if (forceOnClose) { channel.force(true); } channel.close(); } } }
@Override public boolean isEndOfInput() throws Exception { return !(offset < endOffset && file.getChannel().isOpen()); }
@Override public void write(Buffer source, long byteCount) throws IOException { if (!channel.isOpen()) throw new IllegalStateException("closed"); if (byteCount == 0) return; long remaining = byteCount; while (remaining > 0) { long written = channel.transferFrom(source, position, remaining); position += written; remaining -= written; } }
public void run() { if (address == 0) return; try { unmap0(address, size); address = 0; if (channel.isOpen()) { channel.close(); } } catch (Exception e) { e.printStackTrace(); } } }
@Override public long read(Buffer sink, long byteCount) throws IOException { if (!channel.isOpen()) throw new IllegalStateException("closed"); if (position == channel.size()) return -1L; long read = channel.transferTo(position, byteCount, sink); position += read; return read; }
@Override public boolean isEndOfInput() throws Exception { return !(offset < endOffset && file.getChannel().isOpen()); }
/** * @throws FileNotFoundException */ public void checkOpen() throws FileNotFoundException { if (cachedFile != null || !cachedChannel.isOpen()) { cachedRAFile = new RandomAccessFile(cachedFile, "rw"); cachedChannel = cachedRAFile.getChannel(); } }
@Override public synchronized int getReceiveBufferSize() throws SocketException { if (!channel.isOpen()) { throw new SocketException("Socket is closed"); } throw new UnsupportedOperationException("Getting the receive buffer size is not supported"); }
@Override public void flush() { try { if (channel.isOpen()) { channel.force(true); } } catch (IOException e) { throw new StorageException(e); } }
@Override protected long transferContentTo(WritableByteChannel target) throws IOException { // WARN: don't use channel.position(), it's always 0 here // from FileChannel javadoc: "This method does not modify this channel's // position." long transferred = getChannel().transferTo(position, BodyChunkedInput.DEFAULT_CHUNK_SIZE, target); if (transferred > 0) { position += transferred; } if (position == length || transferred < 0) { state = MultipartState.POST_CONTENT; if (channel.isOpen()) { channel.close(); } } else { slowTarget = true; } return transferred; }
@Override protected long transferContentTo(ByteBuf target) throws IOException { // can return -1 if file is empty or FileChannel was closed int transferred = target.writeBytes(getChannel(), target.writableBytes()); if (transferred > 0) { position += transferred; } if (position == length || transferred < 0) { state = MultipartState.POST_CONTENT; if (channel.isOpen()) { channel.close(); } } return transferred; }
public void release() throws IOException { if (!channel().isOpen()) { throw new ClosedChannelException(); } if (!isReleased) { ((FileChannelImpl) channel()).release(this); isReleased = true; } } }
@Test public void testCleanup() { try { ByteBuffer data = ByteBuffer.allocate(157); data.order(ByteOrder.LITTLE_ENDIAN); FileUtils.writeCompletely(fileChannel, data); fileChannel.position(54); SpilledBufferOrEventSequence seq = new SpilledBufferOrEventSequence(tempFile, fileChannel, buffer, pageSize); seq.open(); seq.cleanup(); assertFalse(fileChannel.isOpen()); assertFalse(tempFile.exists()); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
@After public void cleanupSpiller() throws IOException { if (spiller != null) { spiller.close(); assertFalse(spiller.getCurrentChannel().isOpen()); assertFalse(spiller.getCurrentSpillFile().exists()); } checkNoTempFilesRemain(); }
@Test public void shouldNotCloseChannelUponBufferClose() { buffer = new MappedResizeableBuffer(channel, 0, SIZE); buffer.close(); assertTrue(channel.isOpen()); buffer = null; }