congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
ServletOutputStream
Code IndexAdd Tabnine to your IDE (free)

How to use
ServletOutputStream
in
javax.servlet

Best Java code snippets using javax.servlet.ServletOutputStream (Showing top 20 results out of 8,433)

Refine searchRefine arrow

  • HttpServletResponse
  • HttpServletRequest
  • PrintWriter
  • ByteArrayOutputStream
  • InputStream
  • ServletException
  • Enumeration
origin: gocd/gocd

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setHeader("Plugins-Status", status);
    pluginProps.setProperty("Active Mock Bundle 1", "1.1.1");
    pluginProps.setProperty("Active Mock Bundle 2", "2.2.2");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    pluginProps.store(baos, "Go Plugins for Testing");
    resp.getOutputStream().write(baos.toByteArray());
    baos.close();
  }
}
origin: spring-projects/spring-framework

/**
 * Write the given temporary OutputStream to the HTTP response.
 * @param response current HTTP response
 * @param baos the temporary OutputStream to write
 * @throws IOException if writing/flushing failed
 */
protected void writeToResponse(HttpServletResponse response, ByteArrayOutputStream baos) throws IOException {
  // Write content type and also length (determined via byte array).
  response.setContentType(getContentType());
  response.setContentLength(baos.size());
  // Flush byte array to servlet output stream.
  ServletOutputStream out = response.getOutputStream();
  baos.writeTo(out);
  out.flush();
}
origin: javax.servlet/servlet-api

String responseString = "TRACE "+ req.getRequestURI()+
  " " + req.getProtocol();
