ArrayIndexOutOfBoundsException: 16384

最近突然发现自己的系统在输出字符串的时候出现下标越界的错误,如下:

java.lang.ArrayIndexOutOfBoundsException: 16384

at com.caucho.vfs.i18n.UTF8Writer.write(UTF8Writer.java:143)

at com.caucho.server.connection.ToByteResponseStream.flushCharBuffer(ToByteResponseStream.java:476)

at com.caucho.server.connection.ToByteResponseStream.nextCharBuffer(ToByteResponseStream.java:461)

at com.caucho.server.connection.ResponseWriter.write(ResponseWriter.java:144)

at com.caucho.vfs.AbstractPrintWriter.print(AbstractPrintWriter.java:210)

at cn.joy.action.BaseAction.outPrint(BaseAction.java:207)

at cn.joy.action.CommentsAction.commentsList(CommentsAction.java:70)

跟踪代码发现输出字符串的时候用的PrintWriter 对的print方法

HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
		} catch (IOException e) {

		}
		String result = message;

		if (out != null) {
			out.print(result);
			out.flush();
			out.close();
		}

最后测试发现当web服务器为tomcat的时候该问题不会出现,所以自己推断该问题与不同web服务器对PrintWriter的实现不同有关系,所以最后采用直接输出字节流的形式解决该问题:

HttpServletResponse response = ServletActionContext.getResponse();
		//response.setContentType("text/html;charset=utf-8");
		response.setContentType("application/json;charset=utf-8");
		ServletOutputStream out = null;
		try {
			//out = response.getWriter();
			response.setCharacterEncoding("utf-8");
			out = response.getOutputStream();
			if (out != null){
				out.write(message.getBytes("utf-8"));
				out.flush();
			}
		} catch (Exception e) {
            log.error(e.getMessage(), e);
		}finally{
			try {
				if (out != null) {
				    out.close();
				}
			} catch (IOException e) {
				log.error(e.getMessage(), e);
			}
		}

希望对大家有帮助

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-09 09:55:17

ArrayIndexOutOfBoundsException: 16384的相关文章

java.lang.ArrayIndexOutOfBoundsException

1.错误描述 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at com.you.model.Args.main(Args.java:18) 2.错误原因 /** * */ package com.you.model; /** * @author YHD * */ public class Args { /** * @param args */ public static void main

ArrayIndexOutOfBoundsException

dos窗口编译java文件:javac xxx.java dos窗口运行class文件:java xxx /** * @author liangyadong * @date 2016年9月27日 下午9:34:51 * @version 1.0 * * 演示ArrayIndexOutOfBoundsException * * 编译时并不出错,运行时才会报数组角标越界异常! */ public class Array { public static void main(String[] args)

java.lang.ArrayIndexOutOfBoundsException: 2

1.错误描述 java.lang.ArrayIndexOutOfBoundsException: 2 at report.service.impl.ExportServiceImpl$7.setSheetValue(ExportServiceImpl.java:2649) at utils.ExcelUtil.getWorkbook(ExcelUtil.java:45) at report.service.impl.ExportServiceImpl.exportStation(ExportSe

java.lang.ArrayIndexOutOfBoundsException: 100

在用SaxParser做XML解析的时候碰到如下错误信息: java.lang.ArrayIndexOutOfBoundsException: 100         at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.scanLiteral(XMLEntityScanner.java:1145)         at com.sun.org.apache.xerces.internal.impl.XMLScanner.scan

AndroidStudio编译出现Caused by: java.lang.ArrayIndexOutOfBoundsException: 4其中一种的原因

Caused by: java.lang.ArrayIndexOutOfBoundsException: 4 at com.android.tools.profiler.asm.ClassReader.a(Unknown Source) at com.android.tools.profiler.asm.ClassReader.a(Unknown Source) at com.android.tools.profiler.asm.ClassReader.a(Unknown Source) at

android listview Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3

android listview 适配器在多种类型viewType报错: Caused by: java.lang.ArrayIndexOutOfBoundsException: length=3; index=3 2 at android.widget.AbsListView$RecycleBin.addScrapView(AbsListView.java:6822) 3 at android.widget.AbsListView.trackMotionScroll(AbsListView.j

Oracle executeBatch异常:ArrayIndexOutOfBoundsException

原文地址:http://yanwushu.sinaapp.com/oracle_executebatch_arrayindexoutofboundsexception/ 使用jdbc接口PreparedStatement.executeBatch()向oracle中批量执行sql时候,出现异常ArrayIndexOutOfBoundsException,具体信息如下: java.lang.ArrayIndexOutOfBoundsException: -32413 at oracle.jdbc.

WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while reading XML data错误

原文:WCF服务接口多,客户端在引用时出错!报WCF The maximum nametable character count quota (16384) has been exceeded while reading XML data错误 在服务端中定义接口太多时,在客户端的服务引用时,报错误: 元数据包含无法解析的引用:“net.tcp://localhost:8081/BaseData/mex”.    XML 文档中有错误.    读取 XML 数据时,超出最大名称表字符计数配额 (1

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1

场景:eclipse中编写java中用到数组 问题: 程序不报错但是运行过程中 终止,显示字样 “ Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 ” 截图: 原因: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException 这句话表示异常出现在main这个线程里面,错误是java.lang.Ar