当前位置: 首页>>代码示例>>Java>>正文


Java ServletOutputStream.write方法代码示例

本文整理汇总了Java中javax.servlet.ServletOutputStream.write方法的典型用法代码示例。如果您正苦于以下问题:Java ServletOutputStream.write方法的具体用法?Java ServletOutputStream.write怎么用?Java ServletOutputStream.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.servlet.ServletOutputStream的用法示例。


在下文中一共展示了ServletOutputStream.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOutputStream

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@Override
public ServletOutputStream getOutputStream() throws IOException {

  final ServletOutputStream outputStream = d.getOutputStream();
  return new ServletOutputStream() {

    @Override
    public void write(int b) throws IOException {
      respBody.write(b);
      outputStream.write(b);
    }

    @Override
    public void setWriteListener(WriteListener writeListener) {
      outputStream.setWriteListener(writeListener);
    }

    @Override
    public boolean isReady() {
      return outputStream.isReady();
    }
  };
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:24,代码来源:AccessLogFilter.java

示例2: copyRange

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
 * Copy the contents of the specified input stream to the specified
 * output stream, and ensure that both streams are closed before returning
 * (even in the face of an exception).
 *
 * @param istream The input stream to read from
 * @param ostream The output stream to write to
 * @return Exception which occurred during processing
 */
protected IOException copyRange(InputStream istream,
                              ServletOutputStream ostream) {

    // Copy the input stream to the output stream
    IOException exception = null;
    byte buffer[] = new byte[input];
    int len = buffer.length;
    while (true) {
        try {
            len = istream.read(buffer);
            if (len == -1)
                break;
            ostream.write(buffer, 0, len);
        } catch (IOException e) {
            exception = e;
            len = -1;
            break;
        }
    }
    return exception;

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:32,代码来源:DefaultServlet.java

示例3: copyRange

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
 * Copy the contents of the specified input stream to the specified output
 * stream, and ensure that both streams are closed before returning (even in
 * the face of an exception).
 *
 * @param istream
 *            The input stream to read from
 * @param ostream
 *            The output stream to write to
 * @return Exception which occurred during processing
 */
protected IOException copyRange(InputStream istream, ServletOutputStream ostream) {

	// Copy the input stream to the output stream
	IOException exception = null;
	byte buffer[] = new byte[input];
	int len = buffer.length;
	while (true) {
		try {
			len = istream.read(buffer);
			if (len == -1)
				break;
			ostream.write(buffer, 0, len);
		} catch (IOException e) {
			exception = e;
			len = -1;
			break;
		}
	}
	return exception;

}
 
开发者ID:how2j,项目名称:lazycat,代码行数:33,代码来源:DefaultServlet.java

示例4: copyRange

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
 * Copy the contents of the specified input stream to the specified
 * output stream, and ensure that both streams are closed before returning
 * (even in the face of an exception).
 *
 * @param istream The input stream to read from
 * @param ostream The output stream to write to
 * @return Exception which occurred during processing
 */
private IOException copyRange(InputStream istream,
                              ServletOutputStream ostream) {

    // Copy the input stream to the output stream
    IOException exception = null;
    byte buffer[] = new byte[input];
    int len = buffer.length;
    while (true) {
        try {
            len = istream.read(buffer);
            if (len == -1)
                break;
            ostream.write(buffer, 0, len);
        } catch (IOException e) {
            exception = e;
            len = -1;
            break;
        }
    }
    return exception;

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:32,代码来源:DefaultServlet.java

示例5: doGet

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Center center = ApplicationContextHelper.getBean(Constant.CENTERS_BEAN_NAME, Centers.class)
            .getCenterBySessionId(req.getParameter("sessionId"));
    ServletOutputStream out = resp.getOutputStream();
    try {
        // hex to bytes
        byte[] bytes = CoderUtils.hexStringToByteArray(req.getParameter("data"));
        // 解密
        String text = new String(RsaUtils.decryptByPublicKey(bytes, center.getPublicKey()));
        // 通过name选取方法并调用
        Object result = invokeMethodByName(req.getParameter("name"), text);
        byte[] respData = JSON.toJSONString(result).getBytes("utf-8");
        if (respData.length > center.getLength() - Constant.RSA_RESERVED_LENGTH) {
            throw new Exception("response data is too big");
        }
        // 返回加密
        respData = RsaUtils.encryptByPublicKey(respData, center.getPublicKey());
        out.write(respData);
    } catch (Exception e) {
        e.printStackTrace();
        out.write(500);
    } finally {
        out.close();
    }
}
 
开发者ID:cwdtom,项目名称:hermes-java,代码行数:27,代码来源:HermesServlet.java

示例6: getNullImage

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@RequestMapping(value = "/webservice1_0bs/multimediaImage/null", method = RequestMethod.GET)
@ResponseBody
public void getNullImage(HttpServletResponse response) {
	try {
		byte[] b = new byte[0];
		InputStream i = App.retGlobalResource("/src/main/ui/no_image_icon.png").openStream();
		response.setHeader("Cache-Control", "no-store");
		response.setHeader("Pragma", "no-cache");
		response.setDateHeader("Expires", 0);
		response.setContentType("image/" + "png");
		ServletOutputStream responseOutputStream = response.getOutputStream();
		byte[] bytes = new byte[1024];
		int read = 0;
		while ((read = i.read(bytes)) != -1) {
			responseOutputStream.write(bytes, 0, read);
		}

		responseOutputStream.flush();
		responseOutputStream.close();
	} catch (IOException e1) {
		log.error(e1);
		try {
			response.sendError(HttpServletResponse.SC_NOT_FOUND);
		} catch (Exception e) {
			log.error(e);
		}
	}
}
 
开发者ID:ForJ-Latech,项目名称:fwm,代码行数:29,代码来源:Webservice1_0BSController.java

示例7: doGet

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    ServletOutputStream out = resp.getOutputStream();
    Spider s=new GithubCrawler().createSpider();
    SpiderManager.get().add(s);
    out.write(("add spider of "+s.getName()).getBytes());
    out.flush();
    out.close();
}
 
开发者ID:xbynet,项目名称:crawler,代码行数:11,代码来源:HelloServlet.java

示例8: copy

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
 * Copy the contents of the specified input stream to the specified
 * output stream, and ensure that both streams are closed before returning
 * (even in the face of an exception).
 *
 * @param cacheEntry The cache entry for the source resource
 * @param is The input stream to read the source resource from
 * @param ostream The output stream to write to
 *
 * @exception IOException if an input/output error occurs
 */
protected void copy(CacheEntry cacheEntry, InputStream is,
                  ServletOutputStream ostream)
    throws IOException {

    IOException exception = null;
    InputStream resourceInputStream = null;

    // Optimization: If the binary content has already been loaded, send
    // it directly
    if (cacheEntry.resource != null) {
        byte buffer[] = cacheEntry.resource.getContent();
        if (buffer != null) {
            ostream.write(buffer, 0, buffer.length);
            return;
        }
        resourceInputStream = cacheEntry.resource.streamContent();
    } else {
        resourceInputStream = is;
    }

    InputStream istream = new BufferedInputStream
        (resourceInputStream, input);

    // Copy the input stream to the output stream
    exception = copyRange(istream, ostream);

    // Clean up the input stream
    istream.close();

    // Rethrow any exception that has occurred
    if (exception != null)
        throw exception;

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:46,代码来源:DefaultServlet.java

示例9: execute

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
public String execute() throws Exception {
		HttpServletRequest request = Struts2Utils.getRequest();
		HttpServletResponse response = Struts2Utils.getResponse();
        ByteArrayOutputStream out = null;
        byte[] captchaChallengeAsJpeg = null;  
        // the output stream to render the captcha image as jpeg into  
        ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();  
        try {  
            // get the session id that will identify the generated captcha.  
            // the same id must be used to validate the response, the session id  
            // is a good candidate!  
            String captchaId = request.getSession().getId();  
            // call the ImageCaptchaService getChallenge method  
            BufferedImage challenge = imageCaptchaService.getImageChallengeForID(captchaId, request.getLocale());
            // a jpeg encoder
/*** jdk1.7之后默认不支持了 **/
//            JPEGImageEncoder jpegEncoder = JPEGCodec.createJPEGEncoder(jpegOutputStream);
//            jpegEncoder.encode(challenge);

//            换成新版图片api
            ImageIO.write(challenge, "jpg", jpegOutputStream);

        } catch (Exception e) {  
            // TODO Auto-generated catch block  
            e.printStackTrace();  
        }
        captchaChallengeAsJpeg = jpegOutputStream.toByteArray();    
        // flush it in the response    
        response.setHeader("Cache-Control", "no-store");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setContentType("image/jpeg");
        ServletOutputStream responseOutputStream = response.getOutputStream();
        responseOutputStream.write(captchaChallengeAsJpeg);
        responseOutputStream.flush();
        responseOutputStream.close();
        return null;
	}
 
开发者ID:wkeyuan,项目名称:DWSurvey,代码行数:39,代码来源:JcaptchaAction.java

示例10: exportFileByNIO

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
 * @description 文件下载 nio 大缓存
 * @param response
 * @param file
 * @throws IOException
 */
public static void exportFileByNIO(HttpServletResponse response, File file) throws IOException {
    String filename = URLEncoder.encode(file.getName(), CharEncoding.UTF_8);
    response.setContentType(HttpUtil.CONTENT_TYPE_APPLICATION_OCTET_STREAM);
    response.setContentLength((int) file.length());
    response.setHeader(HttpUtil.CONTENT_DISPOSITION, "attachment;filename=" + filename);
    response.setHeader(HttpUtil.LOCATION, filename);
    ServletOutputStream op = response.getOutputStream();
    int bufferSize = 1024 * 128;
    FileInputStream fileInputStream = new FileInputStream(file.getPath());
    FileChannel fileChannel = fileInputStream.getChannel();
    ByteBuffer bb = ByteBuffer.allocateDirect(1024 * 1024 * 128);
    byte[] buffer = new byte[bufferSize];
    int nRead, nGet;
    while ((nRead = fileChannel.read(bb)) != -1) {
        if (nRead == 0) {
            continue;
        }
        bb.position(0);
        bb.limit(nRead);
        while (bb.hasRemaining()) {
            nGet = Math.min(bb.remaining(), bufferSize);
            bb.get(buffer, 0, nGet);
            op.write(buffer);
        }
        bb.clear();
    }
    fileChannel.close();
    fileInputStream.close();
}
 
开发者ID:tong12580,项目名称:OutsourcedProject,代码行数:36,代码来源:FileManagementUtil.java

示例11: writeOutputStream

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
private void writeOutputStream(InputStream in, ServletOutputStream out) throws IOException {
    int length;
    byte[] bytes = new byte[512];

    while ((length = in.read(bytes)) != -1) {
        out.write(bytes, 0, length);
        out.flush();
    }
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:10,代码来源:ForwarderServlet.java

示例12: copy

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
/**
 * Copy the contents of the specified input stream to the specified
 * output stream, and ensure that both streams are closed before returning
 * (even in the face of an exception).
 *
 * @param resourceInfo The resource information
 * @param ostream The output stream to write to
 *
 * @exception IOException if an input/output error occurs
 */
protected void copy(CacheEntry cacheEntry, InputStream is,
                  ServletOutputStream ostream)
    throws IOException {

    IOException exception = null;
    InputStream resourceInputStream = null;

    // Optimization: If the binary content has already been loaded, send
    // it directly
    if (cacheEntry.resource != null) {
        byte buffer[] = cacheEntry.resource.getContent();
        if (buffer != null) {
            ostream.write(buffer, 0, buffer.length);
            return;
        }
        resourceInputStream = cacheEntry.resource.streamContent();
    } else {
        resourceInputStream = is;
    }

    InputStream istream = new BufferedInputStream
        (resourceInputStream, input);

    // Copy the input stream to the output stream
    exception = copyRange(istream, ostream);

    // Clean up the input stream
    istream.close();

    // Rethrow any exception that has occurred
    if (exception != null)
        throw exception;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:45,代码来源:DefaultServlet.java

示例13: sendData

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
@Override
public IoFuture<Void> sendData(final ByteBuffer data) {
    try {
        final ServletOutputStream outputStream = response.getOutputStream();
        while (data.hasRemaining()) {
            outputStream.write(data.get());
        }
        return new FinishedIoFuture<>(null);
    } catch (IOException e) {
        final FutureResult<Void> ioFuture = new FutureResult<>();
        ioFuture.setException(e);
        return ioFuture.getIoFuture();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:ServletWebSocketHttpExchange.java

示例14: writeBodyBytes

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
private void writeBodyBytes(byte[] bytes) {
  try {
    headerContentLength(bytes.length);
    ServletOutputStream out = response.getOutputStream();
    out.write(bytes);
    out.flush();
  } catch (IOException e) {
    throw new RuntimeException("Couldn't send body: "+e.getMessage(), e);
  }
}
 
开发者ID:rockscript,项目名称:rockscript,代码行数:11,代码来源:ServerResponse.java

示例15: contextInitialized

import javax.servlet.ServletOutputStream; //导入方法依赖的package包/类
public void contextInitialized(ServletContextEvent sce) {
  Map<String, AsyncContext> notificationStreams = new ConcurrentHashMap<String, AsyncContext>();
  sce.getServletContext().setAttribute("notificationStreams", notificationStreams);
  Thread thread = new Thread(new Runnable(){

@Override
public void run() {
	String clientId = null;
	AsyncContext asyncContext = null;
	while(true)
	   {
		   try {
			   Map.Entry<String, String> entry = blockingQueue.take();
			   clientId = entry.getKey();
			   asyncContext = notificationStreams.get(clientId);
			   if(notificationStreams.get(entry.getKey()) != null){
				   ServletOutputStream out = asyncContext.getResponse().getOutputStream();
				   out.write(entry.getValue().getBytes());
				   out.flush();
				   asyncContext.getResponse().flushBuffer();
			   }
		   } catch (Exception e){
			   ErrorLog.logError("Cannot write to client",	e.getStackTrace());
			   asyncContext.complete();
			   notificationStreams.remove(clientId);
			   break;
		   }
	   }
}

  });
  thread.start();

 }
 
开发者ID:opendaylight,项目名称:fpc,代码行数:35,代码来源:NotificationService.java


注:本文中的javax.servlet.ServletOutputStream.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。