public final void readFully(final byte b[]) throws IOException { readFully(b, 0, b.length); }
public final long readLong() throws IOException { return ((readByte() & 0xff) | ((long) (readByte() & 0xff) << 8) | ((long) (readByte() & 0xff) << 16) | ((long) (readByte() & 0xff) << 24) | ((long) (readByte() & 0xff) << 32) | ((long) (readByte() & 0xff) << 40) | ((long) (readByte() & 0xff) << 48) | ((long) (readByte() & 0xff) << 56)); }
public final char readChar() throws IOException { return (char) readUnsignedShort(); }
final LittleEndianRandomAccessDataInput bis = new LittleEndianRandomAccessDataInput(md2Stream); final Md2Header header = new Md2Header(bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt(), bis.readInt()); bis.seek(header.offsetSkins); for (int i = 0; i < header.numSkins; i++) { texNames[i] = bis.readString(64); bis.seek(header.offsetTexCoords); final float inverseWidth = 1f / header.skinWidth; final float inverseHeight = 1f / header.skinHeight; for (int i = 0; i < header.numTexCoords; i++) { texCoords[i * 2 + 0] = bis.readShort() * inverseWidth; texCoords[i * 2 + 1] = bis.readShort() * inverseHeight; bis.seek(header.offsetTriangles); for (int i = 0; i < header.numTriangles; i++) { triangles[i * 6 + 0] = bis.readShort(); // vert index 0 triangles[i * 6 + 1] = bis.readShort(); // vert index 1 triangles[i * 6 + 2] = bis.readShort(); // vert index 2 triangles[i * 6 + 3] = bis.readShort(); // texcoord index 0 triangles[i * 6 + 4] = bis.readShort(); // texcoord index 1 triangles[i * 6 + 5] = bis.readShort(); // texcoord index 2 bis.seek(header.offsetGlCommands); int length, absLength;
@Test public void testReadUint() throws Exception { // test reading of uint vs int. final byte[] data = new byte[4]; data[0] = (byte) 0xff; data[1] = (byte) 0xff; data[2] = (byte) 0xff; data[3] = (byte) 0xff; final ByteArrayInputStream bais = new ByteArrayInputStream(data); final LittleEndianRandomAccessDataInput littleEndien = new LittleEndianRandomAccessDataInput(bais); final long val = littleEndien.readUnsignedInt(); assertTrue(val == 4294967295L); littleEndien.seek(0); final int val2 = littleEndien.readInt(); assertTrue(val2 == -1); } }
/** * 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; }
public final float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
/** * 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. Will use the platform's * default Charset to convert the bytes to string. * * @param size * the length of the string to read. * @return the string read. * @throws IOException * if EOS/EOF is reached before "size" number of bytes are read. */ public String readString(final int size) throws IOException { return readString(size, Charset.defaultCharset()); }
public final double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
/** * 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; }
public final float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
/** * 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. Will use the platform's * default Charset to convert the bytes to string. * * @param size * the length of the string to read. * @return the string read. * @throws IOException * if EOS/EOF is reached before "size" number of bytes are read. */ public String readString(final int size) throws IOException { return readString(size, Charset.defaultCharset()); }
public final double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
public final long readLong() throws IOException { return ((readByte() & 0xff) | ((long) (readByte() & 0xff) << 8) | ((long) (readByte() & 0xff) << 16) | ((long) (readByte() & 0xff) << 24) | ((long) (readByte() & 0xff) << 32) | ((long) (readByte() & 0xff) << 40) | ((long) (readByte() & 0xff) << 48) | ((long) (readByte() & 0xff) << 56)); }
public final void readFully(final byte b[]) throws IOException { readFully(b, 0, b.length); }
public final short readShort() throws IOException { return (short) readUnsignedShort(); }
public final char readChar() throws IOException { return (char) readUnsignedShort(); }
public final short readShort() throws IOException { return (short) readUnsignedShort(); }