@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo(); final int code = statusInfo.getStatusCode(); final String reason = statusInfo.getReasonPhrase() == null ? HttpStatus.getMessage(code) : statusInfo.getReasonPhrase(); response.setStatusWithReason(code, reason); if (contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { response.addHeader(e.getKey(), value); } } try { return response.getOutputStream(); } catch (final IOException ioe) { throw new ContainerException("Error during writing out the response headers.", ioe); } }
public ActionImpl implements Action { public Response get(Request request) { Response response = request.newResponse(OK); response.getOutputStream().write("body"); return response; } }
public boolean closeIfAllContentWritten(long written) throws IOException { if (_contentLength >= 0 && written >= _contentLength) { switch (_outputType) { case WRITER: _writer.close(); break; case STREAM: getOutputStream().close(); } return true; } return false; }
public boolean closeIfAllContentWritten(long written) throws IOException { if (_contentLength >= 0 && written >= _contentLength) { switch (_outputType) { case WRITER: _writer.close(); break; case STREAM: getOutputStream().close(); } return true; } return false; }
/** * Returns the response stream if it exists. * * @return The response stream if it exists. */ @Override public OutputStream getResponseEntityStream() { try { return getConnection().getResponse().getOutputStream(); } catch (IOException e) { getLogger().log(Level.WARNING, "Unable to get response entity stream", e); return null; } }
public void closeOutput() throws IOException { switch (_outputType) { case WRITER: _writer.close(); if (!_out.isClosed()) _out.close(); break; case STREAM: getOutputStream().close(); break; default: _out.close(); } }
public void closeOutput() throws IOException { switch (_outputType) { case WRITER: _writer.close(); if (!_out.isClosed()) _out.close(); break; case STREAM: getOutputStream().close(); break; default: _out.close(); } }
public void closeOutput() throws IOException { switch (_outputType) { case WRITER: _writer.close(); if (!_out.isClosed()) _out.close(); break; case STREAM: getOutputStream().close(); break; default: _out.close(); } }
public void setContentLength(int len) { // Protect from setting after committed as default handling // of a servlet HEAD request ALWAYS sets _content length, even // if the getHandling committed the response! if (isCommitted() || _connection.isIncluding()) return; _connection._generator.setContentLength(len); if (len>0) { _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len); if (_connection._generator.isAllContentWritten()) { if (_outputState==WRITER) _writer.close(); else if (_outputState==STREAM) { try { getOutputStream().close(); } catch(IOException e) { throw new RuntimeException(e); } } } } }
public void setContentLength(int len) { // Protect from setting after committed as default handling // of a servlet HEAD request ALWAYS sets _content length, even // if the getHandling committed the response! if (isCommitted() || _connection.isIncluding()) return; _connection._generator.setContentLength(len); if (len>0) { _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len); if (_connection._generator.isAllContentWritten()) { if (_outputState==WRITER) _writer.close(); else if (_outputState==STREAM) { try { getOutputStream().close(); } catch(IOException e) { throw new RuntimeException(e); } } } } }
public void setContentLength(int len) { // Protect from setting after committed as default handling // of a servlet HEAD request ALWAYS sets _content length, even // if the getHandling committed the response! if (isCommitted() || _connection.isIncluding()) return; _connection._generator.setContentLength(len); if (len>0) { _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len); if (_connection._generator.isAllContentWritten()) { if (_outputState==WRITER) _writer.close(); else if (_outputState==STREAM) { try { getOutputStream().close(); } catch(IOException e) { throw new RuntimeException(e); } } } } }
public void setContentLength(int len) { // Protect from setting after committed as default handling // of a servlet HEAD request ALWAYS sets _content length, even // if the getHandling committed the response! if (isCommitted() || _connection.isIncluding()) return; _connection._generator.setContentLength(len); if (len>0) { _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len); if (_connection._generator.isAllContentWritten()) { if (_outputState==WRITER) _writer.close(); else if (_outputState==STREAM) { try { getOutputStream().close(); } catch(IOException e) { throw new RuntimeException(e); } } } } }
public void setContentLength(int len) { // Protect from setting after committed as default handling // of a servlet HEAD request ALWAYS sets _content length, even // if the getHandling committed the response! if (isCommitted() || _connection.isIncluding()) return; _connection._generator.setContentLength(len); if (len>0) { _connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len); if (_connection._generator.isAllContentWritten()) { if (_outputState==WRITER) _writer.close(); else if (_outputState==STREAM) { try { getOutputStream().close(); } catch(IOException e) { throw new RuntimeException(e); } } } } }
public void closeOutput() throws IOException { switch (_outputType) { case WRITER: _writer.close(); if (!_out.isClosed()) _out.close(); break; case STREAM: if (!_out.isClosed()) getOutputStream().close(); break; default: if (!_out.isClosed()) _out.close(); } }
try (ServletOutputStream outputStream = getOutputStream())
writer.writeTo(getOutputStream()); writer.destroy();
writer.writeTo(getOutputStream()); writer.destroy();
writer.writeTo(getOutputStream()); writer.destroy();
writer.writeTo(getOutputStream()); writer.destroy();
writer.writeTo(getOutputStream()); writer.destroy();