Enumeration reqHeaderEnum = req.getHeaderNames();
while( reqHeaderEnum.hasMoreElements() ) {
  String headerName = (String)reqHeaderEnum.nextElement();
  responseString += CRLF + headerName + ": " +
  req.getHeader(headerName); 
resp.setContentType("message/http");
resp.setContentLength(responseLength);
ServletOutputStream out = resp.getOutputStream();
out.print(responseString);	
out.close();
return;
origin: spring-projects/spring-framework

private void flush() throws IOException {
  ServletOutputStream outputStream = this.outputStream;
  if (outputStream.isReady()) {
    try {
      outputStream.flush();
      this.flushOnNext = false;
    }
    catch (IOException ex) {
      this.flushOnNext = true;
      throw ex;
    }
  }
  else {
    this.flushOnNext = true;
  }
}
origin: javax.servlet/servlet-api

/**
 * Writes a <code>String</code> to the client, 
 * followed by a carriage return-line feed (CRLF).
 *
 *
 * @param s            the <code>String</code> to write to the client
 *
 * @exception IOException     if an input or output exception occurred
 *
 */
public void println(String s) throws IOException {
print(s);
println();
}
origin: spring-projects/spring-framework

/**
 * Write the DataBuffer to the response body OutputStream.
 * Invoked only when {@link ServletOutputStream#isReady()} returns "true"
 * and the readable bytes in the DataBuffer is greater than 0.
 * @return the number of bytes written
 */
protected int writeToOutputStream(DataBuffer dataBuffer) throws IOException {
  ServletOutputStream outputStream = this.outputStream;
  InputStream input = dataBuffer.asInputStream();
  int bytesWritten = 0;
  byte[] buffer = new byte[this.bufferSize];
  int bytesRead;
  while (outputStream.isReady() && (bytesRead = input.read(buffer)) != -1) {
    outputStream.write(buffer, 0, bytesRead);
    bytesWritten += bytesRead;
  }
  return bytesWritten;
}
origin: AsyncHttpClient/async-http-client

 public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
  Enumeration<?> e = httpRequest.getHeaderNames();
  String param;
  while (e.hasMoreElements()) {
   param = e.nextElement().toString();
   httpResponse.addHeader(param, httpRequest.getHeader(param));
  }
  httpResponse.setStatus(200);
  httpResponse.getOutputStream().flush();
  httpResponse.getOutputStream().close();
 }
}
origin: AsyncHttpClient/async-http-client

   throws IOException {
LOGGER.debug("Echo received request {} on path {}", httpRequest,
    httpRequest.getServletContext().getContextPath());
if (httpRequest.getHeader("X-HEAD") != null) {
 httpResponse.setContentLength(1);
if (httpRequest.getHeader("X-ISO") != null) {
 httpResponse.setContentType(TestUtils.TEXT_HTML_CONTENT_TYPE_WITH_ISO_8859_1_CHARSET);
} else {
 httpResponse.setContentType(TestUtils.TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET);
Enumeration<String> i = httpRequest.getParameterNames();
if (i.hasMoreElements()) {
 StringBuilder requestBody = new StringBuilder();
 while (i.hasMoreElements()) {
  httpResponse.getOutputStream().write(body.getBytes());
final AsyncContext context = httpRequest.startAsync();
final ServletInputStream input = httpRequest.getInputStream();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
origin: AsyncHttpClient/async-http-client

 public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
  Enumeration<?> e = httpRequest.getHeaderNames();
  String param;
  while (e.hasMoreElements()) {
   param = e.nextElement().toString();
   httpResponse.addHeader("X-" + param, httpRequest.getHeader(param));
  }
  int size = 10 * 1024;
  if (httpRequest.getContentLength() > 0) {
   size = httpRequest.getContentLength();
  }
  byte[] bytes = new byte[size];
  if (bytes.length > 0) {
   final InputStream in = httpRequest.getInputStream();
   final OutputStream out = httpResponse.getOutputStream();
   int read;
   while ((read = in.read(bytes)) != -1) {
    out.write(bytes, 0, read);
   }
  }
  httpResponse.setStatus(200);
  httpResponse.getOutputStream().flush();
  httpResponse.getOutputStream().close();
 }
}
origin: loklak/loklak_server

Query post = RemoteAccess.evaluate(request);
if (post.isDoS_blackout()) {  // DoS protection
  response.sendError(503, "your request frequency is too high");
  return;
  response.sendError(503, "a screen_name must be submitted");
  return;
  response.sendError(503, "an id_str must be submitted");
  return;
ByteArrayOutputStream data = new ByteArrayOutputStream();
byte[] b = new byte[2048];
InputStream is = new BufferedInputStream(new FileInputStream(assetFile));
int c;
try {
  while ((c = is.read(b)) >  0) {
    data.write(b, 0, c);
ServletOutputStream sos = response.getOutputStream();
sos.write(data.toByteArray());
origin: AsyncHttpClient/async-http-client

 public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
  if ("POST".equalsIgnoreCase(request.getMethod())) {
   byte[] bytes = new byte[3];
   ByteArrayOutputStream bos = new ByteArrayOutputStream();
   int read = 0;
   while (read > -1) {
    read = request.getInputStream().read(bytes);
    if (read > 0) {
     bos.write(bytes, 0, read);
    }
   }
   response.setStatus(HttpServletResponse.SC_OK);
   response.addHeader("X-Param", new String(bos.toByteArray()));
  } else { // this handler is to handle POST request
   response.sendError(HttpServletResponse.SC_FORBIDDEN);
  }
  response.getOutputStream().flush();
  response.getOutputStream().close();
 }
}
origin: AsyncHttpClient/async-http-client

@Override
protected void handle0(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
 String delay = request.getHeader("X-Delay");
 if (delay != null) {
  try {
   Thread.sleep(Long.parseLong(delay));
  } catch (NumberFormatException | InterruptedException e1) {
   throw new ServletException(e1);
 response.setStatus(200);
 if (request.getMethod().equalsIgnoreCase("OPTIONS")) {
  response.addHeader("Allow", "GET,HEAD,POST,OPTIONS,TRACE");
 response.setContentType(request.getHeader("X-IsoCharset") != null ? TEXT_HTML_CONTENT_TYPE_WITH_ISO_8859_1_CHARSET : TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET);
 response.addHeader("X-ClientPort", String.valueOf(request.getRemotePort()));
 Enumeration<String> headerNames = request.getHeaderNames();
 while (headerNames.hasMoreElements()) {
  String headerName = headerNames.nextElement();
  response.addHeader("X-" + headerName, request.getHeader(headerName));
  response.getOutputStream().write(requestBody.toString().getBytes());
   read = request.getInputStream().read(bytes);
   if (read > 0) {
    response.getOutputStream().write(bytes, 0, read);
origin: loklak/loklak_server

HttpServletResponse response) throws ServletException, IOException {
if (!DAO.writeDump) {
  response.sendError(HttpServletResponse.SC_FORBIDDEN, "Dump generation is disabled on this peer");
String path = request.getPathInfo();
final long now = System.currentTimeMillis();
  response.setContentType("text/html");
  response.setCharacterEncoding("UTF-8");
  response.setStatus(HttpServletResponse.SC_OK);
  response.sendError(404, request.getContextPath() + " " + limitedMessage);
  return;
File dump = ownDumps.size() == 0 ? null : new File(ownDumps.iterator().next().getParentFile(), path);
if (dump == null || !dump.exists()) {
  response.sendError(404, request.getContextPath() + " not available");
  byte[] buffer = new byte[65536];
  int c;
  while ((c = fis.read(buffer)) > 0) {
    response.getOutputStream().write(buffer, 0, c);
  fis.close();
} catch (Throwable e) {
  DAO.severe(e);
origin: opensourceBIM/BIMserver

if (request.getHeader("Authorization") != null) {
  String a = request.getHeader("Authorization");
  if (a.startsWith("Bearer")) {
    token = a.substring(7);
  response.sendError(403, "Token required");
    throw new ServletException("Service \"" + serviceName + "\" not found for this user");
      response.setContentLength(bimBotsOutput.getData().length);
      response.setHeader("Output-Type", bimBotsOutput.getSchemaName());
      response.setHeader("Data-Title", bimBotsOutput.getTitle());
      response.setHeader("Content-Type", bimBotsOutput.getContentType());
        response.setHeader("Context-Id", bimBotsOutput.getContextId());
      response.getOutputStream().write(bimBotsOutput.getData());
      response.setHeader("Output-Type", "Async");
      response.setHeader("Topic-Id", "" + topicKey.getId());
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      IOUtils.copy(inputStream, baos);
      getBimServer().getExecutorService().submit(new BimBotRunner(getBimServer(), new ByteArrayInputStream(baos.toByteArray()), contextId, inputType, authorization, foundService, bimBotsServiceInterface, endPoint.getStreamingSocketInterface(), topicKey.getId(), endPoint.getEndPointId()));
    throw new ServletException("Service \"" + serviceName + "\" does not implement the BimBotsServiceInterface");
origin: jphp-group/jphp

  res.setStatus(404);
  return false;
res.setStatus(200);
res.setContentType(contentType);
res.setContentLengthLong(file.length());
  int bytesRead = inputStream.read(buffer);
  outputStream.write(buffer, 0, bytesRead);
inputStream.close();
outputStream.close();
request.end();
origin: org.jboss.test-jsf/jsf-test-stage

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  InputStream inputStream = getServletContext().getResourceAsStream(req.getPathInfo());
  if(null != inputStream){
    String fileName = req.getServletPath();
    String mimeType = getServletContext().getMimeType(fileName);
    if(null == mimeType){
      mimeType = "text/plain";
    }
    resp.setContentType(mimeType);
    ServletOutputStream outputStream = resp.getOutputStream();
    int c;
    while((c = inputStream.read())>0){
      outputStream.write(c);
    }
    inputStream.close();
    outputStream.close();
  } else {
    resp.sendError(404, "not found");
  }
}

origin: stackoverflow.com

  response.sendError(HttpServletResponse.SC_NOT_FOUND);
  return;
  response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
  return;
long ifModifiedSince = request.getDateHeader("If-Modified-Since");
if (ifNoneMatch == null && ifModifiedSince != -1 && ifModifiedSince + 1000 > lastModified) {
  response.setHeader("ETag", fileName); // Required in 304.
String ifMatch = request.getHeader("If-Match");
if (ifMatch != null && !HttpUtils.matches(ifMatch, fileName)) {
  response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
      logger.info("Return multi part of file : from ({}) to ({})", r.start, r.end);
      sos.println();
      sos.println("--" + MULTIPART_BOUNDARY);
      sos.println("Content-Type: " + contentType);
      sos.println("Content-Range: bytes " + r.start + "-" + r.end + "/" + r.total);
    sos.println();
    sos.println("--" + MULTIPART_BOUNDARY + "--");
    input.skip(start);
    long toRead = length;
origin: alibaba/fastjson

@Override
protected void renderMergedOutputModel(Map<String, Object> model, //
                    HttpServletRequest request, //
                    HttpServletResponse response) throws Exception {
  Object value = filterModel(model);
  String jsonpParameterValue = getJsonpParameterValue(request);
  if(jsonpParameterValue != null) {
    JSONPObject jsonpObject = new JSONPObject(jsonpParameterValue);
    jsonpObject.addParameter(value);
    value = jsonpObject;
  }
  ByteArrayOutputStream outnew = new ByteArrayOutputStream();
  int len = JSON.writeJSONString(outnew, //
      fastJsonConfig.getCharset(), //
      value, //
      fastJsonConfig.getSerializeConfig(), //
      fastJsonConfig.getSerializeFilters(), //
      fastJsonConfig.getDateFormat(), //
      JSON.DEFAULT_GENERATE_FEATURE, //
      fastJsonConfig.getSerializerFeatures());
  if (this.updateContentLength) {
    // Write content length (determined via byte array).
    response.setContentLength(len);
  }
  // Flush byte array to servlet output stream.
  ServletOutputStream out = response.getOutputStream();
  outnew.writeTo(out);
  outnew.close();
  out.flush();
}
origin: stagemonitor/stagemonitor

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
  String requestURI = req.getRequestURI().substring(req.getContextPath().length()).replace("..", "");
  setResponseHeaders(req, res, requestURI);
  InputStream inputStream = null;
  try {
    inputStream = getClass().getClassLoader().getResourceAsStream(StringUtils.removeStart(requestURI, "/"));
    if (inputStream == null) {
      res.sendError(HttpServletResponse.SC_NOT_FOUND);
      return;
    }
    IOUtils.copy(inputStream, res.getOutputStream());
    res.getOutputStream().flush();
    res.flushBuffer();
  } finally {
    try {
      if (inputStream != null) {
        inputStream.close();
      }
    } catch (IOException ioe) {
      // ignore
    }
  }
}
origin: AsyncHttpClient/async-http-client

 public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException {
  try {
   Thread.sleep(20 * 1000);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
  httpResponse.setStatus(200);
  httpResponse.getOutputStream().flush();
  httpResponse.getOutputStream().close();
 }
}
javax.servletServletOutputStream

Javadoc

Provides an output stream for sending binary data to the client. A ServletOutputStream object is normally retrieved via the ServletResponse#getOutputStream method.

This is an abstract class that the servlet container implements. Subclasses of this class must implement the java.io.OutputStream.write(int) method.

Most used methods

  • write
  • flush
  • close
  • print
    Writes a boolean value to the client, with no carriage return-line feed (CRLF) character at the end.
  • println
    Writes a boolean value to the client, followed by a carriage return-line feed (CRLF).
  • setWriteListener
    Instructs the ServletOutputStream to invoke the provided WriteListener when it is possible to write
  • isReady
    This method can be used to determine if data can be written without blocking.
  • <init>
    Does nothing, because this is an abstract class.
  • canWrite

Popular in Java

  • Creating JSON documents from java classes using gson
  • scheduleAtFixedRate (ScheduledExecutorService)
  • onRequestPermissionsResult (Fragment)
  • notifyDataSetChanged (ArrayAdapter)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • FileOutputStream (java.io)
    An output stream that writes bytes to a file. If the output file exists, it can be replaced or appen
  • System (java.lang)
    Provides access to system-related information and resources including standard input and output. Ena
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Reference (javax.naming)
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now