/** * Skips n bytes from the stream. If the end of * the stream has been reached before reading n bytes, * then it returns. * <B>NB:</B> This method uses read() internally. * @param n long the number of bytes to skip. * @return long the number of bytes skipped. * @throws IOException if there is any error while * reading from the stream. */ public long skip(long n) throws IOException { /* TODO a more efficient implementation could be made */ long i = 0; for (; i < n && this.ready(); i++) { this.read(); } return i; } /**
/** * Read bytes into an array. This method will read 100 bytes or the array length, * and until the end of the stream is reached. * <B>NB:</B> Uses read() internally. * @param cbuf cbuf - Destination buffer * @return The number of bytes read, or -1 if the end of the stream has been reached. * @throws IOException If an I/O error occurs */ @Override public int read(byte[] cbuf) throws IOException { if (EOF) return -1; int ReadSize = 100; if (ReadSize > cbuf.length) ReadSize = cbuf.length; int i=0; for(;i<ReadSize;i++) { int c = this.read(); if (c == -1) return i-1; else cbuf[i] = (byte)c;//safe, as this.read() returns -1 to 255, and c!=-1 } return i; } /**
/** * Skips n bytes from the stream. If the end of * the stream has been reached before reading n bytes, * then it returns. * <B>NB:</B> This method uses read() internally. * @param n long the number of bytes to skip. * @return long the number of bytes skipped. * @throws IOException if there is any error while * reading from the stream. */ public long skip(long n) throws IOException { /* TODO a more efficient implementation could be made */ long i = 0; for (; i < n && this.ready(); i++) { this.read(); } return i; } /**
/** * Read bytes into an array. This method will read 100 bytes or the array length, * and until the end of the stream is reached. * <B>NB:</B> Uses read() internally. * @param cbuf cbuf - Destination buffer * @return The number of bytes read, or -1 if the end of the stream has been reached. * @throws IOException If an I/O error occurs */ @Override public int read(byte[] cbuf) throws IOException { if (EOF) return -1; int ReadSize = 100; if (ReadSize > cbuf.length) ReadSize = cbuf.length; int i=0; for(;i<ReadSize;i++) { int c = this.read(); if (c == -1) return i-1; else cbuf[i] = (byte)c;//safe, as this.read() returns -1 to 255, and c!=-1 } return i; } /**