@Override public boolean isOpen() { return channel.isOpen(); }
@Override public boolean isOpen() { return originalChannel.isOpen(); } }
/** * @see ReadableByteChannel#isOpen() */ public boolean isOpen() { return readableByteChannel.isOpen(); }
@Override public boolean isOpen() { return channel.isOpen(); }
@Override public boolean isEndOfInput() throws Exception { if (byteBuffer.position() > 0) { // A previous read was not over, so there is a next chunk in the buffer at least return false; } if (in.isOpen()) { // Try to read a new part, and keep this part (no rewind) int b = in.read(byteBuffer); if (b < 0) { return true; } else { offset += b; return false; } } return true; }
@Override public boolean isEndOfInput() throws Exception { if (byteBuffer.position() > 0) { // A previous read was not over, so there is a next chunk in the buffer at least return false; } if (in.isOpen()) { // Try to read a new part, and keep this part (no rewind) int b = in.read(byteBuffer); if (b < 0) { return true; } else { offset += b; return false; } } return true; }
public boolean hasNextChunk() throws Exception { if (byteBuffer.position() > 0) { // A previous read was not over, so there is a next chunk in the buffer at least return true; } if (in.isOpen()) { // Try to read a new part, and keep this part (no rewind) int b = in.read(byteBuffer); if (b < 0) { return false; } else { offset += b; return true; } } return false; }
public boolean isOpen() { return !invalid && writeChannel.isOpen() && readChannel.isOpen(); }
@Override protected long transferContentTo(WritableByteChannel target) throws IOException { ReadableByteChannel channel = getChannel(); ByteBuffer buffer = getBuffer(); int transferred = 0; int read = channel.read(buffer); if (read > 0) { buffer.flip(); while (buffer.hasRemaining()) { transferred += target.write(buffer); } buffer.compact(); position += transferred; } if (position == getContentLength() || read < 0) { state = MultipartState.POST_CONTENT; if (channel.isOpen()) { channel.close(); } } return transferred; }
@Override public long read(Buffer sink, long byteCount) throws IOException { if (!channel.isOpen()) throw new IllegalStateException("closed"); try (Buffer.UnsafeCursor ignored = sink.readAndWriteUnsafe(cursor)) { timeout.throwIfReached(); long oldSize = sink.size(); int length = (int) Math.min(8192, byteCount); cursor.expandBuffer(length); int read = channel.read(ByteBuffer.wrap(cursor.data, cursor.start, length)); if (read == -1) { cursor.resizeBuffer(oldSize); return -1; } else { cursor.resizeBuffer(oldSize + read); return read; } } }
/** * Does some basic reads from {@code channel}. We execute this against both Okio's channels and * also a standard implementation from the JDK to confirm that their behavior is consistent. */ private void testReadableByteChannel(ReadableByteChannel channel) throws Exception { assertTrue(channel.isOpen()); ByteBuffer byteBuffer = ByteBuffer.allocate(1024); byteBuffer.position(3); byteBuffer.limit(23); int byteCount = channel.read(byteBuffer); assertEquals(20, byteCount); assertEquals(23, byteBuffer.position()); assertEquals(23, byteBuffer.limit()); channel.close(); assertEquals(channel instanceof Buffer, channel.isOpen()); // Buffer.close() does nothing. byteBuffer.flip(); byteBuffer.position(3); byte[] data = new byte[byteBuffer.remaining()]; byteBuffer.get(data); assertEquals("abcdefghijklmnopqrst", new String(data, Charsets.UTF_8)); } }
public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException { checkOpen(); if (!src.isOpen()) { throw new ClosedChannelException();
@Override public boolean isOpen() { return readableChannel.isOpen(); }
public boolean isOpen() { return wrapped.isOpen(); }
@Override public void close() throws IOException { try { super.close(); } finally { if (channel.isOpen()) { channel.close(); } } } }
@Override public boolean isEndOfInput() throws Exception { if (byteBuffer.position() > 0) { // A previous read was not over, so there is a next chunk in the buffer at least return false; } if (in.isOpen()) { // Try to read a new part, and keep this part (no rewind) int b = in.read(byteBuffer); if (b < 0) { return true; } else { offset += b; return false; } } return true; }
/** * The reader will close itself right after reading the CRS from the prj file, so no actual need * to call it explicitly anymore. * * @throws IOException */ public void close() throws IOException { if (buffer != null) { NIOUtilities.clean(buffer); // will close if a MappedByteBuffer buffer = null; } if (channel.isOpen()) { channel.close(); } } }
/** * Clean up all resources associated with this reader.<B>Highly recomended.</B> * * @throws IOException If an error occurs. */ public void close() throws IOException { if (channel != null && channel.isOpen()) { channel.close(); streamLogger.close(); } if (buffer != null) { NIOUtilities.clean(buffer, useMemoryMappedBuffer); } buffer = null; channel = null; bytes = null; header = null; row = null; }
/** * Clean up any resources. Closes the channel. * * @throws IOException If errors occur while closing the channel. */ public void close() throws IOException { // don't throw NPE on double close if (channel == null) return; try { if (channel.isOpen()) { channel.close(); streamLogger.close(); } NIOUtilities.clean(buffer, useMemoryMappedBuffer); } finally { if (shxReader != null) shxReader.close(); } shxReader = null; channel = null; header = null; }
public void close() throws IOException { if (channel.isOpen()) { channel.close(); } }