use of java.nio.channels.ClosedChannelException in project netty by netty.
the class HttpObjectAggregatorTest method testOversizedRequest.
@Test
public void testOversizedRequest() {
EmbeddedChannel embedder = new EmbeddedChannel(new HttpObjectAggregator(4));
HttpRequest message = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.PUT, "http://localhost");
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("test", CharsetUtil.US_ASCII));
HttpContent chunk2 = new DefaultHttpContent(Unpooled.copiedBuffer("test2", CharsetUtil.US_ASCII));
HttpContent chunk3 = LastHttpContent.EMPTY_LAST_CONTENT;
assertFalse(embedder.writeInbound(message));
assertFalse(embedder.writeInbound(chunk1));
assertFalse(embedder.writeInbound(chunk2));
FullHttpResponse response = embedder.readOutbound();
assertEquals(HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE, response.status());
assertEquals("0", response.headers().get(HttpHeaderNames.CONTENT_LENGTH));
assertFalse(embedder.isOpen());
try {
assertFalse(embedder.writeInbound(chunk3));
fail();
} catch (Exception e) {
assertTrue(e instanceof ClosedChannelException);
}
assertFalse(embedder.finish());
}
use of java.nio.channels.ClosedChannelException in project XobotOS by xamarin.
the class FileChannelImpl method transferFrom.
public long transferFrom(ReadableByteChannel src, long position, long count) throws IOException {
checkOpen();
if (!src.isOpen()) {
throw new ClosedChannelException();
}
checkWritable();
if (position < 0 || count < 0 || count > Integer.MAX_VALUE) {
throw new IllegalArgumentException("position=" + position + " count=" + count);
}
if (position > size()) {
return 0;
}
// so the mmap(2) overhead isn't a concern.
if (src instanceof FileChannel) {
FileChannel fileSrc = (FileChannel) src;
long size = fileSrc.size();
long filePosition = fileSrc.position();
count = Math.min(count, size - filePosition);
ByteBuffer buffer = fileSrc.map(MapMode.READ_ONLY, filePosition, count);
try {
fileSrc.position(filePosition + count);
return write(buffer, position);
} finally {
NioUtils.freeDirectBuffer(buffer);
}
}
// For non-file channels, all we can do is read and write via userspace.
ByteBuffer buffer = ByteBuffer.allocate((int) count);
src.read(buffer);
buffer.flip();
return write(buffer, position);
}
use of java.nio.channels.ClosedChannelException in project XobotOS by xamarin.
the class SocketChannelImpl method finishConnect.
@Override
public boolean finishConnect() throws IOException {
synchronized (this) {
if (!isOpen()) {
throw new ClosedChannelException();
}
if (status == SOCKET_STATUS_CONNECTED) {
return true;
}
if (status != SOCKET_STATUS_PENDING) {
throw new NoConnectionPendingException();
}
}
boolean finished = false;
try {
begin();
InetAddress inetAddress = connectAddress.getAddress();
int port = connectAddress.getPort();
// Return immediately.
finished = IoBridge.isConnected(fd, inetAddress, port, 0, 0);
isBound = finished;
} catch (ConnectException e) {
if (isOpen()) {
close();
finished = true;
}
throw e;
} finally {
end(finished);
}
synchronized (this) {
status = (finished ? SOCKET_STATUS_CONNECTED : status);
isBound = finished;
}
return finished;
}
use of java.nio.channels.ClosedChannelException in project voltdb by VoltDB.
the class PooledUnsafeDirectByteBuf method setBytes.
@Override
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
checkIndex(index, length);
ByteBuffer tmpBuf = internalNioBuffer();
index = idx(index);
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpBuf);
} catch (ClosedChannelException ignored) {
return -1;
}
}
use of java.nio.channels.ClosedChannelException in project voltdb by VoltDB.
the class UnpooledUnsafeDirectByteBuf method setBytes.
@Override
public int setBytes(int index, ScatteringByteChannel in, int length) throws IOException {
ensureAccessible();
ByteBuffer tmpBuf = internalNioBuffer();
tmpBuf.clear().position(index).limit(index + length);
try {
return in.read(tmpBuf);
} catch (ClosedChannelException ignored) {
return -1;
}
}
Aggregations