code: public void write(MessageBodyWriterContext context) throws IOException, WebApplicationException {
          Object encoding = context.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING);
  
          if (encoding != null && encoding.toString().equalsIgnoreCase("lzf")) {
              OutputStream old = context.getOutputStream();
              // constructor writes to underlying OS causing headers to be written.
              CommittedLZFOutputStream lzfOutputStream = new CommittedLZFOutputStream(old, null);
  
              // Any content length set will be obsolete
              context.getHeaders().remove("Content-Length");
  
              context.setOutputStream(lzfOutputStream);
              try {
                  context.proceed();
              } finally {
                  if (lzfOutputStream.getLzf() != null) lzfOutputStream.getLzf().flush();
                  context.setOutputStream(old);
              }
              return;
          } else {
              context.proceed();
          }
      }
docs: Grab the outgoing message, if encoding is set to LZF, then wrap the OutputStream in an LZF OutputStream
  before sending it on its merry way, compressing all the time.
  
  Note: strips out the content-length header because the compression changes that unpredictably
  @param context
  @throws IOException
  @throws WebApplicationException