Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed comment about java pushbackInpuStream code translated to C#
    primarykey
    data
    text
    <p>This is the original java code it includes the <strong>PushbackInputStream</strong> class</p> <pre><code>public String readLine(InputStream in) throws IOException { char buf[] = new char[128]; int offset = 0; int ch; for (;;) { ch = in.read(); if (ch == -1 || ch == '\n') { break; } else if (ch == '\r') { int tmpch = in.read(); if (tmpch != '\n') { if (! (in instanceof PushbackInputStream))PushbackInputStream)) { in = new PushbackInputStream(in); } ((PushbackInputStream) in).unread(tmpch); } break; } else { if (offset == buf.length) { char tmpbuf[] = buf; buf = new char[tmpbuf.length * 2]; System.arraycopy(tmpbuf, 0, buf, 0, offset); } buf[offset++] = (char) ch; } } return String.copyValueOf(buf, 0, offset); } </code></pre> <p>Here is what i converted to C# , I implemented the <strong>PushbackInputstream</strong> with the <strong>peek</strong> method of the <strong>StreamReader</strong> class, however there is a keyword that i could not decipher like instanceof. Does the keyword "instanceof" matter in this situation? </p> <pre><code> public String readLine(NetworkStream nsStream) { using (StreamReader reader = new StreamReader(nsStream)) { char[] buffer = new char[128]; int offset = 0; int ch; for (; ; ) { ch = reader.Read(); if (ch == -1 || ch == '\n') { break; } else if (ch == '\r') { if ((reader.Peek()) == '\n') { break; } else { reader.Read(); } } else { if (offset == buffer.Length) { char[] tempBuffer = buffer; buffer = new char[tempBuffer.Length * 2]; Array.Copy(tempBuffer, 0, buffer, 0, offset); } buffer[offset++] = (char)ch; } } return new string(buffer); } } </code></pre> <p>Any comment would be appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload