public String read(int n) throws IOException { if (n < 0) { n = (int) (file.length() - filePosition); if (n < 0) n = 0; } byte[] buf = new byte[n]; n = readBytes(buf, 0, n); if (n < 0) n = 0; return PyString.from_bytes(buf, 0, n); }
public String read(int n) throws IOException { if (n == 0) // nothing to do return ""; if (n < 0) { // read until we hit EOF byte buf[] = new byte[1024]; StringBuffer sbuf = new StringBuffer(); for (int read = 0; read >= 0; read = istream.read(buf)) sbuf.append(PyString.from_bytes(buf, 0, read)); return sbuf.toString(); } // read the next chunk available, but make sure it's at least // one byte so as not to trip the `empty string' return value // test done by the caller // int avail = istream.available(); // n = (n > avail) ? n : avail; byte buf[] = new byte[n]; int read = istream.read(buf); if (read < 0) // EOF encountered return ""; return PyString.from_bytes(buf, 0, read); }