public void terminateWrites() throws IOException { final long val = enterShutdown(); if (anyAreSet(val, MASK_COUNT) && !broken) { UndertowLogger.REQUEST_IO_LOGGER.debugf("Fixed length stream closed with with %s bytes remaining", val & MASK_COUNT); try { next.truncateWrites(); } finally { if (!anyAreSet(state, FLAG_FINISHED_CALLED)) { state |= FLAG_FINISHED_CALLED; channelFinished(); } } } else if (allAreSet(config, CONF_FLAG_PASS_CLOSE)) { next.terminateWrites(); } }
public boolean flush() throws IOException { long val = state; if (anyAreSet(val, FLAG_CLOSE_COMPLETE)) { return true; } boolean flushed = false; try { return flushed = next.flush(); } catch (IOException | RuntimeException | Error e) { broken = true; throw e; } finally { exitFlush(val, flushed); } }
public int write(final ByteBuffer src) throws IOException { long val = state; final long remaining = val & MASK_COUNT; if (!src.hasRemaining()) { return 0; } if (allAreSet(val, FLAG_CLOSE_REQUESTED)) { throw new ClosedChannelException(); } int oldLimit = src.limit(); if (remaining == 0) { throw new FixedLengthOverflowException(); } else if (src.remaining() > remaining) { src.limit((int) (src.position() + remaining)); } int res = 0; try { return res = next.write(src); } catch (IOException | RuntimeException | Error e) { broken = true; throw e; } finally { src.limit(oldLimit); exitWrite(val, (long) res); } }
@Override public void truncateWrites() throws IOException { try { if (!anyAreSet(state, FLAG_FINISHED_CALLED)) { state |= FLAG_FINISHED_CALLED; channelFinished(); } } finally { super.truncateWrites(); } }
void reset(long contentLength, HttpServerExchange exchange) { this.exchange = exchange; super.reset(contentLength, !exchange.isPersistent()); }
public long transferFrom(final FileChannel src, final long position, final long count) throws IOException { if (count == 0L) return 0L; long val = state; if (allAreSet(val, FLAG_CLOSE_REQUESTED)) { throw new ClosedChannelException(); } if (allAreClear(val, MASK_COUNT)) { throw new FixedLengthOverflowException(); } long res = 0L; try { return res = next.transferFrom(src, position, min(count, (val & MASK_COUNT))); } catch (IOException | RuntimeException | Error e) { broken = true; throw e; } finally { exitWrite(val, res); } }
private void exitFlush(long oldVal, boolean flushed) { long newVal = oldVal; boolean callFinish = false; if ((anyAreSet(oldVal, FLAG_CLOSE_REQUESTED) || (newVal & MASK_COUNT) == 0L) && flushed) { newVal |= FLAG_CLOSE_COMPLETE; if (!anyAreSet(oldVal, FLAG_FINISHED_CALLED) && (newVal & MASK_COUNT) == 0L) { newVal |= FLAG_FINISHED_CALLED; callFinish = true; } state = newVal; if (callFinish) { channelFinished(); } } }
void reset(long contentLength, HttpServerExchange exchange) { this.exchange = exchange; super.reset(contentLength, !exchange.isPersistent()); }
public void terminateWrites() throws IOException { final long val = enterShutdown(); if (anyAreSet(val, MASK_COUNT) && !broken) { UndertowLogger.REQUEST_IO_LOGGER.debugf("Fixed length stream closed with with %s bytes remaining", val & MASK_COUNT); try { next.truncateWrites(); } finally { if (!anyAreSet(state, FLAG_FINISHED_CALLED)) { state |= FLAG_FINISHED_CALLED; channelFinished(); } } } else if (allAreSet(config, CONF_FLAG_PASS_CLOSE)) { next.terminateWrites(); } }
public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException { if (count == 0L) return 0L; long val = state; if (allAreSet(val, FLAG_CLOSE_REQUESTED)) { throw new ClosedChannelException(); } if (allAreClear(val, MASK_COUNT)) { throw new FixedLengthOverflowException(); } long res = 0L; try { return res = next.transferFrom(source, min(count, (val & MASK_COUNT)), throughBuffer); } catch (IOException | RuntimeException | Error e) { broken = true; throw e; } finally { exitWrite(val, res); } }
@Override public void truncateWrites() throws IOException { try { if (!anyAreSet(state, FLAG_FINISHED_CALLED)) { state |= FLAG_FINISHED_CALLED; channelFinished(); } } finally { super.truncateWrites(); } }
void reset(long contentLength, HttpServerExchange exchange) { this.exchange = exchange; super.reset(contentLength, !exchange.isPersistent()); }
public boolean flush() throws IOException { long val = state; if (anyAreSet(val, FLAG_CLOSE_COMPLETE)) { return true; } boolean flushed = false; try { return flushed = next.flush(); } catch (IOException | RuntimeException | Error e) { broken = true; throw e; } finally { exitFlush(val, flushed); } }
public void terminateWrites() throws IOException { final long val = enterShutdown(); if (anyAreSet(val, MASK_COUNT) && !broken) { UndertowLogger.REQUEST_IO_LOGGER.debugf("Fixed length stream closed with with %s bytes remaining", val & MASK_COUNT); try { next.truncateWrites(); } finally { if (!anyAreSet(state, FLAG_FINISHED_CALLED)) { state |= FLAG_FINISHED_CALLED; channelFinished(); } } } else if (allAreSet(config, CONF_FLAG_PASS_CLOSE)) { next.terminateWrites(); } }
public int write(final ByteBuffer src) throws IOException { long val = state; final long remaining = val & MASK_COUNT; if (!src.hasRemaining()) { return 0; } if (allAreSet(val, FLAG_CLOSE_REQUESTED)) { throw new ClosedChannelException(); } int oldLimit = src.limit(); if (remaining == 0) { throw new FixedLengthOverflowException(); } else if (src.remaining() > remaining) { src.limit((int) (src.position() + remaining)); } int res = 0; try { return res = next.write(src); } catch (IOException | RuntimeException | Error e) { broken = true; throw e; } finally { src.limit(oldLimit); exitWrite(val, (long) res); } }
@Override public void truncateWrites() throws IOException { try { if (!anyAreSet(state, FLAG_FINISHED_CALLED)) { state |= FLAG_FINISHED_CALLED; channelFinished(); } } finally { super.truncateWrites(); } }
public boolean flush() throws IOException { long val = state; if (anyAreSet(val, FLAG_CLOSE_COMPLETE)) { return true; } boolean flushed = false; try { return flushed = next.flush(); } catch (IOException | RuntimeException | Error e) { broken = true; throw e; } finally { exitFlush(val, flushed); } }