public final void readFully(final byte b[]) throws IOException { readFully(b, 0, b.length); }
public final void readFully(final byte b[]) throws IOException { readFully(b, 0, b.length); }
/** * Reads a specified number of bytes to form a string. The length of the string (number of characters) is required * to notify when reading should stop. The index is increased the number of characters read. * * @param size * the length of the string to read. * @param charset * the charset used to convert the bytes to a string. * @return the string read. * @throws IOException * if EOS/EOF is reached before "size" number of bytes are read. */ public String readString(final int size, final Charset charset) throws IOException { final int start = position(); final byte[] content = new byte[size]; readFully(content); seek(start + size); int indexOfNullByte = size; // Look for zero terminated string from byte array for (int i = 0; i < size; i++) { if (content[i] == 0) { indexOfNullByte = i; break; } } final String s = new String(content, 0, indexOfNullByte, charset); return s; }
/** * Reads a specified number of bytes to form a string. The length of the string (number of characters) is required * to notify when reading should stop. The index is increased the number of characters read. * * @param size * the length of the string to read. * @param charset * the charset used to convert the bytes to a string. * @return the string read. * @throws IOException * if EOS/EOF is reached before "size" number of bytes are read. */ public String readString(final int size, final Charset charset) throws IOException { final int start = position(); final byte[] content = new byte[size]; readFully(content); seek(start + size); int indexOfNullByte = size; // Look for zero terminated string from byte array for (int i = 0; i < size; i++) { if (content[i] == 0) { indexOfNullByte = i; break; } } final String s = new String(content, 0, indexOfNullByte, charset); return s; }
final String name = bis.readString(16); final byte[] vertData = new byte[header.numVertices * 4]; bis.readFully(vertData); frames[i] = new Md2Frame(vertData, name, scale, translate);