// ... and replace it
final BodyDataSink inBodyChannel = exchange.send(response.getResponseHeader());
//... by a body forward handler
BodyForwarder bodyForwardHandler = new BodyForwarder(orgDataSource, inBodyChannel) {
@Override
public void onData(NonBlockingBodyDataSource bodyDataSource, BodyDataSink bodyDataSink) throws BufferUnderflowException, IOException {
byte[] data = bodyDataSource.readBytesByLength(bodyDataSource.available());
for (int i = 0; i < data.length; i++) {
data[i] = (byte) ((int) data[i] - shift);
}
inBodyChannel.write(data);
inBodyChannel.flush();
}
};
orgDataSource.setDataHandler(bodyForwardHandler);
} else {
exchange.send(response);
}
};
public void onException(IOException ioe) {
};
};
// does request contain a body?
if (exchange.getRequest().hasBody()) {
// get the body
NonBlockingBodyDataSource orgDataSource = exchange.getRequest().getNonBlockingBody();
// ... and replace it ...
final BodyDataSink inBodyChannel = exchange.forward(exchange.getRequest().getRequestHeader(), responseInterceptor);
//... by a body forward handler
BodyForwarder bodyForwardHandler = new BodyForwarder(orgDataSource, inBodyChannel) {
@Override
public void onData(NonBlockingBodyDataSource bodyDataSource, BodyDataSink bodyDataSink) throws BufferUnderflowException, IOException {
byte[] data = bodyDataSource.readBytesByLength(bodyDataSource.available());