|
From: <fd...@us...> - 2006-12-26 00:22:52
|
Revision: 2955
http://jnode.svn.sourceforge.net/jnode/?rev=2955&view=rev
Author: fduminy
Date: 2006-12-25 16:22:49 -0800 (Mon, 25 Dec 2006)
Log Message:
-----------
patch submited by Andrei DORE :
fixed bug in ByteBufferInputStream.available() implementation + added test case
Modified Paths:
--------------
trunk/core/src/core/org/jnode/util/ByteBufferInputStream.java
Added Paths:
-----------
trunk/core/src/test/org/jnode/test/bugs/TestByteBufferInputStream.java
Modified: trunk/core/src/core/org/jnode/util/ByteBufferInputStream.java
===================================================================
--- trunk/core/src/core/org/jnode/util/ByteBufferInputStream.java 2006-12-22 21:17:39 UTC (rev 2954)
+++ trunk/core/src/core/org/jnode/util/ByteBufferInputStream.java 2006-12-26 00:22:49 UTC (rev 2955)
@@ -33,6 +33,7 @@
}
/**
+ * @Override
* @see java.io.InputStream#read()
*/
public int read() throws IOException {
@@ -41,5 +42,14 @@
} else {
return -1;
}
- }
+ }
+
+ @Override
+ /**
+ * @author Andrei DORE
+ */
+ public int available() throws IOException
+ {
+ return buf.remaining();
+ }
}
Added: trunk/core/src/test/org/jnode/test/bugs/TestByteBufferInputStream.java
===================================================================
--- trunk/core/src/test/org/jnode/test/bugs/TestByteBufferInputStream.java (rev 0)
+++ trunk/core/src/test/org/jnode/test/bugs/TestByteBufferInputStream.java 2006-12-26 00:22:49 UTC (rev 2955)
@@ -0,0 +1,41 @@
+package org.jnode.test.bugs;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import junit.framework.TestCase;
+
+import org.jnode.util.ByteBufferInputStream;
+
+/**
+ *
+ * @author Andrei DORE
+ *
+ */
+public class TestByteBufferInputStream extends TestCase {
+ /**
+ * That test show if the (ByteBuffer)InputStream.available is properly implemented
+ * or not
+ * @throws IOException
+ */
+ public void testWrappedByBufferedInputStream() throws IOException{
+ final int SIZE = 5000;
+
+ ByteBuffer buffer=ByteBuffer.allocate(SIZE);
+ for(int i=0;i<SIZE;i++){
+ buffer.put((byte)1);
+ }
+
+ buffer.rewind();
+
+ ByteBufferInputStream input=new ByteBufferInputStream(buffer);
+
+ BufferedInputStream bufferedInputStream=new BufferedInputStream(input,2048);
+
+
+ byte data[]=new byte[SIZE];
+
+ assertEquals(SIZE, bufferedInputStream.read(data));
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|