Hi,
there is a serious bug in NodeRevisionContent.
The stream returned by NodesRevisionContent.streamContent() should be used
only once, if the was set in NodeRevisionContent.setContent(InputStream
inputStream)
However it will be used more often:
1) in most implementations of ContentInterceptor.preStoreContent
2) when storeing the content
3) in most implementations of ContentInterceptor.postStoreContent
Only the first read will be successfull.
The second read will result in a exception like this:
==============
java.io.IOException: Stream closed
at
org.apache.coyote.tomcat4.CoyoteInputStream.read(CoyoteInputStream.java:148)
at
org.apache.coyote.tomcat4.CoyoteInputStream.read(CoyoteInputStream.java:139)
at
org.apache.slide.content.NodeRevisionContent.readFromStream(NodeRevisionContent.java:349)
at
org.apache.slide.content.NodeRevisionContent.getContent(NodeRevisionContent.java:144)
at
de.vs_c.slide.content.LuceneContentInterceptor.postStoreContent(LuceneContentInterceptor.java:68)
at
org.apache.slide.content.ContentImpl.invokeInterceptors(ContentImpl.java:1341)
at org.apache.slide.content.ContentImpl.create(ContentImpl.java:643)
at
org.apache.slide.webdav.method.PutMethod.executeRequest(PutMethod.java:267)
at
org.apache.slide.webdav.method.AbstractWebdavMethod.run(AbstractWebdavMethod.java:323)
at org.apache.slide.webdav.WebdavServlet.service(WebdavServlet.java:230)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
===============
Unless the concept of ContentInterceptos is cancelled, the
NodeRevisionContent must keep a copy of the content.
I have attached a patch, which fixes the bug at the price of lower speed and
higher memory consumption.
Martin
Index: NodeRevisionContent.java
===================================================================
RCS file: /home/cvspublic/jakarta-slide/src/share/org/apache/slide/content/NodeRevisionContent.java,v
retrieving revision 1.10
diff -u -r1.10 NodeRevisionContent.java
--- NodeRevisionContent.java 25 Apr 2002 21:30:13 -0000 1.10
+++ NodeRevisionContent.java 30 Jul 2002 12:01:25 -0000
@@ -92,22 +92,9 @@
/**
* Content.
*/
- private char[] content = null;
private byte[] contentBytes = null;
- /**
- * Reader.
- */
- private transient Reader reader = null;
-
-
- /**
- * Input stream.
- */
- private transient InputStream inputStream = null;
-
-
// ------------------------------------------------------------- Properties
@@ -118,81 +105,21 @@
*/
public char[] getContent() {
char[] result = null;
- if (content != null) {
- result = content;
- inputStream = null;
- reader = null;
- }
- else if (reader != null) {
- try {
- content = readFromReader(reader);
- } catch (IOException e) {
- e.printStackTrace();
- }
- result = content;
- inputStream = null;
- reader = null;
- }
- else if (contentBytes != null) {
- content = new String(contentBytes).toCharArray();
- result = content;
- inputStream = null;
- reader = null;
- }
- else if (inputStream != null) {
- try {
- contentBytes = readFromStream(inputStream);
- } catch (IOException e) {
- e.printStackTrace();
- }
- content = new String(contentBytes).toCharArray();
- result = content;
- inputStream = null;
- reader = null;
- }
+
+ if (contentBytes != null) {
+ result = new String(contentBytes).toCharArray();
+ }
+
return result;
}
/**
* Content accessor.
*
- * @return char[] Content
+ * @return byte[] Content
*/
public byte[] getContentBytes() {
- byte[] result = null;
- if (contentBytes != null) {
- result = contentBytes;
- inputStream = null;
- reader = null;
- }
- else if (inputStream != null) {
- try {
- contentBytes = readFromStream(inputStream);
- } catch (IOException e) {
- e.printStackTrace();
- }
- result = contentBytes;
- inputStream = null;
- reader = null;
- }
- else if (content != null) {
- contentBytes = new String(content).getBytes();
- result = contentBytes;
- inputStream = null;
- reader = null;
- }
- else if (reader != null) {
- try {
- content = readFromReader(reader);
- } catch (IOException e) {
- e.printStackTrace();
- }
- contentBytes = new String(content).getBytes();
- result = contentBytes;
- inputStream = null;
- reader = null;
- }
- return result;
+ return contentBytes;
}
@@ -205,23 +132,8 @@
public Reader readContent()
throws IOException {
Reader result = null;
- if (reader != null) {
- result = reader;
- inputStream = null;
- }
- else if (content != null) {
- result = new CharArrayReader(content);
- inputStream = null;
- reader = null;
- }
- else if (inputStream != null) {
- result = new InputStreamReader(inputStream);
- reader = null;
- }
- else if (contentBytes != null) {
+ if (contentBytes != null) {
result = new CharArrayReader(new String(contentBytes).toCharArray());
- inputStream = null;
- reader = null;
}
return result;
}
@@ -235,27 +147,9 @@
public InputStream streamContent()
throws IOException {
InputStream result = null;
- if (inputStream != null) {
- result = inputStream;
- content = null;
- reader = null;
- }
- else if (contentBytes != null) {
+ if (contentBytes != null) {
result = new ByteArrayInputStream( contentBytes );
- reader = null;
- inputStream = null;
- }
-// else if( reader != null ) {
-// result = ???;
-// inputStream = null;
-// }
- else if (content != null) {
-// Class StringBufferInputStream is deprecated !!
-// result = new StringBufferInputStream(new String(content));
- result = new ByteArrayInputStream( new String(content).getBytes() );
- reader = null;
- inputStream = null;
- }
+ }
return result;
}
@@ -266,10 +160,7 @@
* @param content New content
*/
public void setContent(byte[] contentBytes) {
- this.contentBytes = contentBytes;
- this.reader = null;
- this.inputStream = null;
- this.content = null;
+ this.contentBytes = contentBytes;
}
/**
@@ -278,10 +169,8 @@
* @param content New content
*/
public void setContent(char[] content) {
- this.content = content;
- this.reader = null;
- this.inputStream = null;
- this.contentBytes = null;
+ contentBytes = new String(content).getBytes();
+
}
@@ -291,10 +180,13 @@
* @param reader New reader
*/
public void setContent(Reader reader) {
- this.reader = reader;
- this.inputStream = null;
- this.content = null;
- this.contentBytes = null;
+ try {
+ char content[] = readFromReader(reader);
+ contentBytes = new String(content).getBytes();
+ } catch (IOException ie) {
+ contentBytes = null;
+ ie.printStackTrace();
+ }
}
@@ -304,10 +196,12 @@
* @param inputStream New input stream
*/
public void setContent(InputStream inputStream) {
- this.inputStream = inputStream;
- this.reader = null;
- this.content = null;
- this.contentBytes = null;
+ try {
+ contentBytes = readFromStream(inputStream);
+ } catch (IOException ie) {
+ contentBytes = null;
+ ie.printStackTrace();
+ }
}
@@ -319,7 +213,7 @@
*/
public void validate() {
- if ((content == null) && (contentBytes == null) && (reader == null) && (inputStream == null))
+ if (contentBytes == null)
throw new ObjectValidationFailedException
(Messages.message
(NodeRevisionContent.class.getName() + ".noContent"));
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>