Author: david.lloyd(a)jboss.com
Date: 2008-07-03 19:31:01 -0400 (Thu, 03 Jul 2008)
New Revision: 4351
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java
Log:
Fix various minor bugs
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java
===================================================================
---
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java 2008-07-03
18:37:32 UTC (rev 4350)
+++
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/ByteBufferInputStream.java 2008-07-03
23:31:01 UTC (rev 4351)
@@ -96,7 +96,9 @@
try {
final ByteBuffer buffer = current;
current = null;
- allocator.free(buffer);
+ if (buffer != null) {
+ allocator.free(buffer);
+ }
bufferSource.close();
} finally {
closed = true;
@@ -107,13 +109,16 @@
private ByteBuffer getBuffer() throws IOException {
final ByteBuffer buffer = current;
if (buffer == null) {
- if (bufferSource.hasNext()) {
+ while (bufferSource.hasNext()) {
final ByteBuffer newBuffer = bufferSource.next();
- current = newBuffer;
- return newBuffer;
- } else {
- return null;
+ if (newBuffer.hasRemaining()) {
+ current = newBuffer;
+ return newBuffer;
+ } else {
+ allocator.free(newBuffer);
+ }
}
+ return null;
} else {
return buffer;
}
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java
===================================================================
---
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java 2008-07-03
18:37:32 UTC (rev 4350)
+++
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferReader.java 2008-07-03
23:31:01 UTC (rev 4351)
@@ -100,7 +100,9 @@
try {
final CharBuffer buffer = current;
current = null;
- allocator.free(buffer);
+ if (buffer != null) {
+ allocator.free(buffer);
+ }
bufferSource.close();
} finally {
closed = true;
@@ -147,13 +149,16 @@
private CharBuffer getBuffer() throws IOException {
final CharBuffer buffer = current;
if (buffer == null) {
- if (bufferSource.hasNext()) {
+ while (bufferSource.hasNext()) {
final CharBuffer newBuffer = bufferSource.next();
- current = newBuffer;
- return newBuffer;
- } else {
- return null;
+ if (newBuffer.hasRemaining()) {
+ current = newBuffer;
+ return newBuffer;
+ } else {
+ allocator.free(newBuffer);
+ }
}
+ return null;
} else {
return buffer;
}
Modified:
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java
===================================================================
---
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java 2008-07-03
18:37:32 UTC (rev 4350)
+++
remoting3/trunk/api/src/main/java/org/jboss/cx/remoting/stream/CharBufferWriter.java 2008-07-03
23:31:01 UTC (rev 4351)
@@ -107,7 +107,7 @@
do {
final CharBuffer buffer = getBuffer();
final int rem = Math.min(len, buffer.remaining());
- buffer.put(str, off, rem);
+ buffer.put(str, off, off + rem);
if (! buffer.hasRemaining()) {
localFlush();
}
Modified:
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java
===================================================================
---
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java 2008-07-03
18:37:32 UTC (rev 4350)
+++
remoting3/trunk/util/src/main/java/org/jboss/cx/remoting/util/CollectionUtil.java 2008-07-03
23:31:01 UTC (rev 4351)
@@ -578,7 +578,7 @@
public static <T> Iterable<T> reverse(final List<T> list) {
return new Iterable<T>() {
public Iterator<T> iterator() {
- return reverse(list.listIterator());
+ return reverse(list.listIterator(list.size()));
}
};
}
Show replies by date