summaryrefslogtreecommitdiff
path: root/gnu/java/nio/ChannelReader.java
diff options
context:
space:
mode:
authorRobert Schuster <theBohemian@gmx.net>2005-02-21 18:19:13 +0000
committerRobert Schuster <theBohemian@gmx.net>2005-02-21 18:19:13 +0000
commiteea386ed5f0662a478dec558c49b1d4c4dbe6da7 (patch)
tree06f7d6107ab2e24495c4a1f21c1ef4bbf7efc22c /gnu/java/nio/ChannelReader.java
parent53c048f6336e1f9e943245c2ea8261d08b8b54b6 (diff)
downloadclasspath-eea386ed5f0662a478dec558c49b1d4c4dbe6da7.tar.gz
2005-02-21 Robert Schuster <thebohemian@gmx.net>
* gnu/java/nio/ChannelReader: Fixed comments.
Diffstat (limited to 'gnu/java/nio/ChannelReader.java')
-rw-r--r--gnu/java/nio/ChannelReader.java106
1 files changed, 39 insertions, 67 deletions
diff --git a/gnu/java/nio/ChannelReader.java b/gnu/java/nio/ChannelReader.java
index 1aa0455ea..11e66a77e 100644
--- a/gnu/java/nio/ChannelReader.java
+++ b/gnu/java/nio/ChannelReader.java
@@ -52,7 +52,7 @@ import java.nio.charset.CodingErrorAction;
* CharsetDecoder.
*
* <p>
- * This is a bridge between NIO <->IO character decoding.
+ * This is a bridge between NIO <-> IO character decoding.
* </p>
*
* @author Robert Schuster
@@ -83,10 +83,8 @@ public class ChannelReader extends Reader
int size = (minBufferCap == -1) ? DEFAULT_BUFFER_CAP : minBufferCap;
- /*
- * Allocates the buffers and prepares them for reading, because that is the
- * first operation being done on them.
- */
+ // Allocates the buffers and prepares them for reading, because that is the
+ // first operation being done on them.
byteBuffer = ByteBuffer.allocate(size);
byteBuffer.flip();
charBuffer = CharBuffer.allocate((int) (size * decoder.averageCharsPerByte()));
@@ -94,46 +92,34 @@ public class ChannelReader extends Reader
public int read(char[] buf, int offset, int count) throws IOException
{
- /*
- * I declared channel being null meaning that the reader is closed.
- */
+ // I declared channel being null meaning that the reader is closed.
if (!channel.isOpen())
throw new IOException("Reader was already closed.");
- /*
- * I declared decoder being null meaning that there is no more data to read
- * and convert.
- */
+ // I declared decoder being null meaning that there is no more data to read
+ // and convert.
if (decoder == null)
return -1;
- /*
- * Stores the amount of character being read. It -1 so that if no conversion
- * occured the caller will see this as an 'end of file'.
- */
+ // Stores the amount of character being read. It -1 so that if no conversion
+ // occured the caller will see this as an 'end of file'.
int sum = -1;
- /*
- * Copies any characters which may be left from the last invocation into the
- * destination array.
- */
+ // Copies any characters which may be left from the last invocation into the
+ // destination array.
if (charBuffer.remaining() > 0)
{
sum = Math.min(count, charBuffer.remaining());
charBuffer.get(buf, offset, sum);
- /*
- * Updates the control variables according to the latest copy operation.
- */
+ // Updates the control variables according to the latest copy operation.
offset += sum;
count -= sum;
}
- /*
- * Copies the character which have not been put in the destination array to
- * the beginning. If data is actually copied count will be 0. If no data is
- * copied count is >0 and we can now convert some more characters.
- */
+ // Copies the character which have not been put in the destination array to
+ // the beginning. If data is actually copied count will be 0. If no data is
+ // copied count is >0 and we can now convert some more characters.
charBuffer.compact();
int converted = 0;
@@ -141,23 +127,19 @@ public class ChannelReader extends Reader
while (count != 0)
{
- /*
- * Tries to convert some bytes (Which will intentionally fail in the
- * first place because we have not read any bytes yet.)
- */
+ // Tries to convert some bytes (Which will intentionally fail in the
+ // first place because we have not read any bytes yet.)
CoderResult result = decoder.decode(byteBuffer, charBuffer, last);
- if(result.isMalformed() || result.isUnmappable()) {
- /* JDK throws exception when bytes are malformed for sure.
- * FIXME: Unsure what happens when a character is simply
- * unmappable.
- */
- result.throwException();
- }
-
- /*
- * Marks that we should end this loop regardless whether the caller
- * wants more chars or not, when this was the last conversion.
- */
+ if (result.isMalformed() || result.isUnmappable())
+ {
+ // JDK throws exception when bytes are malformed for sure.
+ // FIXME: Unsure what happens when a character is simply
+ // unmappable.
+ result.throwException();
+ }
+
+ // Marks that we should end this loop regardless whether the caller
+ // wants more chars or not, when this was the last conversion.
if (last)
{
decoder = null;
@@ -166,20 +148,16 @@ public class ChannelReader extends Reader
{
// We need more bytes to do the conversion.
- /*
- * Copies the not yet converted bytes to the beginning making it
- * being able to receive more bytes.
- */
+ // Copies the not yet converted bytes to the beginning making it
+ // being able to receive more bytes.
byteBuffer.compact();
// Reads in another bunch of bytes for being converted.
if (channel.read(byteBuffer) == -1)
{
- /*
- * If there is no more data available in the channel we mark
- * that state for the final character conversion run which is
- * done in the next loop iteration.
- */
+ // If there is no more data available in the channel we mark
+ // that state for the final character conversion run which is
+ // done in the next loop iteration.
last = true;
}
@@ -193,21 +171,17 @@ public class ChannelReader extends Reader
converted = Math.min(count, charBuffer.remaining());
charBuffer.get(buf, offset, converted);
- /*
- * Copies characters which have not yet being copied into the char-Array
- * to the beginning making it possible to read them later (If data is
- * really copied here, then the caller has received enough characters so
- * far.).
- */
+ // Copies characters which have not yet being copied into the char-Array
+ // to the beginning making it possible to read them later (If data is
+ // really copied here, then the caller has received enough characters so
+ // far.).
charBuffer.compact();
- /*
- * Updates the control variables according to the latest copy operation.
- */
+ // Updates the control variables according to the latest copy operation.
offset += converted;
count -= converted;
- // Updates the amount of transferred characters
+ // Updates the amount of transferred characters.
sum += converted;
if (decoder == null)
@@ -215,10 +189,8 @@ public class ChannelReader extends Reader
break;
}
- /*
- * Now that more characters have been transfered we let the loop decide
- * what to do next.
- */
+ // Now that more characters have been transfered we let the loop decide
+ // what to do next.
}
// Makes the charBuffer ready for reading on the next invocation.