/** * Reads a given number of chars from the stream * * @param dis * the stream to read * @param num * the number of chars to read * @return a character array containing the next <code>num</code> in the stream * * @throws IOException * if an error occurs */ public static char[] readChars(DataInputStream dis, int num) throws IOException { char[] carray = new char[num]; for (int i = 0; i < num; i++) { carray[i] = readChar(dis); } return carray; }
/** * Reads a given number of chars from the stream * * @param dis * the stream to read * @param num * the number of chars to read * @return a character array containing the next <code>num</code> in the stream * * @throws IOException * if an error occurs */ public static char[] readChars(DataInputStream dis, int num) throws IOException { char[] carray = new char[num]; for (int i = 0; i < num; i++) { carray[i] = readChar(dis); } return carray; }
/** * Reads the next word (text separated by whitespace) from the given stream * * @param dis * the input stream * * @return the next word * * @throws IOException * on error */ public static String readWord(DataInputStream dis) throws IOException { StringBuilder sb = new StringBuilder(); char c; // skip leading whitespace do { c = readChar(dis); } while (Character.isWhitespace(c)); // read the word do { sb.append(c); c = readChar(dis); } while (!Character.isWhitespace(c)); return sb.toString(); }
/** * Reads the next word (text separated by whitespace) from the given stream * * @param dis * the input stream * * @return the next word * * @throws IOException * on error */ public static String readWord(DataInputStream dis) throws IOException { StringBuilder sb = new StringBuilder(); char c; // skip leading whitespace do { c = readChar(dis); } while (Character.isWhitespace(c)); // read the word do { sb.append(c); c = readChar(dis); } while (!Character.isWhitespace(c)); return sb.toString(); }