ReaderRead - mehdimo/janett GitHub Wiki

Note:This feature will be available in later releases.

java.io.Reader.read in Java returns -1 if end of the stream has been reached but similar method in .Net (System.IO.TextReader.Read) returns number of characters read, so it returns 0 if end of the stream has been reached.

Java code (from Lucene) like this:

while (true) {
    length = input.read(this.buffer);
    if (length == -1) break;
    buffer.append(this.buffer, 0, length);
}

will fail in .Net.

instead of patching resulting code or translating it to:

while (true) {
    length = ConvertReaderReadReturn(input.read(this.buffer));
    if (length == -1) break;
    buffer.append(this.buffer, 0, length);
}

we can write more or less intelligent classes which can translate it to:

while (true) {
    length = input.read(this.buffer);
    if (length == 0) break;
    buffer.append(this.buffer, 0, length);
}

This would be hard in some situations but reusability across projects is worth the effort.

We call these transformers Adapter.