@Override public StreamSinkConduit wrap(final ConduitFactory<StreamSinkConduit> factory, final HttpServerExchange exchange) { UndertowLogger.REQUEST_LOGGER.tracef("Created DEFLATE response conduit for %s", exchange); return new DeflatingStreamSinkConduit(factory, exchange, deflaterPool); } };
return next.flush(); } else { if (!performFlushIfRequired()) { return false; deflateData(false); if (allAreClear(state, WRITTEN_TRAILER)) { state |= WRITTEN_TRAILER; byte[] data = getTrailer(); if (data != null) { Connectors.updateResponseBytesSent(exchange, data.length); if (next == null) { nextCreated = true; this.next = createNextChannel(); if (performFlushIfRequired()) { state |= NEXT_SHUTDOWN; freeBuffer(); next.terminateWrites(); return next.flush(); if (next == null) { nextCreated = true; this.next = createNextChannel(); deflateData(true); if(allAreClear(state, FLUSHING_BUFFER)) {
@Override public void run() { if (writeReadyHandler != null) { try { writeReadyHandler.writeReady(); } finally { //if writes are still resumed queue up another one if (next == null && isWriteResumed()) { queueWriteListener(); } } } } });
@Override public long write(final ByteBuffer[] srcs, final int offset, final int length) throws IOException { if (anyAreSet(state, SHUTDOWN | CLOSED) || currentBuffer == null) { throw new ClosedChannelException(); } try { int total = 0; for (int i = offset; i < offset + length; ++i) { if (srcs[i].hasRemaining()) { int ret = write(srcs[i]); total += ret; if (ret == 0) { return total; } } } return total; } catch (IOException | RuntimeException | Error e) { freeBuffer(); throw e; } }
if (!performFlushIfRequired()) { return 0; deflateData(false); if (!deflater.needsInput()) { return 0; preDeflate(data); deflater.setInput(data); Connectors.updateResponseBytesSent(exchange, 0 - data.length); deflateData(false); return data.length; } catch (IOException | RuntimeException | Error e) { freeBuffer(); throw e;
if (next == null) { nextCreated = true; this.next = createNextChannel(); if (!performFlushIfRequired()) { return;
public DeflateEncodingProvider(int deflateLevel) { this(DeflatingStreamSinkConduit.newInstanceDeflaterPool(deflateLevel)); }
@Override public long transferFrom(final FileChannel src, final long position, final long count) throws IOException { if (anyAreSet(state, SHUTDOWN | CLOSED)) { throw new ClosedChannelException(); } if (!performFlushIfRequired()) { return 0; } return src.transferTo(position, count, new ConduitWritableByteChannel(this)); }
@Override public void resumeWrites() { if (next == null) { state |= WRITES_RESUMED; queueWriteListener(); } else { next.resumeWrites(); } }
@Override public void truncateWrites() throws IOException { freeBuffer(); state |= CLOSED; next.truncateWrites(); }
if (!performFlushIfRequired()) { return 0; deflateData(false); if (!deflater.needsInput()) { return 0; preDeflate(data); deflater.setInput(data); Connectors.updateResponseBytesSent(exchange, 0 - data.length); deflateData(false); return data.length; } catch (IOException | RuntimeException | Error e) { freeBuffer(); throw e;
@Override public long write(final ByteBuffer[] srcs, final int offset, final int length) throws IOException { if (anyAreSet(state, SHUTDOWN | CLOSED) || currentBuffer == null) { throw new ClosedChannelException(); } try { int total = 0; for (int i = offset; i < offset + length; ++i) { if (srcs[i].hasRemaining()) { int ret = write(srcs[i]); total += ret; if (ret == 0) { return total; } } } return total; } catch (IOException | RuntimeException | Error e) { freeBuffer(); throw e; } }
if (next == null) { nextCreated = true; this.next = createNextChannel(); if (!performFlushIfRequired()) { return;
public DeflatingStreamSinkConduit(final ConduitFactory<StreamSinkConduit> conduitFactory, final HttpServerExchange exchange, int deflateLevel) { this(conduitFactory, exchange, newInstanceDeflaterPool(deflateLevel)); }
@Override public long transferFrom(final StreamSourceChannel source, final long count, final ByteBuffer throughBuffer) throws IOException { if (anyAreSet(state, SHUTDOWN | CLOSED)) { throw new ClosedChannelException(); } if (!performFlushIfRequired()) { return 0; } return IoUtils.transfer(source, count, throughBuffer, new ConduitWritableByteChannel(this)); }
@Override public void resumeWrites() { if (next == null) { state |= WRITES_RESUMED; queueWriteListener(); } else { next.resumeWrites(); } }
@Override public void truncateWrites() throws IOException { freeBuffer(); state |= CLOSED; next.truncateWrites(); }
return next.flush(); } else { if (!performFlushIfRequired()) { return false; deflateData(false); if (allAreClear(state, WRITTEN_TRAILER)) { state |= WRITTEN_TRAILER; byte[] data = getTrailer(); if (data != null) { Connectors.updateResponseBytesSent(exchange, data.length); if (next == null) { nextCreated = true; this.next = createNextChannel(); if (performFlushIfRequired()) { state |= NEXT_SHUTDOWN; freeBuffer(); next.terminateWrites(); return next.flush(); if (next == null) { nextCreated = true; this.next = createNextChannel(); deflateData(true); if(allAreClear(state, FLUSHING_BUFFER)) {
if (!performFlushIfRequired()) { return 0; deflateData(false); if (!deflater.needsInput()) { return 0; preDeflate(data); deflater.setInput(data); Connectors.updateResponseBytesSent(exchange, 0 - data.length); deflateData(false); return data.length; } catch (IOException | RuntimeException | Error e) { freeBuffer(); throw e;
@Override public long write(final ByteBuffer[] srcs, final int offset, final int length) throws IOException { if (anyAreSet(state, SHUTDOWN | CLOSED) || currentBuffer == null) { throw new ClosedChannelException(); } try { int total = 0; for (int i = offset; i < offset + length; ++i) { if (srcs[i].hasRemaining()) { int ret = write(srcs[i]); total += ret; if (ret == 0) { return total; } } } return total; } catch (IOException | RuntimeException | Error e) { freeBuffer(); throw e; } }