Author: nbelaevski
Date: 2011-04-21 08:16:50 -0400 (Thu, 21 Apr 2011)
New Revision: 22435
Added:
trunk/core/api/src/main/java/org/ajax4jsf/io/
trunk/core/api/src/main/java/org/ajax4jsf/io/ByteBuffer.java
trunk/core/api/src/main/java/org/ajax4jsf/io/CharBuffer.java
trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java
trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java
trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferReader.java
trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferWriter.java
trunk/core/api/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java
trunk/core/api/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java
trunk/core/api/src/main/java/org/ajax4jsf/io/package-info.java
trunk/core/api/src/test/java/org/ajax4jsf/io/
trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java
trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java
trunk/core/api/src/test/java/org/ajax4jsf/io/Test.java
Removed:
trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java
trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java
trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java
trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java
trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java
Modified:
trunk/core/api/src/test/java/org/richfaces/log/JavaLoggerTest.java
trunk/core/api/src/test/java/org/richfaces/util/LRUMapTest.java
trunk/core/impl/src/test/java/org/richfaces/cache/JBossCacheTest.java
trunk/core/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java
Log:
RF-10128
Checkstyle fixes
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/ByteBuffer.java (from rev 22426,
trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/ByteBuffer.java
(rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/ByteBuffer.java 2011-04-21 12:16:50 UTC
(rev 22435)
@@ -0,0 +1,276 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * A single link in chain of byte arrays.
+ *
+ * @author glory
+ */
+public class ByteBuffer {
+ private static final int MAX_WASTE = 16384;
+
+ /**
+ * Stored bytes
+ */
+ private byte[] bytes;
+
+ /**
+ * Length of byte array.
+ */
+ private int cacheSize;
+ private ByteBuffer next;
+ private ByteBuffer prev;
+
+ /**
+ * Number of bytes stored in the array.
+ */
+ private int usedSize;
+
+ /**
+ * Creates instance of ByteBuffer already filled by bytes.
+ *
+ * @param bytes
+ */
+ public ByteBuffer(byte[] bytes) {
+ this.bytes = bytes;
+ usedSize = bytes.length;
+ cacheSize = usedSize;
+ }
+
+ /**
+ * Creates instance of ByteBuffer with byte array of required length.
+ *
+ * @param cacheSize length of byte array
+ */
+ public ByteBuffer(int cacheSize) {
+ bytes = new byte[cacheSize];
+ this.cacheSize = cacheSize;
+ usedSize = 0;
+ }
+
+ /**
+ * Appends byte to array if there are unfilled positions in it.
+ * Otherwize creates next link in the chain, and appends the byte to it.
+ *
+ * @param c
+ * @return instance of ByteBuffer to which byte was appended.
+ */
+ public ByteBuffer append(byte c) {
+ if (next != null) {
+ return next.append(c);
+ }
+
+ if (usedSize < cacheSize) {
+ bytes[usedSize] = c;
+ usedSize++;
+
+ return this;
+ } else {
+ next = new ByteBuffer(cacheSize * 2);
+ next.prev = this;
+
+ return next.append(c);
+ }
+ }
+
+ /**
+ * Appends segment of a byte array to array if there are unfilled positions in it.
+ * Otherwize creates next link in the chain, and appends data to it.
+ *
+ * @param c
+ * @return instance of ByteBuffer to which byte array was appended.
+ */
+ public ByteBuffer append(byte[] bs, int off, int len) {
+ if (next != null) {
+ return next.append(bs, off, len);
+ }
+
+ if (len + usedSize <= cacheSize) {
+ System.arraycopy(bs, off, bytes, usedSize, len);
+ usedSize += len;
+
+ return this;
+ }
+
+ int av = cacheSize - usedSize;
+
+ if (av > 0) {
+ System.arraycopy(bs, off, bytes, usedSize, av);
+ usedSize += av;
+ off += av;
+ len -= av;
+ }
+
+ next = new ByteBuffer(cacheSize * 2);
+ next.prev = this;
+
+ return next.append(bs, off, len);
+ }
+
+ /**
+ * Returns stored byte array.
+ *
+ * @return stored byte array
+ */
+ public byte[] getBytes() {
+ return bytes;
+ }
+
+ /**
+ * Returns byte at index. No check is fulfilled to provide high speed.
+ *
+ * @param index
+ * @return
+ */
+ public byte getByteAt(int index) {
+ return bytes[index];
+ }
+
+ /**
+ * Returns actual number of byte stored in this link.
+ *
+ * @return
+ */
+ public int getUsedSize() {
+ return usedSize;
+ }
+
+ /**
+ * Returns capacity of this link.
+ *
+ * @return
+ */
+ public int getCacheSize() {
+ return cacheSize;
+ }
+
+ /**
+ * Returns total number of bytes stored in this link and all its predecessors.
+ *
+ * @return
+ */
+ public int getTotalSize() {
+ return (prev == null) ? usedSize : prev.getTotalSize() + usedSize;
+ }
+
+ /**
+ * Returns the previous link in the chain.
+ *
+ * @return
+ */
+ public ByteBuffer getPrevious() {
+ return prev;
+ }
+
+ /**
+ * Returns the next link in the chain.
+ *
+ * @return
+ */
+ public ByteBuffer getNext() {
+ return next;
+ }
+
+ /**
+ * Sets the next link in the chain.
+ *
+ * @param b
+ */
+ public void setNext(ByteBuffer b) {
+ next = b;
+
+ if (b != null) {
+ b.prev = this;
+ }
+ }
+
+ /**
+ * Transforms this instance to instance of CharBuffer (a link of chain of char
arrays).
+ *
+ * @param encoding
+ * @return link of chain of char arrays
+ * @throws UnsupportedEncodingException
+ */
+ public CharBuffer toCharBuffer(String encoding) throws UnsupportedEncodingException
{
+ String s;
+
+ if (null != encoding) {
+ s = new String(bytes, 0, usedSize, encoding);
+ } else {
+ s = new String(bytes, 0, usedSize);
+ }
+
+ return new CharBuffer(s.toCharArray());
+ }
+
+ /**
+ * Transforms this instance to instance of CharBuffer (a link of chain of char
arrays).
+ *
+ * @return link of chain of char arrays
+ */
+ public CharBuffer toCharBuffer() {
+ String s = new String(bytes, 0, usedSize);
+
+ 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;
+ }
+
+ /**
+ * @since 4.0
+ */
+ public void compact() {
+ if (bytes.length - usedSize > MAX_WASTE) {
+ byte[] bs = new byte[usedSize];
+
+ System.arraycopy(bytes, 0, bs, 0, usedSize);
+ this.bytes = bs;
+ this.cacheSize = bs.length;
+ }
+
+ if (next != null) {
+ next.compact();
+ }
+ }
+
+ public ByteBuffer getLast() {
+ ByteBuffer result = this;
+
+ while (result.next != null) {
+ result = result.next;
+ }
+
+ return result;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/CharBuffer.java (from rev 22426,
trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/CharBuffer.java
(rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/CharBuffer.java 2011-04-21 12:16:50 UTC
(rev 22435)
@@ -0,0 +1,266 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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;
+
+import java.io.UnsupportedEncodingException;
+
+/**
+ * A single link in chain of char arrays.
+ *
+ * @author glory
+ */
+public class CharBuffer {
+ private static final int MAX_WASTE = 16384;
+ private static final int MIN_CACHE_SIZE = 64;
+
+ /**
+ * Length of char array.
+ */
+ private int cacheSize;
+
+ /**
+ * Stored characters
+ */
+ private char[] chars;
+ private CharBuffer next;
+ private CharBuffer prev;
+
+ /**
+ * number of characters stored in the array.
+ */
+ private int usedSize;
+
+ /**
+ * Creates instance of CharBuffer already filled by chars.
+ *
+ * @param bytes
+ */
+ public CharBuffer(char[] chars) {
+ this.chars = chars;
+ usedSize = chars.length;
+ cacheSize = usedSize;
+ }
+
+ /**
+ * Creates instance of CharBuffer with char array of required length.
+ *
+ * @param cacheSize length of char array
+ */
+ public CharBuffer(int cacheSize) {
+ if (cacheSize < MIN_CACHE_SIZE) {
+ this.cacheSize = MIN_CACHE_SIZE;
+ } else {
+ this.cacheSize = cacheSize;
+ }
+
+ chars = new char[this.cacheSize];
+ usedSize = 0;
+ }
+
+ /**
+ * Appends character to array chars if there are unfilled positions in it.
+ * Otherwise creates next link in the chain, and appends the character to it.
+ *
+ * @param c
+ * @return instance of CharBuffer to which character was appended.
+ */
+ public CharBuffer append(char c) {
+ if (next != null) {
+ return next.append(c);
+ }
+
+ if (usedSize < cacheSize) {
+ chars[usedSize] = c;
+ usedSize++;
+
+ return this;
+ } else {
+ next = new CharBuffer(cacheSize * 2);
+ next.prev = this;
+
+ return next.append(c);
+ }
+ }
+
+ /**
+ * Appends segment of a char array to array if there are unfilled positions in it.
+ * Otherwise creates next link in the chain, and appends data to it.
+ *
+ * @param c
+ * @return instance of CharBuffer to which char array was appended.
+ */
+ public CharBuffer append(char[] cs, int off, int len) {
+ if (next != null) {
+ return next.append(cs, off, len);
+ }
+
+ if (len + usedSize <= cacheSize) {
+ System.arraycopy(cs, off, chars, usedSize, len);
+ usedSize += len;
+
+ return this;
+ }
+
+ int av = cacheSize - usedSize;
+
+ if (av > 0) {
+ System.arraycopy(cs, off, chars, usedSize, av);
+ usedSize += av;
+ off += av;
+ len -= av;
+ }
+
+ next = new CharBuffer(cacheSize * 2);
+ next.prev = this;
+
+ return next.append(cs, off, len);
+ }
+
+ /**
+ * Returns stored char array.
+ *
+ * @return stored char array
+ */
+ public char[] getChars() {
+ return chars;
+ }
+
+ /**
+ * Returns character at index. No check is fulfilled to provide high speed.
+ *
+ * @param index
+ * @return
+ */
+ public char getCharAt(int index) {
+ return chars[index];
+ }
+
+ /**
+ * Returns actual number of characters stored in this link.
+ *
+ * @return
+ */
+ public int getUsedSize() {
+ return usedSize;
+ }
+
+ /**
+ * Returns capacity of this link.
+ *
+ * @return
+ */
+ public int getCacheSize() {
+ return cacheSize;
+ }
+
+ /**
+ * Returns total number of characters stored in this link and all its predecessors.
+ *
+ * @return
+ */
+ public int getTotalSize() {
+ return (prev == null) ? usedSize : prev.getTotalSize() + usedSize;
+ }
+
+ /**
+ * Returns the previous link in the chain.
+ *
+ * @return
+ */
+ public CharBuffer getPrevious() {
+ return prev;
+ }
+
+ /**
+ * Returns the next link in the chain.
+ *
+ * @return
+ */
+ public CharBuffer getNext() {
+ return next;
+ }
+
+ /**
+ * Sets the next link in the chain.
+ *
+ * @param b
+ */
+ public void setNext(CharBuffer b) {
+ next = b;
+
+ if (b != null) {
+ b.prev = this;
+ }
+ }
+
+ /**
+ * Transforms this instance to instance of ByteBuffer (a link of chain of byte
arrays).
+ *
+ * @param encoding
+ * @return link of chain of byte arrays
+ * @throws UnsupportedEncodingException
+ */
+ public ByteBuffer toByteBuffer(String encoding) throws UnsupportedEncodingException
{
+ byte[] bs = new String(chars, 0, usedSize).getBytes(encoding);
+
+ return new ByteBuffer(bs);
+ }
+
+ /**
+ * Transforms this instance to instance of ByteBuffer (a link of chain of byte
arrays).
+ *
+ * @return link of chain of byte arrays
+ */
+ public ByteBuffer toByteBuffer() {
+ byte[] bs = new String(chars, 0, usedSize).getBytes();
+
+ return new ByteBuffer(bs);
+ }
+
+ /**
+ * Resets this char buffer to empty state
+ *
+ * @since 3.3.0
+ */
+ public void reset() {
+ usedSize = 0;
+ next = null;
+ prev = null;
+ }
+
+ /**
+ * @since 4.0
+ */
+ public void compact() {
+ if (chars.length - usedSize > MAX_WASTE) {
+ char[] cs = new char[usedSize];
+
+ System.arraycopy(chars, 0, cs, 0, usedSize);
+ this.chars = cs;
+ this.cacheSize = cs.length;
+ }
+
+ if (next != null) {
+ next.compact();
+ }
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java (from rev
22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java
(rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -0,0 +1,260 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Class for reading from a byte array chain.
+ *
+ * @author glory
+ */
+public class FastBufferInputStream extends InputStream {
+
+ /**
+ * Currently read link.
+ */
+ ByteBuffer current;
+
+ /**
+ * The first link in the chain of char arrays.
+ */
+ ByteBuffer firstLink;
+
+ /**
+ * Position of next byte in current link.
+ */
+ int index;
+ int mark;
+
+ public FastBufferInputStream(ByteBuffer byteBuffer) {
+ this.firstLink = byteBuffer;
+ current = byteBuffer;
+ index = 0;
+ mark = 0;
+ }
+
+ /**
+ * Creates instance of FastBufferInputStream.
+ *
+ * @param stream
+ */
+ @Deprecated
+ public FastBufferInputStream(FastBufferOutputStream stream) {
+ this(stream.getFirstBuffer());
+ }
+
+ /**
+ * @see java.io.InputStream.read()
+ */
+ public int read() throws IOException {
+ if (current == null) {
+ return -1;
+ }
+
+ if (current.getUsedSize() <= index) {
+ current = current.getNext();
+
+ if (current == null) {
+ return -1;
+ }
+
+ index = 0;
+ }
+
+ byte c = current.getByteAt(index);
+
+ index++;
+
+ return c;
+ }
+
+ /**
+ * @see java.io.InputStream.read(byte b[])
+ */
+ @Override
+ public int read(byte[] b) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ }
+
+ if (current == null) {
+ return -1;
+ }
+
+ int off = 0;
+ int len = b.length;
+ int actuallyRead = 0;
+
+ while ((current != null) && (len > 0)) {
+ int av = current.getUsedSize() - index;
+
+ if (av <= 0) {
+ current = current.getNext();
+ index = 0;
+
+ continue;
+ }
+
+ if (av > len) {
+ av = len;
+ }
+
+ System.arraycopy(current.getBytes(), index, b, off, av);
+ index += av;
+ off += av;
+ actuallyRead += av;
+ len -= av;
+ }
+
+ return (actuallyRead == 0) ? -1 : actuallyRead;
+ }
+
+ /**
+ * @see java.io.InputStream.read(byte b[], int off, int len)
+ */
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len)
> b.length) || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return 0;
+ }
+
+ if (current == null) {
+ return -1;
+ }
+
+ int actuallyRead = 0;
+
+ while ((current != null) && (len > 0)) {
+ int av = current.getUsedSize() - index;
+
+ if (av <= 0) {
+ current = current.getNext();
+ index = 0;
+
+ continue;
+ }
+
+ if (av > len) {
+ av = len;
+ }
+
+ System.arraycopy(current.getBytes(), index, b, off, av);
+ index += av;
+ off += av;
+ actuallyRead += av;
+ len -= av;
+ }
+
+ return (actuallyRead == 0) ? -1 : actuallyRead;
+ }
+
+ /**
+ * @see java.io.InputStream.available()
+ */
+ public int available() throws IOException {
+ if (current == null) {
+ return 0;
+ }
+
+ ByteBuffer b = current;
+ int result = -index;
+
+ while (b != null) {
+ result += b.getUsedSize();
+ b = b.getNext();
+ }
+
+ return result;
+ }
+
+ /**
+ * @see java.io.InputStream.mark()
+ */
+ public void mark(int readAheadLimit) {
+ if (current == null) {
+ mark = 0;
+ } else {
+ mark = index;
+
+ ByteBuffer b = current.getPrevious();
+
+ if (b != null) {
+ mark += b.getTotalSize();
+ }
+ }
+ }
+
+ /**
+ * @see java.io.InputStream.reset()
+ */
+ public void reset() {
+ if (current == null) {
+ current = firstLink;
+ }
+
+ int m = 0;
+
+ while ((current != null) && (current.getUsedSize() + m <= mark)) {
+ m += current.getUsedSize();
+ current = current.getNext();
+ }
+
+ if (current != null) {
+ index = mark - m;
+ }
+ }
+
+ /**
+ * @see java.io.InputStream.skip()
+ */
+ public long skip(long n) throws IOException {
+ long skipped = 0;
+
+ while (n > 0) {
+ if (current == null) {
+ return 0;
+ }
+
+ if (current.getUsedSize() - index <= n) {
+ index += n;
+ skipped += n;
+
+ break;
+ } else {
+ int dn = current.getUsedSize() - index;
+
+ skipped += dn;
+ n -= dn;
+ current = current.getNext();
+ index = 0;
+ }
+ }
+
+ return skipped;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java (from rev
22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java
(rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -0,0 +1,256 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+
+/**
+ * Class for writing to chain of byte arrays extending OutputStream.
+ *
+ * @author glory
+ */
+public class FastBufferOutputStream extends OutputStream {
+
+ /**
+ * The beginning of the chain of byte arrays.
+ */
+ ByteBuffer firstBuffer;
+
+ /**
+ * Currently filled link of the chain of byte arrays.
+ */
+ ByteBuffer lastBuffer;
+
+ /**
+ * Total number of written bytes.
+ */
+ int length;
+
+ /**
+ * Creates instance of default initial capacity.
+ */
+ public FastBufferOutputStream() {
+ this(256);
+ }
+
+ /**
+ * Creates instance for an already existing chain of byte arrays.
+ *
+ * @param firstBuffer
+ */
+ public FastBufferOutputStream(ByteBuffer firstBuffer) {
+ this.firstBuffer = firstBuffer;
+ this.lastBuffer = firstBuffer;
+ }
+
+ /**
+ * Creates instance with required initial capacity.
+ *
+ * @param initialSize
+ */
+ public FastBufferOutputStream(int initialSize) {
+ this(new ByteBuffer(initialSize));
+ }
+
+ /**
+ * @see java.io.OutputStream.write(int c)
+ */
+ public void write(int c) throws IOException {
+ lastBuffer = lastBuffer.append((byte) c);
+ length++;
+ }
+
+ /**
+ * @see java.io.OutputStream.write(byte b[])
+ */
+ public void write(byte[] b) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ }
+
+ int limit = b.length;
+
+ length += limit;
+ lastBuffer = lastBuffer.append(b, 0, limit);
+ }
+
+ /**
+ * @see java.io.OutputStream.write(byte[] b, int off, int len)
+ */
+ public void write(byte[] b, int off, int len) throws IOException {
+ if (b == null) {
+ throw new NullPointerException();
+ } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len)
> b.length) || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return;
+ }
+
+ lastBuffer = lastBuffer.append(b, off, len);
+ length += len;
+ }
+
+ /**
+ * Returns the total number of written bytes.
+ *
+ * @return
+ */
+ public int getLength() {
+ return length;
+ }
+
+ /**
+ * Returns the first link of the chain of byte arrays.
+ *
+ * @return
+ */
+ public ByteBuffer getFirstBuffer() {
+ return firstBuffer;
+ }
+
+ public byte[] toByteArray() {
+ ByteBuffer b = getFirstBuffer();
+
+ if (b == null) {
+ return new byte[0];
+ }
+
+ ByteBuffer l = b;
+
+ while (l.getNext() != null) {
+ l = l.getNext();
+ }
+
+ byte[] result = new byte[l.getTotalSize()];
+ int index = 0;
+
+ while (b != null) {
+ int s = b.getUsedSize();
+
+ System.arraycopy(b.getBytes(), 0, result, index, s);
+ index += s;
+ b = b.getNext();
+ }
+
+ return result;
+ }
+
+ /**
+ * Writes all data written up to the moment to out.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public void writeTo(OutputStream out) throws IOException {
+ ByteBuffer b = getFirstBuffer();
+
+ while (b != null) {
+ out.write(b.getBytes(), 0, b.getUsedSize());
+ b = b.getNext();
+ }
+ }
+
+ /**
+ * Writes all data written up to the moment to out.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public void writeTo(Writer out, String encoding) throws IOException {
+ ByteBuffer b = getFirstBuffer();
+
+ while (b != null) {
+ CharBuffer c = b.toCharBuffer(encoding);
+
+ out.write(c.getChars(), 0, c.getUsedSize());
+ b = b.getNext();
+ }
+ }
+
+ /**
+ * Returns instance of FastBufferWriter containing all data written to this output
stream.
+ *
+ * @param encoding
+ * @return
+ * @throws UnsupportedEncodingException
+ */
+ public FastBufferWriter convertToWriter(String encoding) throws
UnsupportedEncodingException {
+ ByteBuffer c = firstBuffer;
+ CharBuffer first = c.toCharBuffer(encoding);
+ CharBuffer b = first;
+
+ while (c != null) {
+ c = c.getNext();
+
+ if (c == null) {
+ break;
+ }
+
+ CharBuffer n = c.toCharBuffer(encoding);
+
+ b.setNext(n);
+ b = n;
+ }
+
+ return new FastBufferWriter(first);
+ }
+
+ /**
+ * Returns instance of FastBufferWriter containing all data written to this output
stream.
+ *
+ * @return
+ */
+ public FastBufferWriter convertToWriter() {
+ ByteBuffer c = firstBuffer;
+ CharBuffer first = c.toCharBuffer();
+ CharBuffer b = first;
+
+ while (c != null) {
+ c = c.getNext();
+
+ if (c == null) {
+ break;
+ }
+
+ CharBuffer n = c.toCharBuffer();
+
+ b.setNext(n);
+ b = n;
+ }
+
+ 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;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferReader.java (from rev
22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferReader.java
(rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferReader.java 2011-04-21 12:16:50
UTC (rev 22435)
@@ -0,0 +1,181 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * Class for reading from a char array chain.
+ *
+ * @author glory
+ */
+public class FastBufferReader extends Reader {
+
+ /**
+ * Currently read link.
+ */
+ CharBuffer current;
+
+ /**
+ * The first link in the chain of char arrays.
+ */
+ CharBuffer firstLink;
+
+ /**
+ * Position of next char in current link.
+ */
+ int index;
+
+ public FastBufferReader(CharBuffer buffer) {
+ firstLink = buffer;
+ current = firstLink;
+ index = 0;
+ }
+
+ /**
+ * Creates instance for given writer.
+ *
+ * @param writer
+ */
+ @Deprecated
+ public FastBufferReader(FastBufferWriter writer) {
+ firstLink = writer.getFirstBuffer();
+ current = firstLink;
+ index = 0;
+ }
+
+ public void close() throws IOException {
+ }
+
+ /**
+ * @see java.io.Reader.read()
+ */
+ public int read() throws IOException {
+ if (current == null) {
+ return -1;
+ }
+
+ if (current.getUsedSize() <= index) {
+ current = current.getNext();
+
+ if (current == null) {
+ return -1;
+ }
+
+ index = 0;
+ }
+
+ char c = current.getCharAt(index);
+
+ index++;
+
+ return c;
+ }
+
+ /**
+ * @see java.io.Reader.read(char[] cbuf, int off, int len)
+ */
+ public int read(char[] cbuf, int off, int len) throws IOException {
+ if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) >
cbuf.length) || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return 0;
+ }
+
+ if (current == null) {
+ return -1;
+ }
+
+ int actuallyRead = 0;
+
+ while ((current != null) && (len > 0)) {
+ int av = current.getUsedSize() - index;
+
+ if (av <= 0) {
+ current = current.getNext();
+ index = 0;
+
+ continue;
+ }
+
+ if (av > len) {
+ av = len;
+ }
+
+ System.arraycopy(current.getChars(), index, cbuf, off, av);
+ index += av;
+ off += av;
+ actuallyRead += av;
+ len -= av;
+ }
+
+ return (actuallyRead == 0) ? -1 : actuallyRead;
+ }
+
+ /**
+ * Returns the number of chars that may be read from this storage.
+ *
+ * @return
+ * @throws IOException
+ */
+ public int available() throws IOException {
+ if (current == null) {
+ return 0;
+ }
+
+ CharBuffer b = current;
+ int result = -index;
+
+ while (b != null) {
+ result += b.getUsedSize();
+ b = b.getNext();
+ }
+
+ return result;
+ }
+
+ /**
+ * Writes rest of data written up to the moment to out.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public void writeTo(Writer writer) throws IOException {
+ if (current == null) {
+ return;
+ }
+
+ if (current.getUsedSize() > index) {
+ writer.write(current.getChars(), index, current.getUsedSize() - index);
+ current = current.getNext();
+ }
+
+ while (current != null) {
+ writer.write(current.getChars(), 0, current.getUsedSize());
+ current = current.getNext();
+ }
+
+ index = 0;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferWriter.java (from rev
22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferWriter.java
(rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/FastBufferWriter.java 2011-04-21 12:16:50
UTC (rev 22435)
@@ -0,0 +1,262 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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;
+
+import javax.servlet.ServletOutputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.io.Writer;
+
+/**
+ * Class for writing to chain of char arrays extending Writer.
+ *
+ * @author glory
+ */
+public class FastBufferWriter extends Writer {
+
+ /**
+ * The beginning of the chain of char arrays.
+ */
+ CharBuffer firstBuffer;
+
+ /**
+ * Currently filled link of the chain of char arrays.
+ */
+ CharBuffer lastBuffer;
+
+ /**
+ * Total number of written chars.
+ */
+ int length;
+
+ /**
+ * Creates instance of default initial capacity.
+ */
+ public FastBufferWriter() {
+ this(256);
+ }
+
+ /**
+ * Creates instance for an already existing chain of char arrays.
+ *
+ * @param firstBuffer
+ */
+ public FastBufferWriter(CharBuffer firstBuffer) {
+ this.firstBuffer = firstBuffer;
+ lastBuffer = firstBuffer;
+ }
+
+ /**
+ * Creates instance with required initial capacity.
+ *
+ * @param initialSize
+ */
+ public FastBufferWriter(int initialSize) {
+ this(new CharBuffer(initialSize));
+ }
+
+ /**
+ * @see java.io.Writer.write(int c)
+ */
+ public void write(int c) throws IOException {
+ lastBuffer = lastBuffer.append((char) c);
+ length++;
+ }
+
+ /**
+ * @see java.io.Writer.write(char cbuf[])
+ */
+ public void write(char[] cbuf) throws IOException {
+ if (cbuf == null) {
+ throw new NullPointerException();
+ }
+
+ lastBuffer = lastBuffer.append(cbuf, 0, cbuf.length);
+ length += cbuf.length;
+ }
+
+ /**
+ * @see java.io.Writer.write(char cbuf[], int off, int len)
+ */
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ if (cbuf == null) {
+ throw new NullPointerException();
+ }
+
+ if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) >
cbuf.length) || ((off + len) < 0)) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return;
+ }
+
+ lastBuffer = lastBuffer.append(cbuf, off, len);
+ length += len;
+ }
+
+ /**
+ * Returns the total number of written chars.
+ *
+ * @return
+ */
+ public int getLength() {
+ return length;
+ }
+
+ /**
+ * Returns the first link of the chain of char arrays.
+ *
+ * @return
+ */
+ public CharBuffer getFirstBuffer() {
+ return firstBuffer;
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+
+ @Override
+ public void flush() throws IOException {
+ }
+
+ /**
+ * Writes all data written up to the moment to string buffer.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public char[] toCharArray() {
+ CharBuffer b = firstBuffer;
+
+ if (b == null) {
+ return new char[0];
+ }
+
+ CharBuffer l = b;
+
+ while (l.getNext() != null) {
+ l = l.getNext();
+ }
+
+ char[] result = new char[l.getTotalSize()];
+ int index = 0;
+
+ while (b != null) {
+ int s = b.getUsedSize();
+
+ System.arraycopy(b.getChars(), 0, result, index, s);
+ index += s;
+ b = b.getNext();
+ }
+
+ return result;
+ }
+
+ /**
+ * Writes all data written up to the moment to out.
+ *
+ * @param out
+ * @throws IOException
+ */
+ public void writeTo(Writer writer) throws IOException {
+ CharBuffer b = firstBuffer;
+
+ while (b != null) {
+ writer.write(b.getChars(), 0, b.getUsedSize());
+ b = b.getNext();
+ }
+ }
+
+ public void printTo(ServletOutputStream outputStream) throws IOException {
+ CharBuffer b = firstBuffer;
+
+ while (b != null) {
+ outputStream.print(new String(b.getChars()));
+ b = b.getNext();
+ }
+ }
+
+ /**
+ * Returns instance of FastBufferOutputStream containing all data written to this
writer.
+ *
+ * @param encoding
+ * @return
+ * @throws UnsupportedEncodingException
+ */
+ public FastBufferOutputStream convertToOutputStream(String encoding) throws
UnsupportedEncodingException {
+ CharBuffer c = firstBuffer;
+ ByteBuffer first = c.toByteBuffer(encoding);
+ ByteBuffer b = first;
+
+ while (c != null) {
+ c = c.getNext();
+
+ if (c == null) {
+ break;
+ }
+
+ ByteBuffer n = c.toByteBuffer(encoding);
+
+ b.setNext(n);
+ b = n;
+ }
+
+ return new FastBufferOutputStream(first);
+ }
+
+ /**
+ * Returns instance of FastBufferOutputStream containing all data written to this
writer.
+ *
+ * @return
+ */
+ public FastBufferOutputStream convertToOutputStream() {
+ CharBuffer c = firstBuffer;
+ ByteBuffer first = c.toByteBuffer();
+ ByteBuffer b = first;
+
+ while (c != null) {
+ c = c.getNext();
+
+ if (c == null) {
+ break;
+ }
+
+ ByteBuffer n = c.toByteBuffer();
+
+ b.setNext(n);
+ b = n;
+ }
+
+ 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;
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java (from rev
22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java
(rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -0,0 +1,562 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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;
+
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.AttributesImpl;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.ResponseWriter;
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * @author shura
+ * <p/>
+ * Realization of Faces <code>ResponseWriter</code> for Cocoon
Environment.
+ * Use ONLY Markup-specific calls , send it as SAX events to
+ * <code>XMLConsumer</code> Use "State" pattern for control
of events flow.
+ * TODO - implement namespace capabilites
+ */
+public class SAXResponseWriter extends ResponseWriter {
+
+ /**
+ * As we in XML framework, only UTF-8 supported for
+ * <code>CHARTER_ENCODING</code>
+ */
+ private static final String CHARTER_ENCODING = "UTF-8";
+
+ /**
+ * As we in XML framework, only xml supported for
<code>CONTENT_TYPE</code>
+ */
+ private static final String CONTENT_TYPE = "text/xml";
+ private String namespaceURI = "http://www.w3.org/1999/xhtml";
+ private LexicalHandler xmlLexicalHandler = null;
+ private AttributesImpl attributes;
+ private XMLResponseWriterState cdataState;
+ private String element;
+
+ /**
+ * State after startElement. Collect Attributes for SAX startElement
+ * <code>elementState</code>
+ */
+ private XMLResponseWriterState elementState;
+
+ /**
+ * State in normal document <code>inDocumentState</code>
+ */
+ private XMLResponseWriterState inDocumentState;
+
+ /**
+ * Before StartDocument or after EndDocument
<code>notDocumentState</code>
+ */
+ private XMLResponseWriterState notDocumentState;
+ private XMLResponseWriterState state;
+
+ /**
+ * Hold Cocoon Generator XML <code>consumer</code>
+ */
+ private ContentHandler xmlConsumer;
+
+ /**
+ * @param consumer -
+ * SAX events receiver for Cocoon pipeline.
+ */
+ public SAXResponseWriter(ContentHandler consumer) {
+ super();
+ this.xmlConsumer = consumer;
+
+ if (consumer instanceof LexicalHandler) {
+ xmlLexicalHandler = (LexicalHandler) consumer;
+ }
+
+ // Initialise states. May be must implemented in static block ?
+ this.notDocumentState = new NotDocumentState();
+
+ // inside document. allow any events exclude attributes and
+ // startDocument.
+ this.inDocumentState = new InDocumentState();
+ this.cdataState = new CDATAState();
+
+ // In element, collect attributes ...
+ this.elementState = new ElementState();
+ this.state = notDocumentState;
+ }
+
+ public ContentHandler getXmlConsumer() {
+ return xmlConsumer;
+ }
+
+ /**
+ * @return Returns the namespaceURI.
+ */
+ public String getNamespaceURI() {
+ return namespaceURI;
+ }
+
+ /**
+ * @param namespaceURI The namespaceURI to set.
+ */
+ public void setNamespaceURI(String namespaceURI) {
+ this.namespaceURI = namespaceURI;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#getContentType()
+ */
+ public String getContentType() {
+ return CONTENT_TYPE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#getCharacterEncoding()
+ */
+ public String getCharacterEncoding() {
+ return CHARTER_ENCODING;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Flushable#flush()
+ */
+ public void flush() throws IOException {
+
+ // DO NOTHING...
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#startDocument()
+ */
+ public void startDocument() throws IOException {
+ state.startDocument();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#endDocument()
+ */
+ public void endDocument() throws IOException {
+ state.endDocument();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#startElement(java.lang.String,
+ * javax.faces.component.UIComponent)
+ */
+ public void startElement(String name, UIComponent component) throws IOException {
+ state.startElement(name, component);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#endElement(java.lang.String)
+ */
+ public void endElement(String name) throws IOException {
+ state.endElement(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeAttribute(java.lang.String,
+ * java.lang.Object, java.lang.String)
+ */
+ public void writeAttribute(String name, Object value, String property) throws
IOException {
+ state.writeAttribute(name, value, property);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeURIAttribute(java.lang.String,
+ * java.lang.Object, java.lang.String)
+ */
+ public void writeURIAttribute(String name, Object value, String property) throws
IOException {
+ state.writeURIAttribute(name, value, property);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeComment(java.lang.Object)
+ */
+ public void writeComment(Object comment) throws IOException {
+ state.writeComment(comment);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeText(java.lang.Object,
+ * java.lang.String)
+ */
+ public void writeText(Object text, String property) throws IOException {
+ state.writeText(text, property);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#writeText(char[], int, int)
+ */
+ public void writeText(char[] text, int off, int len) throws IOException {
+ state.writeText(text, off, len);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see javax.faces.context.ResponseWriter#cloneWithWriter(java.io.Writer)
+ */
+ public ResponseWriter cloneWithWriter(Writer writer) {
+
+ // TODO as used XML consumer to get sax Events, we simple return current
+ // instance.
+ // if will used wrapper to combine XML Consumer with plain Servlet
+ // responce writer, must
+ // perform real clone ...
+ // We can use org.apache.cocoon.xml.SaxBuffer;
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Writer#write(char[], int, int)
+ */
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ state.writeText(cbuf, off, len);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.io.Closeable#close()
+ */
+ public void close() throws IOException {
+
+ // TODO Auto-generated method stub
+ }
+
+ /**
+ * @author shura
+ * <p/>
+ * CDATA section. allow regular write() functions, write any text.
+ */
+ private final class CDATAState extends XMLResponseWriterState {
+ void flushCDATA() throws IOException {
+
+ // try {
+ // xmlConsumer.endCDATA();
+ // } catch (SAXException e) {
+ // throw new IOException("Exception in endCDATA: "+
e.getMessage());
+ // }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#endDocument()
+ */
+ void endDocument() throws IOException {
+ flushCDATA();
+ state = inDocumentState;
+ state.endDocument();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#endElement(java.lang.String)
+ */
+ void endElement(String name) throws IOException {
+ flushCDATA();
+ state = inDocumentState;
+ state.endElement(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#startElement(java.lang.String,
+ * javax.faces.component.UIComponent)
+ */
+ void startElement(String name, UIComponent component) throws IOException {
+ flushCDATA();
+ element = name;
+ attributes = new AttributesImpl();
+ state = elementState;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeComment(java.lang.Object)
+ */
+ void writeComment(Object comment) throws IOException {
+ flushCDATA();
+ state = inDocumentState;
+ state.writeComment(comment);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(char[],
+ * int, int)
+ */
+ void writeText(char[] text, int off, int len) throws IOException {
+ try {
+ xmlConsumer.characters(text, off, len);
+ } catch (SAXException e) {
+ throw new IOException("Sax exceptions in writeText: " +
e.getMessage());
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(java.lang.Object,
+ * java.lang.String)
+ */
+ void writeText(Object text, String property) throws IOException {
+ writeText(text.toString().toCharArray(), 0, text.toString().length());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#write(char[],
+ * int, int)
+ */
+ void write(char[] cbuf, int off, int len) throws IOException {
+ writeText(cbuf, off, len);
+ }
+ }
+
+ /**
+ * @author shura State in element declsration. Collect attributes, on any
+ * other eventss - generate SAX startElement()
+ */
+ private final class ElementState extends XMLResponseWriterState {
+
+ /**
+ * Generate SAX StartElement event
+ *
+ * @throws IOException
+ */
+ void flushElement() throws IOException {
+ try {
+ xmlConsumer.startElement(getNamespaceURI(), element, element,
attributes);
+ } catch (SAXException e) {
+ throw new IOException("Exception in startElement: " +
e.getMessage());
+ } finally {
+ element = null;
+ attributes = null;
+ }
+ }
+
+ void writeAttribute(String name, Object value, String property) throws
IOException {
+ attributes.addAttribute(getNamespaceURI(), name, name,
"id".equalsIgnoreCase(name) ? "ID" : "CDATA",
+ value.toString());
+ }
+
+ void writeURIAttribute(String name, Object value, String property) throws
IOException {
+ String uri = value.toString();
+
+ // TODO - perform encodeActionURL() or ???
+ attributes.addAttribute(getNamespaceURI(), name, name, "CDATA",
uri);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#endElement(java.lang.String)
+ */
+ void endElement(String name) throws IOException {
+
+ //
+ flushElement();
+ state = inDocumentState;
+ state.endElement(name);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#startElement(java.lang.String,
+ * javax.faces.component.UIComponent)
+ */
+ void startElement(String name, UIComponent component) throws IOException {
+
+ //
+ flushElement();
+ element = name;
+ attributes = new AttributesImpl();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeComment(java.lang.Object)
+ */
+ void writeComment(Object comment) throws IOException {
+
+ // TODO Auto-generated method stub
+ flushElement();
+ state = inDocumentState;
+ state.writeComment(comment);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(char[],
+ * int, int)
+ */
+ void writeText(char[] text, int off, int len) throws IOException {
+
+ // TODO Auto-generated method stub
+ flushElement();
+ state = cdataState;
+ state.writeText(text, off, len);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(java.lang.Object,
+ * java.lang.String)
+ */
+ void writeText(Object text, String property) throws IOException {
+
+ // TODO Auto-generated method stub
+ flushElement();
+ state = cdataState;
+ state.writeText(text, property);
+ }
+ }
+
+ /**
+ * @author shura
+ * <p/>
+ * State in regular document. Disabled attributes & startDocument.
+ */
+ private final class InDocumentState extends XMLResponseWriterState {
+ void startElement(String name, UIComponent component) {
+ element = name;
+ attributes = new AttributesImpl();
+ state = elementState;
+ }
+
+ void writeComment(Object comment) throws IOException {
+ String remark = comment.toString();
+
+ try {
+ xmlLexicalHandler.comment(remark.toCharArray(), 0, remark.length());
+ } catch (SAXException e) {
+ throw new IOException("Comment SAX exception :" +
e.getMessage());
+ }
+ }
+
+ void writeText(Object o, String property) throws IOException {
+ writeText(o.toString().toCharArray(), 0, o.toString().length());
+ }
+
+ void writeText(char[] text, int start, int lenght) throws IOException {
+
+ // try {
+ // xmlConsumer.startCDATA();
+ // } catch (SAXException e) {
+ // throw new IOException("Sax exceptions in writeText: "+
+ // e.getMessage());
+ // } finally {
+ state = cdataState;
+
+ // }
+ state.writeText(text, start, lenght);
+ }
+
+ void endElement(String name) throws IOException {
+ try {
+ xmlConsumer.endElement(getNamespaceURI(), name, name);
+ } catch (SAXException e) {
+ throw new IOException("Sax exceptions in endElement: " +
e.getMessage());
+ }
+ }
+
+ void endDocument() throws IOException {
+ try {
+ xmlConsumer.endDocument();
+ } catch (SAXException e) {
+ throw new IOException("Sax exceptions in endDocument" +
e.getMessage());
+ } finally {
+
+ // after endDocument all events disabled ...
+ state = new XMLResponseWriterState();
+ }
+ }
+ }
+
+
+ // Private classes
+
+ /**
+ * @author shura
+ * <p/>
+ * state before startDocument - only allow startDocument.
+ */
+ private final class NotDocumentState extends XMLResponseWriterState {
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#startDocument()
+ */
+ void startDocument() throws IOException {
+ try {
+
+ //
+ xmlConsumer.startDocument();
+ } catch (SAXException e) {
+
+ //
+ throw new IOException("StartDocument SAX exception :" +
e.getMessage());
+ } finally {
+ state = inDocumentState;
+ }
+ }
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java (from rev
22426, trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java
(rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -0,0 +1,127 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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;
+
+import javax.faces.component.UIComponent;
+import java.io.IOException;
+
+/**
+ * @author shura Class to implement state pattern for
+ * <code>ResponseWriter</code> Real states must extend this. By
+ * default, block any events, ignore output.
+ */
+class XMLResponseWriterState {
+
+ // private ResponseWriter writer;
+
+ /**
+ * @throws java.io.IOException
+ */
+ void endDocument() throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param name
+ * @throws java.io.IOException
+ */
+ void endElement(String name) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @throws java.io.IOException
+ */
+ void startDocument() throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param name
+ * @param component
+ * @throws java.io.IOException
+ */
+ void startElement(String name, UIComponent component) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param name
+ * @param value
+ * @param property
+ * @throws java.io.IOException
+ */
+ void writeAttribute(String name, Object value, String property) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param comment
+ * @throws java.io.IOException
+ */
+ void writeComment(Object comment) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param text
+ * @param off
+ * @param len
+ * @throws java.io.IOException
+ */
+ void writeText(char[] text, int off, int len) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param text
+ * @param property
+ * @throws java.io.IOException
+ */
+ void writeText(Object text, String property) throws IOException {
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * @param name
+ * @param value
+ * @param property
+ * @throws java.io.IOException
+ */
+ void writeURIAttribute(String name, Object value, String property) throws IOException
{
+ throw new IOException("Illegal state for this method");
+ }
+
+ /**
+ * Main hook for realise <code>Writer</code>. In document writed as
+ * comment, outside of document do nothing ....
+ *
+ * @param cbuf
+ * @param off
+ * @param len
+ * @throws IOException
+ */
+ void write(char[] cbuf, int off, int len) throws IOException {
+
+ // DO NOTHING
+ }
+}
Copied: trunk/core/api/src/main/java/org/ajax4jsf/io/package-info.java (from rev 22426,
trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java)
===================================================================
--- trunk/core/api/src/main/java/org/ajax4jsf/io/package-info.java
(rev 0)
+++ trunk/core/api/src/main/java/org/ajax4jsf/io/package-info.java 2011-04-21 12:16:50 UTC
(rev 22435)
@@ -0,0 +1,4 @@
+/**
+ * Implementation of I/O streams based on buffers
+ */
+package org.ajax4jsf.io;
Copied: trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java (from
rev 22426, trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java)
===================================================================
--- trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java
(rev 0)
+++
trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -0,0 +1,81 @@
+/**
+ * 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;
+
+import junit.framework.TestCase;
+
+/**
+ * @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());
+ }
+}
Copied: trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java (from rev
22426, trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java)
===================================================================
--- trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java
(rev 0)
+++ trunk/core/api/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -0,0 +1,114 @@
+/**
+ * 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;
+
+import junit.framework.TestCase;
+
+/**
+ * @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());
+ }
+
+ public void testCompact() throws Exception {
+ int itemsTowWrite = 16384 + 16000;
+ FastBufferWriter writer = new FastBufferWriter(16384);
+
+ for (int i = 0; i < itemsTowWrite; i++) {
+ writer.write(i);
+ }
+
+ writer.close();
+
+ CharBuffer firstBuffer = writer.getFirstBuffer();
+
+ assertNotNull(firstBuffer);
+
+ CharBuffer nextBuffer = firstBuffer.getNext();
+
+ assertNotNull(nextBuffer);
+ assertNull(nextBuffer.getNext());
+ assertTrue(firstBuffer.getUsedSize() == firstBuffer.getCacheSize());
+ assertTrue(nextBuffer.getUsedSize() < nextBuffer.getCacheSize());
+ firstBuffer.compact();
+ assertTrue(firstBuffer.getUsedSize() == firstBuffer.getCacheSize());
+ assertTrue(nextBuffer.getUsedSize() == nextBuffer.getCacheSize());
+
+ FastBufferReader reader = new FastBufferReader(firstBuffer);
+
+ for (int i = 0; i < itemsTowWrite; i++) {
+ assertEquals(i, reader.read());
+ }
+
+ reader.close();
+ }
+}
Copied: trunk/core/api/src/test/java/org/ajax4jsf/io/Test.java (from rev 22426,
trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java)
===================================================================
--- trunk/core/api/src/test/java/org/ajax4jsf/io/Test.java (rev
0)
+++ trunk/core/api/src/test/java/org/ajax4jsf/io/Test.java 2011-04-21 12:16:50 UTC (rev
22435)
@@ -0,0 +1,340 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import org.junit.Ignore;
+
+@Ignore
+public final class Test {
+ private static final int ARRAY_LENGTH = 27;
+ private static final int READ_LENGTH = 22;
+ private static final int READ_OFF = 4;
+ private static final boolean OUT_STRING = true;
+ private static final boolean BUILD_STRING = false;
+
+ private Test() {}
+
+ static void testStreams() throws IOException {
+ String s = "This is a senseless text to test streams.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ byte[] bytes = s.getBytes();
+ FastBufferOutputStream output = new FastBufferOutputStream(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ FastBufferInputStream input = new FastBufferInputStream(output);
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ byte[] bs = new byte[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ System.out.println("Length=" + output.getLength());
+ }
+ }
+
+ static void testStandardStreams() throws IOException {
+ String s = "This is a senseless text to test streams.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ byte[] bytes = s.getBytes();
+ ByteArrayOutputStream output = new ByteArrayOutputStream(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ byte[] bs = new byte[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testReaders() throws IOException {
+ String s = "This is a senseless text to test readers.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ char[] bytes = s.toCharArray();
+ FastBufferWriter output = new FastBufferWriter(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ FastBufferReader input = new FastBufferReader(output);
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ char[] bs = new char[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testStandardReaders() throws IOException {
+ String s = "This is a senseless text to test readers.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ char[] bytes = s.toCharArray();
+ StringWriter output = new StringWriter(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ StringReader input = new StringReader(output.toString());
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ char[] bs = new char[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testTransitionFromWriterToStream() throws IOException {
+ String s = "This is a senseless text to test transform from writer to
stream.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ char[] bytes = s.toCharArray();
+ FastBufferWriter output = new FastBufferWriter(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ FastBufferOutputStream output2 =
output.convertToOutputStream("UTF-8");
+ FastBufferInputStream input = new FastBufferInputStream(output2);
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ byte[] bs = new byte[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testStandardTransitionFromWriterToStream() throws IOException {
+ String s = "This is a senseless text to test transform from writer to
stream.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ char[] bytes = s.toCharArray();
+ StringWriter output = new StringWriter(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ String str = output.toString();
+ ByteArrayInputStream input = new ByteArrayInputStream(str.getBytes());
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ byte[] bs = new byte[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ static void testTransitionFromStreamToWriter() throws IOException {
+ String s = "This is a senseless text to test transform from stream to
writer.\n";
+
+ for (int i = 0; i < 10; i++) {
+ s = s + s; // repeated 16 times
+ }
+
+ byte[] bytes = s.getBytes();
+ FastBufferOutputStream output = new FastBufferOutputStream(16);
+
+ // write it several times.
+ for (int i = 0; i < 4; i++) {
+ output.write(bytes);
+ }
+
+ // write it one more time by one byte
+ for (int i = 0; i < bytes.length; i++) {
+ output.write(bytes[i]);
+ }
+
+ FastBufferWriter output2 = output.convertToWriter("UTF-8");
+ FastBufferReader input = new FastBufferReader(output2);
+ StringBuffer sb = new StringBuffer();
+
+ // use for reading unconvenient array length.
+ char[] bs = new char[ARRAY_LENGTH];
+ int l = 0;
+
+ while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
+ if (BUILD_STRING) {
+ sb.append(new String(bs, READ_OFF, l));
+ }
+ }
+
+ if (BUILD_STRING && OUT_STRING) {
+ System.out.println(sb);
+ }
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ long t = System.currentTimeMillis();
+
+ try {
+ for (int i = 0; i < 10; i++) {
+
+// testStreams();
+// testStandardStreams();
+// testReaders();
+// testStandardReaders();
+// testTransitionFromWriterToStream();
+ testStandardTransitionFromWriterToStream();
+
+// testTransitionFromStreamToWriter();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ long dt = System.currentTimeMillis() - t;
+
+ System.out.println(dt);
+ }
+}
Modified: trunk/core/api/src/test/java/org/richfaces/log/JavaLoggerTest.java
===================================================================
--- trunk/core/api/src/test/java/org/richfaces/log/JavaLoggerTest.java 2011-04-21 10:26:42
UTC (rev 22434)
+++ trunk/core/api/src/test/java/org/richfaces/log/JavaLoggerTest.java 2011-04-21 12:16:50
UTC (rev 22435)
@@ -158,7 +158,7 @@
Logger.class.getMethod(levelName, Throwable.class, Enum.class,
Object[].class).invoke(logger,
new UnsupportedOperationException(levelName),
LoggerTestMessages.TEST_MESSAGE, new Object[] {levelName,
- ANOTHER_DUMMY_MESSAGE});
+ ANOTHER_DUMMY_MESSAGE});
}
Iterator<LogRecord> iterator = publishedRecords.iterator();
Modified: trunk/core/api/src/test/java/org/richfaces/util/LRUMapTest.java
===================================================================
--- trunk/core/api/src/test/java/org/richfaces/util/LRUMapTest.java 2011-04-21 10:26:42
UTC (rev 22434)
+++ trunk/core/api/src/test/java/org/richfaces/util/LRUMapTest.java 2011-04-21 12:16:50
UTC (rev 22435)
@@ -26,8 +26,6 @@
import java.util.Iterator;
import java.util.Map.Entry;
-import org.richfaces.util.LRUMap;
-
import junit.framework.TestCase;
/**
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java 2011-04-21 10:26:42 UTC
(rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/ByteBuffer.java 2011-04-21 12:16:50 UTC
(rev 22435)
@@ -1,266 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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;
-
-import java.io.UnsupportedEncodingException;
-
-/**
- * A single link in chain of byte arrays.
- *
- * @author glory
- */
-public class ByteBuffer {
- private static final int MAX_WASTE = 16384;
-
- /**
- * Stored bytes
- */
- private byte[] bytes;
-
- /**
- * Length of byte array.
- */
- private int cacheSize;
- private ByteBuffer next;
- private ByteBuffer prev;
-
- /**
- * Number of bytes stored in the array.
- */
- private int usedSize;
-
- /**
- * Creates instance of ByteBuffer already filled by bytes.
- *
- * @param bytes
- */
- public ByteBuffer(byte[] bytes) {
- this.bytes = bytes;
- usedSize = bytes.length;
- cacheSize = usedSize;
- }
-
- /**
- * Creates instance of ByteBuffer with byte array of required length.
- *
- * @param cacheSize length of byte array
- */
- public ByteBuffer(int cacheSize) {
- bytes = new byte[cacheSize];
- this.cacheSize = cacheSize;
- usedSize = 0;
- }
-
- /**
- * Appends byte to array if there are unfilled positions in it.
- * Otherwize creates next link in the chain, and appends the byte to it.
- *
- * @param c
- * @return instance of ByteBuffer to which byte was appended.
- */
- public ByteBuffer append(byte c) {
- if (next != null) {
- return next.append(c);
- }
-
- if (usedSize < cacheSize) {
- bytes[usedSize] = c;
- usedSize++;
-
- return this;
- } else {
- next = new ByteBuffer(cacheSize * 2);
- next.prev = this;
-
- return next.append(c);
- }
- }
-
- /**
- * Appends segment of a byte array to array if there are unfilled positions in it.
- * Otherwize creates next link in the chain, and appends data to it.
- *
- * @param c
- * @return instance of ByteBuffer to which byte array was appended.
- */
- public ByteBuffer append(byte[] bs, int off, int len) {
- if (next != null) {
- return next.append(bs, off, len);
- }
-
- if (len + usedSize <= cacheSize) {
- System.arraycopy(bs, off, bytes, usedSize, len);
- usedSize += len;
-
- return this;
- }
-
- int av = cacheSize - usedSize;
-
- if (av > 0) {
- System.arraycopy(bs, off, bytes, usedSize, av);
- usedSize += av;
- off += av;
- len -= av;
- }
-
- next = new ByteBuffer(cacheSize * 2);
- next.prev = this;
-
- return next.append(bs, off, len);
- }
-
- /**
- * Returns stored byte array.
- *
- * @return stored byte array
- */
- public byte[] getBytes() {
- return bytes;
- }
-
- /**
- * Returns byte at index. No check is fulfilled to provide high speed.
- *
- * @param index
- * @return
- */
- public byte getByteAt(int index) {
- return bytes[index];
- }
-
- /**
- * Returns actual number of byte stored in this link.
- *
- * @return
- */
- public int getUsedSize() {
- return usedSize;
- }
-
- /**
- * Returns capacity of this link.
- *
- * @return
- */
- public int getCacheSize() {
- return cacheSize;
- }
-
- /**
- * Returns total number of bytes stored in this link and all its predecessors.
- *
- * @return
- */
- public int getTotalSize() {
- return (prev == null) ? usedSize : prev.getTotalSize() + usedSize;
- }
-
- /**
- * Returns the previous link in the chain.
- *
- * @return
- */
- public ByteBuffer getPrevious() {
- return prev;
- }
-
- /**
- * Returns the next link in the chain.
- *
- * @return
- */
- public ByteBuffer getNext() {
- return next;
- }
-
- /**
- * Sets the next link in the chain.
- *
- * @param b
- */
- public void setNext(ByteBuffer b) {
- next = b;
-
- if (b != null) {
- b.prev = this;
- }
- }
-
- /**
- * Transforms this instance to instance of CharBuffer (a link of chain of char
arrays).
- *
- * @param encoding
- * @return link of chain of char arrays
- * @throws UnsupportedEncodingException
- */
- public CharBuffer toCharBuffer(String encoding) throws UnsupportedEncodingException
{
- String s;
-
- if (null != encoding) {
- s = new String(bytes, 0, usedSize, encoding);
- } else {
- s = new String(bytes, 0, usedSize);
- }
-
- return new CharBuffer(s.toCharArray());
- }
-
- /**
- * Transforms this instance to instance of CharBuffer (a link of chain of char
arrays).
- *
- * @return link of chain of char arrays
- */
- public CharBuffer toCharBuffer() {
- String s = new String(bytes, 0, usedSize);
-
- 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;
- }
-
- /**
- * @since 4.0
- */
- public void compact() {
- if (bytes.length - usedSize > MAX_WASTE) {
- byte[] bs = new byte[usedSize];
-
- System.arraycopy(bytes, 0, bs, 0, usedSize);
- this.bytes = bs;
- this.cacheSize = bs.length;
- }
-
- if (next != null) {
- next.compact();
- }
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java 2011-04-21 10:26:42 UTC
(rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/CharBuffer.java 2011-04-21 12:16:50 UTC
(rev 22435)
@@ -1,266 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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;
-
-import java.io.UnsupportedEncodingException;
-
-/**
- * A single link in chain of char arrays.
- *
- * @author glory
- */
-public class CharBuffer {
- private static final int MAX_WASTE = 16384;
- private static final int MIN_CACHE_SIZE = 64;
-
- /**
- * Length of char array.
- */
- private int cacheSize;
-
- /**
- * Stored characters
- */
- private char[] chars;
- private CharBuffer next;
- private CharBuffer prev;
-
- /**
- * number of characters stored in the array.
- */
- private int usedSize;
-
- /**
- * Creates instance of CharBuffer already filled by chars.
- *
- * @param bytes
- */
- public CharBuffer(char[] chars) {
- this.chars = chars;
- usedSize = chars.length;
- cacheSize = usedSize;
- }
-
- /**
- * Creates instance of CharBuffer with char array of required length.
- *
- * @param cacheSize length of char array
- */
- public CharBuffer(int cacheSize) {
- if (cacheSize < MIN_CACHE_SIZE) {
- this.cacheSize = MIN_CACHE_SIZE;
- } else {
- this.cacheSize = cacheSize;
- }
-
- chars = new char[this.cacheSize];
- usedSize = 0;
- }
-
- /**
- * Appends character to array chars if there are unfilled positions in it.
- * Otherwise creates next link in the chain, and appends the character to it.
- *
- * @param c
- * @return instance of CharBuffer to which character was appended.
- */
- public CharBuffer append(char c) {
- if (next != null) {
- return next.append(c);
- }
-
- if (usedSize < cacheSize) {
- chars[usedSize] = c;
- usedSize++;
-
- return this;
- } else {
- next = new CharBuffer(cacheSize * 2);
- next.prev = this;
-
- return next.append(c);
- }
- }
-
- /**
- * Appends segment of a char array to array if there are unfilled positions in it.
- * Otherwise creates next link in the chain, and appends data to it.
- *
- * @param c
- * @return instance of CharBuffer to which char array was appended.
- */
- public CharBuffer append(char[] cs, int off, int len) {
- if (next != null) {
- return next.append(cs, off, len);
- }
-
- if (len + usedSize <= cacheSize) {
- System.arraycopy(cs, off, chars, usedSize, len);
- usedSize += len;
-
- return this;
- }
-
- int av = cacheSize - usedSize;
-
- if (av > 0) {
- System.arraycopy(cs, off, chars, usedSize, av);
- usedSize += av;
- off += av;
- len -= av;
- }
-
- next = new CharBuffer(cacheSize * 2);
- next.prev = this;
-
- return next.append(cs, off, len);
- }
-
- /**
- * Returns stored char array.
- *
- * @return stored char array
- */
- public char[] getChars() {
- return chars;
- }
-
- /**
- * Returns character at index. No check is fulfilled to provide high speed.
- *
- * @param index
- * @return
- */
- public char getCharAt(int index) {
- return chars[index];
- }
-
- /**
- * Returns actual number of characters stored in this link.
- *
- * @return
- */
- public int getUsedSize() {
- return usedSize;
- }
-
- /**
- * Returns capacity of this link.
- *
- * @return
- */
- public int getCacheSize() {
- return cacheSize;
- }
-
- /**
- * Returns total number of characters stored in this link and all its predecessors.
- *
- * @return
- */
- public int getTotalSize() {
- return (prev == null) ? usedSize : prev.getTotalSize() + usedSize;
- }
-
- /**
- * Returns the previous link in the chain.
- *
- * @return
- */
- public CharBuffer getPrevious() {
- return prev;
- }
-
- /**
- * Returns the next link in the chain.
- *
- * @return
- */
- public CharBuffer getNext() {
- return next;
- }
-
- /**
- * Sets the next link in the chain.
- *
- * @param b
- */
- public void setNext(CharBuffer b) {
- next = b;
-
- if (b != null) {
- b.prev = this;
- }
- }
-
- /**
- * Transforms this instance to instance of ByteBuffer (a link of chain of byte
arrays).
- *
- * @param encoding
- * @return link of chain of byte arrays
- * @throws UnsupportedEncodingException
- */
- public ByteBuffer toByteBuffer(String encoding) throws UnsupportedEncodingException
{
- byte[] bs = new String(chars, 0, usedSize).getBytes(encoding);
-
- return new ByteBuffer(bs);
- }
-
- /**
- * Transforms this instance to instance of ByteBuffer (a link of chain of byte
arrays).
- *
- * @return link of chain of byte arrays
- */
- public ByteBuffer toByteBuffer() {
- byte[] bs = new String(chars, 0, usedSize).getBytes();
-
- return new ByteBuffer(bs);
- }
-
- /**
- * Resets this char buffer to empty state
- *
- * @since 3.3.0
- */
- public void reset() {
- usedSize = 0;
- next = null;
- prev = null;
- }
-
- /**
- * @since 4.0
- */
- public void compact() {
- if (chars.length - usedSize > MAX_WASTE) {
- char[] cs = new char[usedSize];
-
- System.arraycopy(chars, 0, cs, 0, usedSize);
- this.chars = cs;
- this.cacheSize = cs.length;
- }
-
- if (next != null) {
- next.compact();
- }
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java 2011-04-21
10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferInputStream.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -1,260 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-/**
- * Class for reading from a byte array chain.
- *
- * @author glory
- */
-public class FastBufferInputStream extends InputStream {
-
- /**
- * Currently read link.
- */
- ByteBuffer current;
-
- /**
- * The first link in the chain of char arrays.
- */
- ByteBuffer firstLink;
-
- /**
- * Position of next byte in current link.
- */
- int index;
- int mark;
-
- public FastBufferInputStream(ByteBuffer byteBuffer) {
- this.firstLink = byteBuffer;
- current = byteBuffer;
- index = 0;
- mark = 0;
- }
-
- /**
- * Creates instance of FastBufferInputStream.
- *
- * @param stream
- */
- @Deprecated
- public FastBufferInputStream(FastBufferOutputStream stream) {
- this(stream.getFirstBuffer());
- }
-
- /**
- * @see java.io.InputStream.read()
- */
- public int read() throws IOException {
- if (current == null) {
- return -1;
- }
-
- if (current.getUsedSize() <= index) {
- current = current.getNext();
-
- if (current == null) {
- return -1;
- }
-
- index = 0;
- }
-
- byte c = current.getByteAt(index);
-
- index++;
-
- return c;
- }
-
- /**
- * @see java.io.InputStream.read(byte b[])
- */
- @Override
- public int read(byte[] b) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- }
-
- if (current == null) {
- return -1;
- }
-
- int off = 0;
- int len = b.length;
- int actuallyRead = 0;
-
- while ((current != null) && (len > 0)) {
- int av = current.getUsedSize() - index;
-
- if (av <= 0) {
- current = current.getNext();
- index = 0;
-
- continue;
- }
-
- if (av > len) {
- av = len;
- }
-
- System.arraycopy(current.getBytes(), index, b, off, av);
- index += av;
- off += av;
- actuallyRead += av;
- len -= av;
- }
-
- return (actuallyRead == 0) ? -1 : actuallyRead;
- }
-
- /**
- * @see java.io.InputStream.read(byte b[], int off, int len)
- */
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len)
> b.length) || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return 0;
- }
-
- if (current == null) {
- return -1;
- }
-
- int actuallyRead = 0;
-
- while ((current != null) && (len > 0)) {
- int av = current.getUsedSize() - index;
-
- if (av <= 0) {
- current = current.getNext();
- index = 0;
-
- continue;
- }
-
- if (av > len) {
- av = len;
- }
-
- System.arraycopy(current.getBytes(), index, b, off, av);
- index += av;
- off += av;
- actuallyRead += av;
- len -= av;
- }
-
- return (actuallyRead == 0) ? -1 : actuallyRead;
- }
-
- /**
- * @see java.io.InputStream.available()
- */
- public int available() throws IOException {
- if (current == null) {
- return 0;
- }
-
- ByteBuffer b = current;
- int result = -index;
-
- while (b != null) {
- result += b.getUsedSize();
- b = b.getNext();
- }
-
- return result;
- }
-
- /**
- * @see java.io.InputStream.mark()
- */
- public void mark(int readAheadLimit) {
- if (current == null) {
- mark = 0;
- } else {
- mark = index;
-
- ByteBuffer b = current.getPrevious();
-
- if (b != null) {
- mark += b.getTotalSize();
- }
- }
- }
-
- /**
- * @see java.io.InputStream.reset()
- */
- public void reset() {
- if (current == null) {
- current = firstLink;
- }
-
- int m = 0;
-
- while ((current != null) && (current.getUsedSize() + m <= mark)) {
- m += current.getUsedSize();
- current = current.getNext();
- }
-
- if (current != null) {
- index = mark - m;
- }
- }
-
- /**
- * @see java.io.InputStream.skip()
- */
- public long skip(long n) throws IOException {
- long skipped = 0;
-
- while (n > 0) {
- if (current == null) {
- return 0;
- }
-
- if (current.getUsedSize() - index <= n) {
- index += n;
- skipped += n;
-
- break;
- } else {
- int dn = current.getUsedSize() - index;
-
- skipped += dn;
- n -= dn;
- current = current.getNext();
- index = 0;
- }
- }
-
- return skipped;
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java 2011-04-21
10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferOutputStream.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -1,256 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-
-/**
- * Class for writing to chain of byte arrays extending OutputStream.
- *
- * @author glory
- */
-public class FastBufferOutputStream extends OutputStream {
-
- /**
- * The beginning of the chain of byte arrays.
- */
- ByteBuffer firstBuffer;
-
- /**
- * Currently filled link of the chain of byte arrays.
- */
- ByteBuffer lastBuffer;
-
- /**
- * Total number of written bytes.
- */
- int length;
-
- /**
- * Creates instance of default initial capacity.
- */
- public FastBufferOutputStream() {
- this(256);
- }
-
- /**
- * Creates instance for an already existing chain of byte arrays.
- *
- * @param firstBuffer
- */
- public FastBufferOutputStream(ByteBuffer firstBuffer) {
- this.firstBuffer = firstBuffer;
- this.lastBuffer = firstBuffer;
- }
-
- /**
- * Creates instance with required initial capacity.
- *
- * @param initialSize
- */
- public FastBufferOutputStream(int initialSize) {
- this(new ByteBuffer(initialSize));
- }
-
- /**
- * @see java.io.OutputStream.write(int c)
- */
- public void write(int c) throws IOException {
- lastBuffer = lastBuffer.append((byte) c);
- length++;
- }
-
- /**
- * @see java.io.OutputStream.write(byte b[])
- */
- public void write(byte[] b) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- }
-
- int limit = b.length;
-
- length += limit;
- lastBuffer = lastBuffer.append(b, 0, limit);
- }
-
- /**
- * @see java.io.OutputStream.write(byte[] b, int off, int len)
- */
- public void write(byte[] b, int off, int len) throws IOException {
- if (b == null) {
- throw new NullPointerException();
- } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len)
> b.length) || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return;
- }
-
- lastBuffer = lastBuffer.append(b, off, len);
- length += len;
- }
-
- /**
- * Returns the total number of written bytes.
- *
- * @return
- */
- public int getLength() {
- return length;
- }
-
- /**
- * Returns the first link of the chain of byte arrays.
- *
- * @return
- */
- public ByteBuffer getFirstBuffer() {
- return firstBuffer;
- }
-
- public byte[] toByteArray() {
- ByteBuffer b = getFirstBuffer();
-
- if (b == null) {
- return new byte[0];
- }
-
- ByteBuffer l = b;
-
- while (l.getNext() != null) {
- l = l.getNext();
- }
-
- byte[] result = new byte[l.getTotalSize()];
- int index = 0;
-
- while (b != null) {
- int s = b.getUsedSize();
-
- System.arraycopy(b.getBytes(), 0, result, index, s);
- index += s;
- b = b.getNext();
- }
-
- return result;
- }
-
- /**
- * Writes all data written up to the moment to out.
- *
- * @param out
- * @throws IOException
- */
- public void writeTo(OutputStream out) throws IOException {
- ByteBuffer b = getFirstBuffer();
-
- while (b != null) {
- out.write(b.getBytes(), 0, b.getUsedSize());
- b = b.getNext();
- }
- }
-
- /**
- * Writes all data written up to the moment to out.
- *
- * @param out
- * @throws IOException
- */
- public void writeTo(Writer out, String encoding) throws IOException {
- ByteBuffer b = getFirstBuffer();
-
- while (b != null) {
- CharBuffer c = b.toCharBuffer(encoding);
-
- out.write(c.getChars(), 0, c.getUsedSize());
- b = b.getNext();
- }
- }
-
- /**
- * Returns instance of FastBufferWriter containing all data written to this output
stream.
- *
- * @param encoding
- * @return
- * @throws UnsupportedEncodingException
- */
- public FastBufferWriter convertToWriter(String encoding) throws
UnsupportedEncodingException {
- ByteBuffer c = firstBuffer;
- CharBuffer first = c.toCharBuffer(encoding);
- CharBuffer b = first;
-
- while (c != null) {
- c = c.getNext();
-
- if (c == null) {
- break;
- }
-
- CharBuffer n = c.toCharBuffer(encoding);
-
- b.setNext(n);
- b = n;
- }
-
- return new FastBufferWriter(first);
- }
-
- /**
- * Returns instance of FastBufferWriter containing all data written to this output
stream.
- *
- * @return
- */
- public FastBufferWriter convertToWriter() {
- ByteBuffer c = firstBuffer;
- CharBuffer first = c.toCharBuffer();
- CharBuffer b = first;
-
- while (c != null) {
- c = c.getNext();
-
- if (c == null) {
- break;
- }
-
- CharBuffer n = c.toCharBuffer();
-
- b.setNext(n);
- b = n;
- }
-
- 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;
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java 2011-04-21
10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferReader.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -1,181 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-
-/**
- * Class for reading from a char array chain.
- *
- * @author glory
- */
-public class FastBufferReader extends Reader {
-
- /**
- * Currently read link.
- */
- CharBuffer current;
-
- /**
- * The first link in the chain of char arrays.
- */
- CharBuffer firstLink;
-
- /**
- * Position of next char in current link.
- */
- int index;
-
- public FastBufferReader(CharBuffer buffer) {
- firstLink = buffer;
- current = firstLink;
- index = 0;
- }
-
- /**
- * Creates instance for given writer.
- *
- * @param writer
- */
- @Deprecated
- public FastBufferReader(FastBufferWriter writer) {
- firstLink = writer.getFirstBuffer();
- current = firstLink;
- index = 0;
- }
-
- public void close() throws IOException {
- }
-
- /**
- * @see java.io.Reader.read()
- */
- public int read() throws IOException {
- if (current == null) {
- return -1;
- }
-
- if (current.getUsedSize() <= index) {
- current = current.getNext();
-
- if (current == null) {
- return -1;
- }
-
- index = 0;
- }
-
- char c = current.getCharAt(index);
-
- index++;
-
- return c;
- }
-
- /**
- * @see java.io.Reader.read(char[] cbuf, int off, int len)
- */
- public int read(char[] cbuf, int off, int len) throws IOException {
- if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) >
cbuf.length) || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return 0;
- }
-
- if (current == null) {
- return -1;
- }
-
- int actuallyRead = 0;
-
- while ((current != null) && (len > 0)) {
- int av = current.getUsedSize() - index;
-
- if (av <= 0) {
- current = current.getNext();
- index = 0;
-
- continue;
- }
-
- if (av > len) {
- av = len;
- }
-
- System.arraycopy(current.getChars(), index, cbuf, off, av);
- index += av;
- off += av;
- actuallyRead += av;
- len -= av;
- }
-
- return (actuallyRead == 0) ? -1 : actuallyRead;
- }
-
- /**
- * Returns the number of chars that may be read from this storage.
- *
- * @return
- * @throws IOException
- */
- public int available() throws IOException {
- if (current == null) {
- return 0;
- }
-
- CharBuffer b = current;
- int result = -index;
-
- while (b != null) {
- result += b.getUsedSize();
- b = b.getNext();
- }
-
- return result;
- }
-
- /**
- * Writes rest of data written up to the moment to out.
- *
- * @param out
- * @throws IOException
- */
- public void writeTo(Writer writer) throws IOException {
- if (current == null) {
- return;
- }
-
- if (current.getUsedSize() > index) {
- writer.write(current.getChars(), index, current.getUsedSize() - index);
- current = current.getNext();
- }
-
- while (current != null) {
- writer.write(current.getChars(), 0, current.getUsedSize());
- current = current.getNext();
- }
-
- index = 0;
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java 2011-04-21
10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/FastBufferWriter.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -1,262 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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;
-
-import javax.servlet.ServletOutputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
-
-/**
- * Class for writing to chain of char arrays extending Writer.
- *
- * @author glory
- */
-public class FastBufferWriter extends Writer {
-
- /**
- * The beginning of the chain of char arrays.
- */
- CharBuffer firstBuffer;
-
- /**
- * Currently filled link of the chain of char arrays.
- */
- CharBuffer lastBuffer;
-
- /**
- * Total number of written chars.
- */
- int length;
-
- /**
- * Creates instance of default initial capacity.
- */
- public FastBufferWriter() {
- this(256);
- }
-
- /**
- * Creates instance for an already existing chain of char arrays.
- *
- * @param firstBuffer
- */
- public FastBufferWriter(CharBuffer firstBuffer) {
- this.firstBuffer = firstBuffer;
- lastBuffer = firstBuffer;
- }
-
- /**
- * Creates instance with required initial capacity.
- *
- * @param initialSize
- */
- public FastBufferWriter(int initialSize) {
- this(new CharBuffer(initialSize));
- }
-
- /**
- * @see java.io.Writer.write(int c)
- */
- public void write(int c) throws IOException {
- lastBuffer = lastBuffer.append((char) c);
- length++;
- }
-
- /**
- * @see java.io.Writer.write(char cbuf[])
- */
- public void write(char[] cbuf) throws IOException {
- if (cbuf == null) {
- throw new NullPointerException();
- }
-
- lastBuffer = lastBuffer.append(cbuf, 0, cbuf.length);
- length += cbuf.length;
- }
-
- /**
- * @see java.io.Writer.write(char cbuf[], int off, int len)
- */
- public void write(char[] cbuf, int off, int len) throws IOException {
- if (cbuf == null) {
- throw new NullPointerException();
- }
-
- if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) >
cbuf.length) || ((off + len) < 0)) {
- throw new IndexOutOfBoundsException();
- } else if (len == 0) {
- return;
- }
-
- lastBuffer = lastBuffer.append(cbuf, off, len);
- length += len;
- }
-
- /**
- * Returns the total number of written chars.
- *
- * @return
- */
- public int getLength() {
- return length;
- }
-
- /**
- * Returns the first link of the chain of char arrays.
- *
- * @return
- */
- public CharBuffer getFirstBuffer() {
- return firstBuffer;
- }
-
- @Override
- public void close() throws IOException {
- }
-
- @Override
- public void flush() throws IOException {
- }
-
- /**
- * Writes all data written up to the moment to string buffer.
- *
- * @param out
- * @throws IOException
- */
- public char[] toCharArray() {
- CharBuffer b = firstBuffer;
-
- if (b == null) {
- return new char[0];
- }
-
- CharBuffer l = b;
-
- while (l.getNext() != null) {
- l = l.getNext();
- }
-
- char[] result = new char[l.getTotalSize()];
- int index = 0;
-
- while (b != null) {
- int s = b.getUsedSize();
-
- System.arraycopy(b.getChars(), 0, result, index, s);
- index += s;
- b = b.getNext();
- }
-
- return result;
- }
-
- /**
- * Writes all data written up to the moment to out.
- *
- * @param out
- * @throws IOException
- */
- public void writeTo(Writer writer) throws IOException {
- CharBuffer b = firstBuffer;
-
- while (b != null) {
- writer.write(b.getChars(), 0, b.getUsedSize());
- b = b.getNext();
- }
- }
-
- public void printTo(ServletOutputStream outputStream) throws IOException {
- CharBuffer b = firstBuffer;
-
- while (b != null) {
- outputStream.print(new String(b.getChars()));
- b = b.getNext();
- }
- }
-
- /**
- * Returns instance of FastBufferOutputStream containing all data written to this
writer.
- *
- * @param encoding
- * @return
- * @throws UnsupportedEncodingException
- */
- public FastBufferOutputStream convertToOutputStream(String encoding) throws
UnsupportedEncodingException {
- CharBuffer c = firstBuffer;
- ByteBuffer first = c.toByteBuffer(encoding);
- ByteBuffer b = first;
-
- while (c != null) {
- c = c.getNext();
-
- if (c == null) {
- break;
- }
-
- ByteBuffer n = c.toByteBuffer(encoding);
-
- b.setNext(n);
- b = n;
- }
-
- return new FastBufferOutputStream(first);
- }
-
- /**
- * Returns instance of FastBufferOutputStream containing all data written to this
writer.
- *
- * @return
- */
- public FastBufferOutputStream convertToOutputStream() {
- CharBuffer c = firstBuffer;
- ByteBuffer first = c.toByteBuffer();
- ByteBuffer b = first;
-
- while (c != null) {
- c = c.getNext();
-
- if (c == null) {
- break;
- }
-
- ByteBuffer n = c.toByteBuffer();
-
- b.setNext(n);
- b = n;
- }
-
- 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;
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java 2011-04-21
10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/SAXResponseWriter.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -1,562 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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;
-
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-import org.xml.sax.ext.LexicalHandler;
-import org.xml.sax.helpers.AttributesImpl;
-
-import javax.faces.component.UIComponent;
-import javax.faces.context.ResponseWriter;
-import java.io.IOException;
-import java.io.Writer;
-
-/**
- * @author shura
- * <p/>
- * Realization of Faces <code>ResponseWriter</code> for Cocoon
Environment.
- * Use ONLY Markup-specific calls , send it as SAX events to
- * <code>XMLConsumer</code> Use "State" pattern for control
of events flow.
- * TODO - implement namespace capabilites
- */
-public class SAXResponseWriter extends ResponseWriter {
-
- /**
- * As we in XML framework, only UTF-8 supported for
- * <code>CHARTER_ENCODING</code>
- */
- private static final String CHARTER_ENCODING = "UTF-8";
-
- /**
- * As we in XML framework, only xml supported for
<code>CONTENT_TYPE</code>
- */
- private static final String CONTENT_TYPE = "text/xml";
- private String namespaceURI = "http://www.w3.org/1999/xhtml";
- private LexicalHandler xmlLexicalHandler = null;
- private AttributesImpl attributes;
- private XMLResponseWriterState cdataState;
- private String element;
-
- /**
- * State after startElement. Collect Attributes for SAX startElement
- * <code>elementState</code>
- */
- private XMLResponseWriterState elementState;
-
- /**
- * State in normal document <code>inDocumentState</code>
- */
- private XMLResponseWriterState inDocumentState;
-
- /**
- * Before StartDocument or after EndDocument
<code>notDocumentState</code>
- */
- private XMLResponseWriterState notDocumentState;
- private XMLResponseWriterState state;
-
- /**
- * Hold Cocoon Generator XML <code>consumer</code>
- */
- private ContentHandler xmlConsumer;
-
- /**
- * @param consumer -
- * SAX events receiver for Cocoon pipeline.
- */
- public SAXResponseWriter(ContentHandler consumer) {
- super();
- this.xmlConsumer = consumer;
-
- if (consumer instanceof LexicalHandler) {
- xmlLexicalHandler = (LexicalHandler) consumer;
- }
-
- // Initialise states. May be must implemented in static block ?
- this.notDocumentState = new NotDocumentState();
-
- // inside document. allow any events exclude attributes and
- // startDocument.
- this.inDocumentState = new InDocumentState();
- this.cdataState = new CDATAState();
-
- // In element, collect attributes ...
- this.elementState = new ElementState();
- this.state = notDocumentState;
- }
-
- public ContentHandler getXmlConsumer() {
- return xmlConsumer;
- }
-
- /**
- * @return Returns the namespaceURI.
- */
- public String getNamespaceURI() {
- return namespaceURI;
- }
-
- /**
- * @param namespaceURI The namespaceURI to set.
- */
- public void setNamespaceURI(String namespaceURI) {
- this.namespaceURI = namespaceURI;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#getContentType()
- */
- public String getContentType() {
- return CONTENT_TYPE;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#getCharacterEncoding()
- */
- public String getCharacterEncoding() {
- return CHARTER_ENCODING;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.Flushable#flush()
- */
- public void flush() throws IOException {
-
- // DO NOTHING...
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#startDocument()
- */
- public void startDocument() throws IOException {
- state.startDocument();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#endDocument()
- */
- public void endDocument() throws IOException {
- state.endDocument();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#startElement(java.lang.String,
- * javax.faces.component.UIComponent)
- */
- public void startElement(String name, UIComponent component) throws IOException {
- state.startElement(name, component);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#endElement(java.lang.String)
- */
- public void endElement(String name) throws IOException {
- state.endElement(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeAttribute(java.lang.String,
- * java.lang.Object, java.lang.String)
- */
- public void writeAttribute(String name, Object value, String property) throws
IOException {
- state.writeAttribute(name, value, property);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeURIAttribute(java.lang.String,
- * java.lang.Object, java.lang.String)
- */
- public void writeURIAttribute(String name, Object value, String property) throws
IOException {
- state.writeURIAttribute(name, value, property);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeComment(java.lang.Object)
- */
- public void writeComment(Object comment) throws IOException {
- state.writeComment(comment);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeText(java.lang.Object,
- * java.lang.String)
- */
- public void writeText(Object text, String property) throws IOException {
- state.writeText(text, property);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#writeText(char[], int, int)
- */
- public void writeText(char[] text, int off, int len) throws IOException {
- state.writeText(text, off, len);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.faces.context.ResponseWriter#cloneWithWriter(java.io.Writer)
- */
- public ResponseWriter cloneWithWriter(Writer writer) {
-
- // TODO as used XML consumer to get sax Events, we simple return current
- // instance.
- // if will used wrapper to combine XML Consumer with plain Servlet
- // responce writer, must
- // perform real clone ...
- // We can use org.apache.cocoon.xml.SaxBuffer;
- return this;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.Writer#write(char[], int, int)
- */
- public void write(char[] cbuf, int off, int len) throws IOException {
- state.writeText(cbuf, off, len);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.io.Closeable#close()
- */
- public void close() throws IOException {
-
- // TODO Auto-generated method stub
- }
-
- /**
- * @author shura
- * <p/>
- * CDATA section. allow regular write() functions, write any text.
- */
- private final class CDATAState extends XMLResponseWriterState {
- void flushCDATA() throws IOException {
-
- // try {
- // xmlConsumer.endCDATA();
- // } catch (SAXException e) {
- // throw new IOException("Exception in endCDATA: "+
e.getMessage());
- // }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#endDocument()
- */
- void endDocument() throws IOException {
- flushCDATA();
- state = inDocumentState;
- state.endDocument();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#endElement(java.lang.String)
- */
- void endElement(String name) throws IOException {
- flushCDATA();
- state = inDocumentState;
- state.endElement(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#startElement(java.lang.String,
- * javax.faces.component.UIComponent)
- */
- void startElement(String name, UIComponent component) throws IOException {
- flushCDATA();
- element = name;
- attributes = new AttributesImpl();
- state = elementState;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeComment(java.lang.Object)
- */
- void writeComment(Object comment) throws IOException {
- flushCDATA();
- state = inDocumentState;
- state.writeComment(comment);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(char[],
- * int, int)
- */
- void writeText(char[] text, int off, int len) throws IOException {
- try {
- xmlConsumer.characters(text, off, len);
- } catch (SAXException e) {
- throw new IOException("Sax exceptions in writeText: " +
e.getMessage());
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(java.lang.Object,
- * java.lang.String)
- */
- void writeText(Object text, String property) throws IOException {
- writeText(text.toString().toCharArray(), 0, text.toString().length());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#write(char[],
- * int, int)
- */
- void write(char[] cbuf, int off, int len) throws IOException {
- writeText(cbuf, off, len);
- }
- }
-
- /**
- * @author shura State in element declsration. Collect attributes, on any
- * other eventss - generate SAX startElement()
- */
- private final class ElementState extends XMLResponseWriterState {
-
- /**
- * Generate SAX StartElement event
- *
- * @throws IOException
- */
- void flushElement() throws IOException {
- try {
- xmlConsumer.startElement(getNamespaceURI(), element, element,
attributes);
- } catch (SAXException e) {
- throw new IOException("Exception in startElement: " +
e.getMessage());
- } finally {
- element = null;
- attributes = null;
- }
- }
-
- void writeAttribute(String name, Object value, String property) throws
IOException {
- attributes.addAttribute(getNamespaceURI(), name, name,
"id".equalsIgnoreCase(name) ? "ID" : "CDATA",
- value.toString());
- }
-
- void writeURIAttribute(String name, Object value, String property) throws
IOException {
- String uri = value.toString();
-
- // TODO - perform encodeActionURL() or ???
- attributes.addAttribute(getNamespaceURI(), name, name, "CDATA",
uri);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#endElement(java.lang.String)
- */
- void endElement(String name) throws IOException {
-
- //
- flushElement();
- state = inDocumentState;
- state.endElement(name);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#startElement(java.lang.String,
- * javax.faces.component.UIComponent)
- */
- void startElement(String name, UIComponent component) throws IOException {
-
- //
- flushElement();
- element = name;
- attributes = new AttributesImpl();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeComment(java.lang.Object)
- */
- void writeComment(Object comment) throws IOException {
-
- // TODO Auto-generated method stub
- flushElement();
- state = inDocumentState;
- state.writeComment(comment);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(char[],
- * int, int)
- */
- void writeText(char[] text, int off, int len) throws IOException {
-
- // TODO Auto-generated method stub
- flushElement();
- state = cdataState;
- state.writeText(text, off, len);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#writeText(java.lang.Object,
- * java.lang.String)
- */
- void writeText(Object text, String property) throws IOException {
-
- // TODO Auto-generated method stub
- flushElement();
- state = cdataState;
- state.writeText(text, property);
- }
- }
-
- /**
- * @author shura
- * <p/>
- * State in regular document. Disabled attributes & startDocument.
- */
- private final class InDocumentState extends XMLResponseWriterState {
- void startElement(String name, UIComponent component) {
- element = name;
- attributes = new AttributesImpl();
- state = elementState;
- }
-
- void writeComment(Object comment) throws IOException {
- String remark = comment.toString();
-
- try {
- xmlLexicalHandler.comment(remark.toCharArray(), 0, remark.length());
- } catch (SAXException e) {
- throw new IOException("Comment SAX exception :" +
e.getMessage());
- }
- }
-
- void writeText(Object o, String property) throws IOException {
- writeText(o.toString().toCharArray(), 0, o.toString().length());
- }
-
- void writeText(char[] text, int start, int lenght) throws IOException {
-
- // try {
- // xmlConsumer.startCDATA();
- // } catch (SAXException e) {
- // throw new IOException("Sax exceptions in writeText: "+
- // e.getMessage());
- // } finally {
- state = cdataState;
-
- // }
- state.writeText(text, start, lenght);
- }
-
- void endElement(String name) throws IOException {
- try {
- xmlConsumer.endElement(getNamespaceURI(), name, name);
- } catch (SAXException e) {
- throw new IOException("Sax exceptions in endElement: " +
e.getMessage());
- }
- }
-
- void endDocument() throws IOException {
- try {
- xmlConsumer.endDocument();
- } catch (SAXException e) {
- throw new IOException("Sax exceptions in endDocument" +
e.getMessage());
- } finally {
-
- // after endDocument all events disabled ...
- state = new XMLResponseWriterState();
- }
- }
- }
-
-
- // Private classes
-
- /**
- * @author shura
- * <p/>
- * state before startDocument - only allow startDocument.
- */
- private final class NotDocumentState extends XMLResponseWriterState {
-
- /*
- * (non-Javadoc)
- *
- * @see
org.apache.cocoon.components.faces.context.XMLResponseWriterState#startDocument()
- */
- void startDocument() throws IOException {
- try {
-
- //
- xmlConsumer.startDocument();
- } catch (SAXException e) {
-
- //
- throw new IOException("StartDocument SAX exception :" +
e.getMessage());
- } finally {
- state = inDocumentState;
- }
- }
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java 2011-04-21
10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/XMLResponseWriterState.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -1,127 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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;
-
-import javax.faces.component.UIComponent;
-import java.io.IOException;
-
-/**
- * @author shura Class to implement state pattern for
- * <code>ResponseWriter</code> Real states must extend this. By
- * default, block any events, ignore output.
- */
-class XMLResponseWriterState {
-
- // private ResponseWriter writer;
-
- /**
- * @throws java.io.IOException
- */
- void endDocument() throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param name
- * @throws java.io.IOException
- */
- void endElement(String name) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @throws java.io.IOException
- */
- void startDocument() throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param name
- * @param component
- * @throws java.io.IOException
- */
- void startElement(String name, UIComponent component) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param name
- * @param value
- * @param property
- * @throws java.io.IOException
- */
- void writeAttribute(String name, Object value, String property) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param comment
- * @throws java.io.IOException
- */
- void writeComment(Object comment) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param text
- * @param off
- * @param len
- * @throws java.io.IOException
- */
- void writeText(char[] text, int off, int len) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param text
- * @param property
- * @throws java.io.IOException
- */
- void writeText(Object text, String property) throws IOException {
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * @param name
- * @param value
- * @param property
- * @throws java.io.IOException
- */
- void writeURIAttribute(String name, Object value, String property) throws IOException
{
- throw new IOException("Illegal state for this method");
- }
-
- /**
- * Main hook for realise <code>Writer</code>. In document writed as
- * comment, outside of document do nothing ....
- *
- * @param cbuf
- * @param off
- * @param len
- * @throws IOException
- */
- void write(char[] cbuf, int off, int len) throws IOException {
-
- // DO NOTHING
- }
-}
Deleted: trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java
===================================================================
--- trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java 2011-04-21 10:26:42
UTC (rev 22434)
+++ trunk/core/impl/src/main/java/org/ajax4jsf/io/package-info.java 2011-04-21 12:16:50
UTC (rev 22435)
@@ -1,4 +0,0 @@
-/**
- * Implementation of I/O streams based on buffers
- */
-package org.ajax4jsf.io;
Deleted: trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java
===================================================================
---
trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java 2011-04-21
10:26:42 UTC (rev 22434)
+++
trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferOutputStreamTest.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -1,84 +0,0 @@
-/**
- * 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;
-
-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());
- }
-}
Deleted: trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java
===================================================================
--- trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java 2011-04-21
10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/test/java/org/ajax4jsf/io/FastBufferWriterTest.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -1,118 +0,0 @@
-/**
- * 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;
-
-import junit.framework.TestCase;
-
-import org.ajax4jsf.io.CharBuffer;
-import org.ajax4jsf.io.FastBufferReader;
-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());
- }
-
- public void testCompact() throws Exception {
- int itemsTowWrite = 16384 + 16000;
- FastBufferWriter writer = new FastBufferWriter(16384);
-
- for (int i = 0; i < itemsTowWrite; i++) {
- writer.write(i);
- }
-
- writer.close();
-
- CharBuffer firstBuffer = writer.getFirstBuffer();
-
- assertNotNull(firstBuffer);
-
- CharBuffer nextBuffer = firstBuffer.getNext();
-
- assertNotNull(nextBuffer);
- assertNull(nextBuffer.getNext());
- assertTrue(firstBuffer.getUsedSize() == firstBuffer.getCacheSize());
- assertTrue(nextBuffer.getUsedSize() < nextBuffer.getCacheSize());
- firstBuffer.compact();
- assertTrue(firstBuffer.getUsedSize() == firstBuffer.getCacheSize());
- assertTrue(nextBuffer.getUsedSize() == nextBuffer.getCacheSize());
-
- FastBufferReader reader = new FastBufferReader(firstBuffer);
-
- for (int i = 0; i < itemsTowWrite; i++) {
- assertEquals(i, reader.read());
- }
-
- reader.close();
- }
-}
Deleted: trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java
===================================================================
--- trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java 2011-04-21 10:26:42 UTC (rev
22434)
+++ trunk/core/impl/src/test/java/org/ajax4jsf/io/Test.java 2011-04-21 12:16:50 UTC (rev
22435)
@@ -1,340 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * 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;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import org.junit.Ignore;
-
-@Ignore
-public final class Test {
- private static final int ARRAY_LENGTH = 27;
- private static final int READ_LENGTH = 22;
- private static final int READ_OFF = 4;
- private static final boolean OUT_STRING = true;
- private static final boolean BUILD_STRING = false;
-
- private Test() {}
-
- static void testStreams() throws IOException {
- String s = "This is a senseless text to test streams.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- byte[] bytes = s.getBytes();
- FastBufferOutputStream output = new FastBufferOutputStream(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- FastBufferInputStream input = new FastBufferInputStream(output);
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- byte[] bs = new byte[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- System.out.println("Length=" + output.getLength());
- }
- }
-
- static void testStandardStreams() throws IOException {
- String s = "This is a senseless text to test streams.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- byte[] bytes = s.getBytes();
- ByteArrayOutputStream output = new ByteArrayOutputStream(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- byte[] bs = new byte[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testReaders() throws IOException {
- String s = "This is a senseless text to test readers.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- char[] bytes = s.toCharArray();
- FastBufferWriter output = new FastBufferWriter(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- FastBufferReader input = new FastBufferReader(output);
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- char[] bs = new char[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testStandardReaders() throws IOException {
- String s = "This is a senseless text to test readers.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- char[] bytes = s.toCharArray();
- StringWriter output = new StringWriter(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- StringReader input = new StringReader(output.toString());
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- char[] bs = new char[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testTransitionFromWriterToStream() throws IOException {
- String s = "This is a senseless text to test transform from writer to
stream.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- char[] bytes = s.toCharArray();
- FastBufferWriter output = new FastBufferWriter(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- FastBufferOutputStream output2 =
output.convertToOutputStream("UTF-8");
- FastBufferInputStream input = new FastBufferInputStream(output2);
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- byte[] bs = new byte[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testStandardTransitionFromWriterToStream() throws IOException {
- String s = "This is a senseless text to test transform from writer to
stream.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- char[] bytes = s.toCharArray();
- StringWriter output = new StringWriter(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- String str = output.toString();
- ByteArrayInputStream input = new ByteArrayInputStream(str.getBytes());
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- byte[] bs = new byte[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- static void testTransitionFromStreamToWriter() throws IOException {
- String s = "This is a senseless text to test transform from stream to
writer.\n";
-
- for (int i = 0; i < 10; i++) {
- s = s + s; // repeated 16 times
- }
-
- byte[] bytes = s.getBytes();
- FastBufferOutputStream output = new FastBufferOutputStream(16);
-
- // write it several times.
- for (int i = 0; i < 4; i++) {
- output.write(bytes);
- }
-
- // write it one more time by one byte
- for (int i = 0; i < bytes.length; i++) {
- output.write(bytes[i]);
- }
-
- FastBufferWriter output2 = output.convertToWriter("UTF-8");
- FastBufferReader input = new FastBufferReader(output2);
- StringBuffer sb = new StringBuffer();
-
- // use for reading unconvenient array length.
- char[] bs = new char[ARRAY_LENGTH];
- int l = 0;
-
- while ((l = input.read(bs, READ_OFF, READ_LENGTH)) >= 0) {
- if (BUILD_STRING) {
- sb.append(new String(bs, READ_OFF, l));
- }
- }
-
- if (BUILD_STRING && OUT_STRING) {
- System.out.println(sb);
- }
- }
-
- /**
- * @param args
- */
- public static void main(String[] args) {
- long t = System.currentTimeMillis();
-
- try {
- for (int i = 0; i < 10; i++) {
-
-// testStreams();
-// testStandardStreams();
-// testReaders();
-// testStandardReaders();
-// testTransitionFromWriterToStream();
- testStandardTransitionFromWriterToStream();
-
-// testTransitionFromStreamToWriter();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- long dt = System.currentTimeMillis() - t;
-
- System.out.println(dt);
- }
-}
Modified: trunk/core/impl/src/test/java/org/richfaces/cache/JBossCacheTest.java
===================================================================
--- trunk/core/impl/src/test/java/org/richfaces/cache/JBossCacheTest.java 2011-04-21
10:26:42 UTC (rev 22434)
+++ trunk/core/impl/src/test/java/org/richfaces/cache/JBossCacheTest.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -23,7 +23,6 @@
package org.richfaces.cache;
-import org.richfaces.cache.JBossCacheCacheFactory;
/**
* @author Nick Belaevski
Modified:
trunk/core/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java
===================================================================
---
trunk/core/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java 2011-04-21
10:26:42 UTC (rev 22434)
+++
trunk/core/impl/src/test/java/org/richfaces/resource/AbstractCacheableResourceTest.java 2011-04-21
12:16:50 UTC (rev 22435)
@@ -226,7 +226,7 @@
assertTrue(resource.userAgentNeedsUpdate(facesContext));
}
- private static abstract class AbstractTestResource extends AbstractCacheableResource
{
+ private abstract static class AbstractTestResource extends AbstractCacheableResource
{
@Override
public String toString() {
return "mock";