Java Code Examples for io.undertow.server.HttpServerExchange#allocateBuffer()
The following examples show how to use
io.undertow.server.HttpServerExchange#allocateBuffer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: URLResource.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public void serveBlocking(final OutputStream sender, final HttpServerExchange exchange) throws IOException { ByteBuf buffer = exchange.allocateBuffer(false); try (InputStream in = url.openStream()) { int r; while ((r = in.read(buffer.array(), buffer.arrayOffset(), buffer.writableBytes())) > 0) { sender.write(buffer.array(), buffer.arrayOffset(), r); } } finally { buffer.release(); } }
Example 2
Source File: URLResource.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public void serveRangeBlocking(OutputStream sender, HttpServerExchange exchange, long start, long end) throws IOException { ByteBuf buffer = exchange.allocateBuffer(false); int pos = 0; try (InputStream in = url.openStream()) { int r; while ((r = in.read(buffer.array(), buffer.arrayOffset(), buffer.writableBytes())) > 0) { int sw, ew; if (pos < start) { int toEat = (int) (start - pos); if (toEat > r) { sw = -1; } else { sw = toEat; } } else { sw = 0; } int rem = (int) (end - Math.max(pos, start)) + 1; if (rem <= 0) { sender.close(); return; } else if (r > rem) { ew = rem; } else { ew = r; } if (sw != -1) { sender.write(buffer.array(), buffer.arrayOffset() + sw, ew); } pos += r; } sender.close(); } finally { buffer.release(); } }
Example 3
Source File: PathResource.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public void serveBlocking(final OutputStream sender, final HttpServerExchange exchange) throws IOException { ByteBuf buffer = exchange.allocateBuffer(false); try (InputStream in = Files.newInputStream(file)) { int r; while ((r = in.read(buffer.array(), buffer.arrayOffset(), buffer.writableBytes())) > 0) { sender.write(buffer.array(), buffer.arrayOffset(), r); } sender.close(); } finally { buffer.release(); } }
Example 4
Source File: PathResource.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public void serveRangeBlocking(OutputStream sender, HttpServerExchange exchange, long start, long end) throws IOException { ByteBuf buffer = exchange.allocateBuffer(false); int pos = 0; try (InputStream in = Files.newInputStream(file)) { int r; while ((r = in.read(buffer.array(), buffer.arrayOffset(), buffer.writableBytes())) > 0) { int sw, ew; if (pos < start) { int toEat = (int) (start - pos); if (toEat > r) { sw = -1; } else { sw = toEat; } } else { sw = 0; } int rem = (int) (end - Math.max(pos, start)) + 1; if (rem <= 0) { sender.close(); return; } else if (r > rem) { ew = rem; } else { ew = r; } if (sw != -1) { sender.write(buffer.array(), buffer.arrayOffset() + sw, ew); } pos += r; } } finally { buffer.release(); } }