From: Luigi B. <fi...@us...> - 2004-09-13 10:41:39
|
Update of /cvsroot/exist/eXist-1.0/src/org/exist/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18400/src/org/exist/source Modified Files: CocoonSource.java Log Message: https://sourceforge.net/tracker/index.php?func=detail&aid=1019695&group_id=17691&atid=117691 org.exist.source.CocoonSource.getContent() throws NPE if the underlying InputSource cannot report its getContentLength(). For example, when initialized with an org.apache.excalibur.source.Source, which can legitimately report -1 for getContentLength() if the length is unknown a priori, then the CocoonSource.getContent() fails when trying to construct the outgoing ByteArrayOutputStream(source.getContentLength()). This commit fixes the problem. Index: CocoonSource.java =================================================================== RCS file: /cvsroot/exist/eXist-1.0/src/org/exist/source/CocoonSource.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** CocoonSource.java 17 May 2004 09:50:29 -0000 1.1 --- CocoonSource.java 13 Sep 2004 10:41:29 -0000 1.2 *************** *** 89,101 **** public String getContent() throws IOException { ! ByteArrayOutputStream os = new ByteArrayOutputStream((int) inputSource ! .getContentLength()); ! byte[] t = new byte[512]; ! InputStream is = inputSource.getInputStream(); ! int count = 0; ! while ((count = is.read(t)) != -1) { ! os.write(t, 0, count); ! } ! return os.toString("UTF-8"); } --- 89,107 ---- public String getContent() throws IOException { ! int len = (int) inputSource.getContentLength(); ! ! ByteArrayOutputStream os; ! if (len == -1) ! os = new ByteArrayOutputStream(); ! else ! os = new ByteArrayOutputStream(len); ! ! byte[] t = new byte[512]; ! InputStream is = inputSource.getInputStream(); ! int count = 0; ! while ((count = is.read(t)) != -1) { ! os.write(t, 0, count); ! } ! return os.toString("UTF-8"); } |