You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2007/11/27 22:01:51 UTC
svn commit: r598764 -
/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/
Author: jmsnell
Date: Tue Nov 27 13:01:49 2007
New Revision: 598764
URL: http://svn.apache.org/viewvc?rev=598764&view=rev
Log:
General improvements to the i18n.io classes. Some changes are intended to improve performance, others are usability focused
Added:
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PipeChannel.java
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadableByteChannelCodepointIterator.java
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReaderCodepointIterator.java
Modified:
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CharArrayCodepointIterator.java
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CodepointIterator.java
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/DynamicPushbackInputStream.java
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PeekAheadInputStream.java
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadWriteByteChannel.java
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RestrictedCodepointIterator.java
incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RewindableInputStream.java
Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CharArrayCodepointIterator.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CharArrayCodepointIterator.java?rev=598764&r1=598763&r2=598764&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CharArrayCodepointIterator.java (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CharArrayCodepointIterator.java Tue Nov 27 13:01:49 2007
@@ -17,7 +17,6 @@
*/
package org.apache.abdera.i18n.io;
-import org.apache.abdera.i18n.io.CodepointIterator;
/**
* Iterate over Unicode codepoints contained in a char array
Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CodepointIterator.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CodepointIterator.java?rev=598764&r1=598763&r2=598764&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CodepointIterator.java (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/CodepointIterator.java Tue Nov 27 13:01:49 2007
@@ -17,58 +17,129 @@
*/
package org.apache.abdera.i18n.io;
+import java.io.InputStream;
+import java.io.Reader;
import java.nio.CharBuffer;
-
-import org.apache.abdera.i18n.io.ByteArrayCodepointIterator;
-import org.apache.abdera.i18n.io.CharArrayCodepointIterator;
-import org.apache.abdera.i18n.io.CharBufferCodepointIterator;
-import org.apache.abdera.i18n.io.CharSequenceCodepointIterator;
-import org.apache.abdera.i18n.io.CharUtils;
-import org.apache.abdera.i18n.io.CodepointIterator;
-import org.apache.abdera.i18n.io.InvalidCharacterException;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
/**
- * Iterate over Unicode codepoints
+ * Provides an iterator over Unicode Codepoints
*/
public abstract class CodepointIterator {
+ /**
+ * Get a CodepointIterator for the specified char array
+ */
public static CodepointIterator forCharArray(char[] array) {
return new CharArrayCodepointIterator(array);
}
+ /**
+ * Get a CodepointIterator for the specified CharSequence
+ */
public static CodepointIterator forCharSequence(CharSequence seq) {
return new CharSequenceCodepointIterator(seq);
}
+ /**
+ * Get a CodepointIterator for the specified byte array, using the default charset
+ */
public static CodepointIterator forByteArray(byte[] array) {
return new ByteArrayCodepointIterator(array);
}
+
+ /**
+ * Get a CodepointIterator for the specified byte array, using the specified charset
+ */
+ public static CodepointIterator forByteArray(byte[] array, String charset) {
+ return new ByteArrayCodepointIterator(array,charset);
+ }
+ /**
+ * Get a CodepointIterator for the specified CharBuffer
+ */
public static CodepointIterator forCharBuffer(CharBuffer buffer) {
return new CharBufferCodepointIterator(buffer);
}
+ /**
+ * Get a CodepointIterator for the specified ReadableByteChannel
+ */
+ public static CodepointIterator forReadableByteChannel(ReadableByteChannel channel) {
+ return new ReadableByteChannelCodepointIterator(channel);
+ }
+
+ /**
+ * Get a CodepointIterator for the specified ReadableByteChannel
+ */
+ public static CodepointIterator forReadableByteChannel(ReadableByteChannel channel, String charset) {
+ return new ReadableByteChannelCodepointIterator(channel,charset);
+ }
+
+ /**
+ * Get a CodepointIterator for the specified InputStream
+ */
+ public static CodepointIterator forInputStream(InputStream in) {
+ return new ReadableByteChannelCodepointIterator(Channels.newChannel(in));
+ }
+
+ /**
+ * Get a CodepointIterator for the specified InputStream using the specified charset
+ */
+ public static CodepointIterator forInputStream(InputStream in, String charset) {
+ return new ReadableByteChannelCodepointIterator(Channels.newChannel(in),charset);
+ }
+
+ /**
+ * Get a CodepointIterator for the specified Reader
+ */
+ public static CodepointIterator forReader(Reader in) {
+ return new ReaderCodepointIterator(in);
+ }
+
protected int position = -1;
protected int limit = -1;
-
+
+ /**
+ * Get the next char
+ */
protected abstract char get();
+ /**
+ * Get the specified char
+ */
protected abstract char get(int index);
+ /**
+ * True if there are codepoints remaining
+ */
public boolean hasNext() {
return remaining() > 0;
}
+ /**
+ * Return the last char in the iterator
+ */
public int last() {
return (position() > 0) ? get(position() - 1) : -1;
}
+ /**
+ * Return the final index position
+ */
public int lastPosition() {
int p = position();
return (p > -1) ?
(p >= limit()) ? p : p - 1 : -1;
}
+ /**
+ * Return the next chars. If the codepoint is not supplemental,
+ * the char array will have a single member. If the codepoint is
+ * supplemental, the char array will have two members, representing
+ * the high and low surrogate chars
+ */
public char[] nextChars() throws InvalidCharacterException {
if (hasNext()) {
if (isNextSurrogate()) {
@@ -93,11 +164,23 @@
}
return null;
}
-
+
+ /**
+ * Peek the next chars in the iterator. If the codepoint is not supplemental,
+ * the char array will have a single member. If the codepoint is
+ * supplemental, the char array will have two members, representing
+ * the high and low surrogate chars
+ */
public char[] peekChars() throws InvalidCharacterException {
return peekChars(position());
}
+ /**
+ * Peek the specified chars in the iterator. If the codepoint is not supplemental,
+ * the char array will have a single member. If the codepoint is
+ * supplemental, the char array will have two members, representing
+ * the high and low surrogate chars
+ */
private char[] peekChars(int pos) throws InvalidCharacterException {
if (pos < 0 || pos >= limit()) return null;
char c1 = get(pos);
@@ -118,6 +201,9 @@
} else return new char[] {c1};
}
+ /**
+ * Return the next codepoint
+ */
public int next() throws InvalidCharacterException {
char[] chars = nextChars();
return (chars == null) ? -1 :
@@ -125,6 +211,9 @@
CharUtils.toCodePoint(chars[0], chars[1]);
}
+ /**
+ * Peek the next codepoint
+ */
public int peek() throws InvalidCharacterException {
char[] chars = peekChars();
return (chars == null) ? -1 :
@@ -132,6 +221,9 @@
CharUtils.toCodePoint(chars[0], chars[1]);
}
+ /**
+ * Peek the specified codepoint
+ */
public int peek(int index) throws InvalidCharacterException {
char[] chars = peekChars(index);
return (chars == null) ? -1 :
@@ -139,19 +231,31 @@
CharUtils.toCodePoint(chars[0], chars[1]);
}
+ /**
+ * Set the iterator position
+ */
public void position(int n) {
if (n < 0 || n > limit()) throw new ArrayIndexOutOfBoundsException(n);
position = n;
}
+ /**
+ * Get the iterator position
+ */
public int position() {
return position;
}
+ /**
+ * Return the iterator limit
+ */
public int limit() {
return limit;
}
+ /**
+ * Return the remaining iterator size
+ */
public int remaining() {
return limit - position();
}
@@ -162,11 +266,17 @@
return CharUtils.isHighSurrogate(c) || CharUtils.isLowSurrogate(c);
}
+ /**
+ * Returns true if the char at the specified index is a high surrogate
+ */
public boolean isHigh(int index) {
if (index < 0 || index > limit()) throw new ArrayIndexOutOfBoundsException(index);
return CharUtils.isHighSurrogate(get(index));
}
+ /**
+ * Returns true if the char at the specified index is a low surrogate
+ */
public boolean isLow(int index) {
if (index < 0 || index > limit()) throw new ArrayIndexOutOfBoundsException(index);
return CharUtils.isLowSurrogate(get(index));
Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/DynamicPushbackInputStream.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/DynamicPushbackInputStream.java?rev=598764&r1=598763&r2=598764&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/DynamicPushbackInputStream.java (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/DynamicPushbackInputStream.java Tue Nov 27 13:01:49 2007
@@ -25,7 +25,8 @@
* PushbackInputStream implementation that performs dynamic resizing of
* the unread buffer
*/
-public class DynamicPushbackInputStream extends PushbackInputStream {
+public class DynamicPushbackInputStream
+ extends PushbackInputStream {
private int origsize = 1;
@@ -38,6 +39,9 @@
this.origsize = initialSize;
}
+ /**
+ * Clear the buffer
+ */
public synchronized int clear() {
int m = buf.length;
buf = new byte[origsize];
@@ -45,6 +49,11 @@
return m;
}
+ /**
+ * Shrink the buffer. This will reclaim currently unused space in the
+ * buffer, reducing memory but potentially increasing the cost of
+ * resizing the buffer
+ */
public synchronized int shrink() {
byte[] old = buf;
if (pos == 0) return 0; // nothing to do
Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PeekAheadInputStream.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PeekAheadInputStream.java?rev=598764&r1=598763&r2=598764&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PeekAheadInputStream.java (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PeekAheadInputStream.java Tue Nov 27 13:01:49 2007
@@ -20,8 +20,6 @@
import java.io.IOException;
import java.io.InputStream;
-import org.apache.abdera.i18n.io.RewindableInputStream;
-
/**
* A version of RewindableInputStream that provides methods for peeking ahead
* in the stream (equivalent to read() followed by an appropriate unread()
@@ -37,16 +35,27 @@
super(in,initialSize);
}
+ /**
+ * Peek the next byte in the stream
+ */
public synchronized int peek() throws IOException {
int m = read();
unread(m);
return m;
}
+ /**
+ * Peek the next bytes in the stream. Returns the number of bytes peeked.
+ * Will return -1 if the end of the stream is reached
+ */
public synchronized int peek(byte[] buf) throws IOException {
return peek(buf, 0, buf.length);
}
-
+
+ /**
+ * Peek the next bytes in the stream. Returns the number of bytes peeked.
+ * Will return -1 if the end of the stream is reached
+ */
public synchronized int peek(byte[] buf, int off, int len) throws IOException {
int r = read(buf, off, len);
unread(buf,off,len);
Added: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PipeChannel.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PipeChannel.java?rev=598764&view=auto
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PipeChannel.java (added)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/PipeChannel.java Tue Nov 27 13:01:49 2007
@@ -0,0 +1,358 @@
+package org.apache.abdera.i18n.io;
+
+
+import java.io.Closeable;
+import java.io.FilterInputStream;
+import java.io.FilterOutputStream;
+import java.io.FilterReader;
+import java.io.FilterWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.Pipe;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.charset.Charset;
+
+/**
+ * Implements a buffer that provides a slightly more efficient way of writing,
+ * and then reading a stream of bytes.
+ *
+ * To use:
+ *
+ * PipeChannel pipe = new PipeChannel();
+ * byte[] bytes = {'a','b','c','d'};
+ * pipe.write(bytes);
+ * pipe.close();
+ *
+ * InputStream in = pipe.getInputStream();
+ * int i = -1;
+ * while ((i = in.read()) != -1) {...}
+ *
+ * By default, closing will automatically cause it to flip over to Read mode,
+ * locking the buffer from further writes and setting the read position to 0.
+ *
+ * Once the Buffer has been fully read, it must be reset, which sets it
+ * back into write mode
+ *
+ */
+public class PipeChannel
+ implements ReadableByteChannel,
+ WritableByteChannel,
+ Appendable,
+ Readable,
+ Closeable {
+
+ protected String charset = Charset.defaultCharset().name();
+
+ protected Pipe pipe;
+ protected boolean flipped = false;
+
+ public PipeChannel() {
+ reset();
+ }
+
+ public PipeChannel(String charset) {
+ this.charset = charset;
+ }
+
+ private void checkFlipped() {
+ if (flipped) throw new RuntimeException("PipeChannel is read only");
+ }
+
+ private void checkNotFlipped() {
+ if (!flipped) throw new RuntimeException("PipeChannel is write only");
+ }
+
+ /**
+ * Get an inputstream that can read from this pipe. The Pipe must be readable
+ */
+ public InputStream getInputStream() {
+ checkNotFlipped();
+ return new PipeChannelInputStream(this,Channels.newInputStream(pipe.source()));
+ }
+
+ /**
+ * Get an outputstream that can write to this pipe. The Pipe must be writable
+ */
+ public OutputStream getOutputStream() {
+ checkFlipped();
+ return new PipeChannelOutputStream(this,Channels.newOutputStream(pipe.sink()));
+ }
+
+ /**
+ * Get a writer that can write to this pipe. The pipe must be writable
+ */
+ public Writer getWriter() {
+ checkFlipped();
+ return new PipeChannelWriter(this,Channels.newWriter(pipe.sink(),charset));
+ }
+
+ /**
+ * Get a writer that can write to this pipe. The pipe must be writable
+ */
+ public Writer getWriter(String charset) {
+ checkFlipped();
+ return new PipeChannelWriter(this,Channels.newWriter(pipe.sink(), charset));
+ }
+
+ /**
+ * Get a reader that can reader from this pipe. The pipe must be readable
+ */
+ public Reader getReader(String charset) {
+ checkNotFlipped();
+ return new PipeChannelReader(this,Channels.newReader(pipe.source(), charset));
+ }
+
+ /**
+ * Get a reader that can reader from this pipe. The pipe must be readable
+ */
+ public Reader getReader() {
+ checkNotFlipped();
+ return new PipeChannelReader(this,Channels.newReader(pipe.source(), charset));
+ }
+
+ /**
+ * Get a CodepointIterator that can iterate over unicode codepoints in this pipe.
+ * The pipe must be readable
+ */
+ public CodepointIterator getIterator() {
+ checkNotFlipped();
+ return new ReadableByteChannelCodepointIterator(pipe.source(),charset);
+ }
+
+ /**
+ * Get a CodepointIterator that can iterate over unicode codepoints in this pipe.
+ * The pipe must be readable
+ */
+ public CodepointIterator getIterator(String charset) {
+ checkNotFlipped();
+ return new ReadableByteChannelCodepointIterator(pipe.source(),charset);
+ }
+
+ /**
+ * Read from the pipe.
+ */
+ public int read(ByteBuffer dst) throws IOException {
+ checkNotFlipped();
+ return pipe.source().read(dst);
+ }
+
+ /**
+ * Read from the pipe.
+ */
+ public int read(byte[] dst) throws IOException {
+ checkNotFlipped();
+ return pipe.source().read(ByteBuffer.wrap(dst));
+ }
+
+ /**
+ * Read from the pipe.
+ */
+ public int read(byte[] dst, int offset, int length) throws IOException {
+ checkNotFlipped();
+ return pipe.source().read(ByteBuffer.wrap(dst,offset,length));
+ }
+
+ /**
+ * True if the pipe is open
+ */
+ public boolean isOpen() {
+ return pipe.sink().isOpen() || pipe.source().isOpen();
+ }
+
+ /**
+ * Write to the pipe
+ */
+ public int write(ByteBuffer src) throws IOException {
+ checkFlipped();
+ return pipe.sink().write(src);
+ }
+
+ /**
+ * Write to the pipe
+ */
+ public int write(byte[] src) throws IOException {
+ checkFlipped();
+ return write(ByteBuffer.wrap(src));
+ }
+
+ /**
+ * Write to the pipe
+ */
+ public int write(byte[] src, int offset, int len) throws IOException {
+ checkFlipped();
+ return write(ByteBuffer.wrap(src, offset, len));
+ }
+
+ /**
+ * True if this pipe is readable
+ */
+ public boolean isReadable() {
+ return flipped;
+ }
+
+ /**
+ * True if this pipe is writable
+ */
+ public boolean isWritable() {
+ return !flipped;
+ }
+
+ /**
+ * If the pipe is writable, this will close the input and switch to readable mode
+ * If the pipe is readable, this will close the output and reset the pipe
+ */
+ public void close() throws IOException {
+ if (!flipped) {
+ if (pipe.sink().isOpen()) pipe.sink().close();
+ flipped = true;
+ } else {
+ if (pipe.source().isOpen()) pipe.source().close();
+ reset();
+ }
+ }
+
+ /**
+ * Reset the pipe. Switches the pipe to writable mode
+ */
+ public void reset() {
+ try {
+ if (pipe != null) {
+ if (pipe.sink().isOpen()) pipe.sink().close();
+ if (pipe.source().isOpen()) pipe.source().close();
+ }
+ pipe = Pipe.open();
+ flipped = false;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static class PipeChannelInputStream
+ extends FilterInputStream {
+ private final PipeChannel pipe;
+ protected PipeChannelInputStream(
+ PipeChannel pipe,
+ InputStream in) {
+ super(in);
+ this.pipe = pipe;
+ }
+ @Override
+ public void close() throws IOException {
+ pipe.close();
+ }
+ }
+
+ private static class PipeChannelOutputStream
+ extends FilterOutputStream {
+ private final PipeChannel pipe;
+ protected PipeChannelOutputStream(
+ PipeChannel pipe,
+ OutputStream in) {
+ super(in);
+ this.pipe = pipe;
+ }
+ @Override
+ public void close() throws IOException {
+ pipe.close();
+ }
+ }
+
+ private static class PipeChannelReader
+ extends FilterReader {
+ private final PipeChannel pipe;
+ protected PipeChannelReader(
+ PipeChannel pipe,
+ Reader in) {
+ super(in);
+ this.pipe = pipe;
+ }
+ @Override
+ public void close() throws IOException {
+ pipe.close();
+ }
+ }
+
+ private static class PipeChannelWriter
+ extends FilterWriter {
+ private final PipeChannel pipe;
+ protected PipeChannelWriter(
+ PipeChannel pipe,
+ Writer in) {
+ super(in);
+ this.pipe = pipe;
+ }
+ @Override
+ public void close() throws IOException {
+ pipe.close();
+ }
+ }
+
+ public Appendable append(
+ CharSequence csq)
+ throws IOException {
+ getWriter().append(csq);
+ return this;
+ }
+
+ public Appendable append(
+ char c)
+ throws IOException {
+ getWriter().append(c);
+ return this;
+ }
+
+ public Appendable append(
+ CharSequence csq,
+ int start,
+ int end)
+ throws IOException {
+ getWriter().append(csq,start,end);
+ return this;
+ }
+
+ public Appendable append(
+ CharSequence csq,
+ String charset)
+ throws IOException {
+ getWriter(charset).append(csq);
+ return this;
+ }
+
+ public Appendable append(
+ char c,
+ String charset)
+ throws IOException {
+ getWriter(charset).append(c);
+ return this;
+ }
+
+ public Appendable append(
+ CharSequence csq,
+ int start,
+ int end,
+ String charset)
+ throws IOException {
+ getWriter(charset).append(csq,start,end);
+ return this;
+ }
+
+ public int read(
+ CharBuffer cb)
+ throws IOException {
+ return getReader().read(cb);
+ }
+
+ public int read(
+ CharBuffer cb,
+ String charset)
+ throws IOException {
+ return getReader(charset).read(cb);
+ }
+}
Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadWriteByteChannel.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadWriteByteChannel.java?rev=598764&r1=598763&r2=598764&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadWriteByteChannel.java (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadWriteByteChannel.java Tue Nov 27 13:01:49 2007
@@ -28,9 +28,6 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
-import org.apache.abdera.i18n.io.ByteArrayCodepointIterator;
-import org.apache.abdera.i18n.io.CodepointIterator;
-
/**
* Implements a buffer that provides a slightly more efficient way of writing,
* and then reading a stream of bytes.
@@ -53,7 +50,10 @@
* Once the Buffer has been fully read, it must be reset, which sets it
* back into write mode and moves the position pointer back to 0;
*
+ * @deprecated
+ * @see org.apache.abdera.i18n.io.PipeChannel
*/
+@Deprecated
public class ReadWriteByteChannel
implements ReadableByteChannel,
WritableByteChannel,
Added: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadableByteChannelCodepointIterator.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadableByteChannelCodepointIterator.java?rev=598764&view=auto
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadableByteChannelCodepointIterator.java (added)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReadableByteChannelCodepointIterator.java Tue Nov 27 13:01:49 2007
@@ -0,0 +1,49 @@
+package org.apache.abdera.i18n.io;
+
+
+import java.io.ByteArrayOutputStream;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.nio.charset.Charset;
+
+import org.apache.abdera.i18n.io.CharArrayCodepointIterator;
+
+/**
+ * Iterate over Unicode codepoints in a CharSequence (e.g. String, StringBuffer, etc)
+ */
+public class ReadableByteChannelCodepointIterator
+ extends CharArrayCodepointIterator {
+
+ public ReadableByteChannelCodepointIterator(
+ ReadableByteChannel channel) {
+ this(channel,Charset.defaultCharset());
+ }
+
+ public ReadableByteChannelCodepointIterator(
+ ReadableByteChannel channel,
+ String charset) {
+ this(channel,Charset.forName(charset));
+ }
+
+ public ReadableByteChannelCodepointIterator(
+ ReadableByteChannel channel,
+ Charset charset) {
+ try {
+ ByteBuffer buf = ByteBuffer.allocate(1024);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ WritableByteChannel outc = Channels.newChannel(out);
+ while(channel.read(buf) > 0) {
+ buf.flip();
+ outc.write(buf);
+ }
+ CharBuffer cb = charset.decode(ByteBuffer.wrap(out.toByteArray()));
+ buffer = cb.array();
+ position = cb.position();
+ limit = cb.limit();
+ } catch (Exception e) {}
+ }
+
+}
Added: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReaderCodepointIterator.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReaderCodepointIterator.java?rev=598764&view=auto
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReaderCodepointIterator.java (added)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/ReaderCodepointIterator.java Tue Nov 27 13:01:49 2007
@@ -0,0 +1,44 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.i18n.io;
+
+import java.io.IOException;
+import java.io.Reader;
+
+public class ReaderCodepointIterator
+ extends CharArrayCodepointIterator {
+
+ public ReaderCodepointIterator(Reader reader) {
+ try {
+ StringBuilder sb = new StringBuilder();
+ char[] buf = new char[1024];
+ int n = -1;
+ while((n = reader.read(buf)) > -1) {
+ sb.append(buf,0,n);
+ }
+ buffer = new char[sb.length()];
+ sb.getChars(0, sb.length(), buffer, 0);
+ position = 0;
+ limit = buffer.length;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+}
Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RestrictedCodepointIterator.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RestrictedCodepointIterator.java?rev=598764&r1=598763&r2=598764&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RestrictedCodepointIterator.java (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RestrictedCodepointIterator.java Tue Nov 27 13:01:49 2007
@@ -22,7 +22,7 @@
/**
- * A CodepointIterator implementation that checks output against a BitSet.
+ * A CodepointIterator implementation that checks output against a CharUTils.Profile.
* If the iterator is set to "scanning only", the iterator will return -1
* upon encountering a codepoint not in the set, otherwise the iterator
* will throw an InvalidCharacterException
@@ -31,8 +31,8 @@
extends FilterCodepointIterator {
private final Profile profile;
- private boolean scanningOnly = false;
- private boolean notset = false;
+ private final boolean scanningOnly;
+ private final boolean notset;
protected RestrictedCodepointIterator(
CodepointIterator internal,
Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RewindableInputStream.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RewindableInputStream.java?rev=598764&r1=598763&r2=598764&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RewindableInputStream.java (original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/io/RewindableInputStream.java Tue Nov 27 13:01:49 2007
@@ -20,8 +20,6 @@
import java.io.IOException;
import java.io.InputStream;
-import org.apache.abdera.i18n.io.DynamicPushbackInputStream;
-
/**
* RewindableInputStream is a specialization of the PushbackInputStream
* that maintains an internal buffer of read bytes that a user can