Author: nbelaevski
Date: 2008-11-06 11:13:31 -0500 (Thu, 06 Nov 2008)
New Revision: 11046
Added:
trunk/framework/impl/src/test/java/org/ajax4jsf/io/parser/FastBufferOutputStreamTest.java
trunk/framework/impl/src/test/java/org/ajax4jsf/io/parser/FastBufferWriterTest.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java
trunk/framework/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java
trunk/framework/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java
trunk/framework/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java
Log:
Reset methods implemented for FastBufferOutputStream and FastWriter
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java 2008-11-06 13:58:51
UTC (rev 11045)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java 2008-11-06 16:13:31
UTC (rev 11046)
@@ -205,4 +205,13 @@
return new CharBuffer(s.toCharArray());
}
+ /**
+ * Resets this byte buffer to empty state
+ * @since 3.3.0
+ */
+ public void reset() {
+ usedSize = 0;
+ next = null;
+ prev = null;
+ }
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java 2008-11-06 13:58:51
UTC (rev 11045)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java 2008-11-06 16:13:31
UTC (rev 11046)
@@ -208,4 +208,13 @@
return new ByteBuffer(bs);
}
+ /**
+ * Resets this char buffer to empty state
+ * @since 3.3.0
+ */
+ public void reset() {
+ usedSize = 0;
+ next = null;
+ prev = null;
+ }
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java 2008-11-06
13:58:51 UTC (rev 11045)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java 2008-11-06
16:13:31 UTC (rev 11046)
@@ -204,4 +204,15 @@
return new FastBufferWriter(first);
}
+ /**
+ * Resets stream to empty state
+ *
+ * @since 3.3.0
+ */
+ public void reset() {
+ this.firstBuffer.reset();
+ this.lastBuffer = this.firstBuffer;
+
+ this.length = 0;
+ }
}
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java 2008-11-06
13:58:51 UTC (rev 11045)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java 2008-11-06
16:13:31 UTC (rev 11046)
@@ -78,6 +78,7 @@
*/
public void write(int c) throws IOException {
lastBuffer = lastBuffer.append((char)c);
+ length++;
}
/**
@@ -132,7 +133,7 @@
public void flush() throws IOException {
}
-
+
/**
* Writes all data written up to the moment to string buffer.
* @param out
@@ -212,5 +213,16 @@
}
return new FastBufferOutputStream(first);
}
+
+ /**
+ * Resets writer to empty state
+ *
+ * @since 3.3.0
+ */
+ public void reset() {
+ this.firstBuffer.reset();
+ this.lastBuffer = this.firstBuffer;
+ this.length = 0;
+ }
}
Added:
trunk/framework/impl/src/test/java/org/ajax4jsf/io/parser/FastBufferOutputStreamTest.java
===================================================================
---
trunk/framework/impl/src/test/java/org/ajax4jsf/io/parser/FastBufferOutputStreamTest.java
(rev 0)
+++
trunk/framework/impl/src/test/java/org/ajax4jsf/io/parser/FastBufferOutputStreamTest.java 2008-11-06
16:13:31 UTC (rev 11046)
@@ -0,0 +1,82 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io.parser;
+
+import junit.framework.TestCase;
+
+import org.ajax4jsf.io.ByteBuffer;
+import org.ajax4jsf.io.FastBufferOutputStream;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+
+public class FastBufferOutputStreamTest extends TestCase {
+
+ /**
+ * Test method for {@link org.ajax4jsf.io.FastBufferOutputStream#reset()}.
+ */
+ public void testResetOneBuffer() throws Exception {
+ FastBufferOutputStream stream = new FastBufferOutputStream(256);
+ for (int i = 0; i < 255; i++) {
+ stream.write(i);
+ }
+
+ assertEquals(255, stream.getLength());
+ ByteBuffer firstBuffer = stream.getFirstBuffer();
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+
+ stream.reset();
+
+ assertEquals(0, stream.getLength());
+ firstBuffer = stream.getFirstBuffer();
+ assertEquals(0, firstBuffer.getUsedSize());
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.io.FastBufferOutputStream#reset()}.
+ */
+ public void testResetTwoBuffers() throws Exception {
+ FastBufferOutputStream stream = new FastBufferOutputStream(256);
+ for (int i = 0; i < 257; i++) {
+ stream.write(i);
+ }
+
+ assertEquals(257, stream.getLength());
+ ByteBuffer firstBuffer = stream.getFirstBuffer();
+ assertNotNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+
+ stream.reset();
+
+ assertEquals(0, stream.getLength());
+ firstBuffer = stream.getFirstBuffer();
+ assertEquals(0, firstBuffer.getUsedSize());
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ }
+
+}
Added:
trunk/framework/impl/src/test/java/org/ajax4jsf/io/parser/FastBufferWriterTest.java
===================================================================
--- trunk/framework/impl/src/test/java/org/ajax4jsf/io/parser/FastBufferWriterTest.java
(rev 0)
+++
trunk/framework/impl/src/test/java/org/ajax4jsf/io/parser/FastBufferWriterTest.java 2008-11-06
16:13:31 UTC (rev 11046)
@@ -0,0 +1,82 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.io.parser;
+
+import junit.framework.TestCase;
+
+import org.ajax4jsf.io.CharBuffer;
+import org.ajax4jsf.io.FastBufferWriter;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.0
+ */
+
+public class FastBufferWriterTest extends TestCase {
+
+ /**
+ * Test method for {@link org.ajax4jsf.io.FastBufferWriter#reset()}.
+ */
+ public void testResetOneBuffer() throws Exception {
+ FastBufferWriter stream = new FastBufferWriter(256);
+ for (int i = 0; i < 255; i++) {
+ stream.write(i);
+ }
+
+ assertEquals(255, stream.getLength());
+ CharBuffer firstBuffer = stream.getFirstBuffer();
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+
+ stream.reset();
+
+ assertEquals(0, stream.getLength());
+ firstBuffer = stream.getFirstBuffer();
+ assertEquals(0, firstBuffer.getUsedSize());
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ }
+
+ /**
+ * Test method for {@link org.ajax4jsf.io.FastBufferWriter#reset()}.
+ */
+ public void testResetTwoBuffers() throws Exception {
+ FastBufferWriter stream = new FastBufferWriter(256);
+ for (int i = 0; i < 257; i++) {
+ stream.write(i);
+ }
+
+ assertEquals(257, stream.getLength());
+ CharBuffer firstBuffer = stream.getFirstBuffer();
+ assertNotNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+
+ stream.reset();
+
+ assertEquals(0, stream.getLength());
+ firstBuffer = stream.getFirstBuffer();
+ assertEquals(0, firstBuffer.getUsedSize());
+ assertNull(firstBuffer.getNext());
+ assertNull(firstBuffer.getPrevious());
+ }
+
+}