/** * 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; }
@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); } }
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; bis.seek(header.offsetTriangles); for (int i = 0; i < header.numTriangles; i++) { triangles[i * 6 + 0] = bis.readShort(); // vert index 0 bis.seek(header.offsetGlCommands); int length, absLength; Md2GlCommand cmd; bis.seek(header.offsetFrames); final Vector3 scale = new Vector3(); final Vector3 translate = new Vector3();