public static LittleEndien getStream(byte[] buffer) { return new LittleEndien(new DataInputStream(new ByteArrayInputStream(buffer))); }
@Override public Object load(AssetInfo assetInfo) throws IOException { data.clear(); LittleEndien stream = new LittleEndien(new DataInputStream(assetInfo.openStream())); int magic = stream.readInt(); int version = stream.readInt(); int length = stream.readInt(); byte[] json = null; //length is the total size, we have to remove the header size (3 integers = 12 bytes). length -= 12; while (length > 0) { int chunkLength = stream.readInt(); int chunkType = stream.readInt(); if (chunkType == JSON_TYPE) { json = new byte[chunkLength]; stream.read(json); } else { byte[] bin = new byte[chunkLength]; stream.read(bin); data.add(bin); } //8 is the byte size of the 2 ints chunkLength and chunkType. length -= chunkLength + 8; } return loadFromStream(assetInfo, new ByteArrayInputStream(json)); }
bis = new BufferedInputStream(stream); if (format == RawHeightMap.FORMAT_16BITLE) { LittleEndien dis = new LittleEndien(bis); int index; index = (i * size) + j; heightData[index] = dis.readUnsignedShort(); dis.close(); } else { DataInputStream dis = new DataInputStream(bis);
private static void populateIntBuffer(IntBuffer buffer, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); while (index < end) { for (int i = 0; i < numComponents; i++) { buffer.put(stream.readInt()); } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateByteArray(byte[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { array[arrayIndex] = stream.readByte(); arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateShortArray(short[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { if (componentSize == 2) { array[arrayIndex] = stream.readShort(); } else { array[arrayIndex] = stream.readByte(); } arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private AudioData load(InputStream inputStream, boolean stream) throws IOException{ this.in = new LittleEndien(inputStream); int sig = in.readInt(); if (sig != i_RIFF) throw new IOException("File is not a WAVE file"); in.readInt(); if (in.readInt() != i_WAVE) throw new IOException("WAVE File does not contain audio"); int type = in.readInt(); int len = in.readInt(); int skipped = in.skipBytes(len); if (skipped <= 0) { return null;
int compression = in.readShort(); if (compression != 1){ throw new IOException("WAV Loader only supports PCM wave files"); int channels = in.readShort(); int sampleRate = in.readInt(); bytesPerSec = in.readInt(); // used to calculate duration int bytesPerSample = in.readShort(); int bitsPerSample = in.readShort(); in.skipBytes(remaining);
public short readShort() throws IOException { return (short) this.readUnsignedShort(); }
private static void populateFloatArray(float[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { array[arrayIndex] = readAsFloat(stream, format); arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
private static void populateShortBuffer(ShortBuffer buffer, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); while (index < end) { for (int i = 0; i < numComponents; i++) { buffer.put(stream.readShort()); } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } System.err.println(""); }
private void readDataChunkForBuffer(int len) throws IOException { ByteBuffer data = BufferUtils.createByteBuffer(len); byte[] buf = new byte[512]; int read = 0; while ( (read = in.read(buf)) > 0){ data.put(buf, 0, Math.min(read, data.remaining()) ); } data.flip(); audioBuffer.updateData(data); in.close(); }
public double readDouble() throws IOException { return Double.longBitsToDouble(readLong()); }
public char readChar() throws IOException { return (char) this.readUnsignedShort(); }
private static void populateIntBuffer(IntBuffer buffer, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); while (index < end) { for (int i = 0; i < numComponents; i++) { buffer.put(stream.readInt()); } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateShortArray(short[] array, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); int arrayIndex = 0; while (index < end) { for (int i = 0; i < numComponents; i++) { if (componentSize == 2) { array[arrayIndex] = stream.readShort(); } else { array[arrayIndex] = stream.readByte(); } arrayIndex++; } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
private static void populateFloatBuffer(FloatBuffer buffer, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); while (index < end) { for (int i = 0; i < numComponents; i++) { buffer.put(readAsFloat(stream, format)); } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } }
public float readFloat() throws IOException { return Float.intBitsToFloat(readInt()); }
private static void populateShortBuffer(ShortBuffer buffer, LittleEndien stream, int count, int byteOffset, int byteStride, int numComponents, VertexBuffer.Format format) throws IOException { int componentSize = format.getComponentSize(); int index = byteOffset; int dataLength = componentSize * numComponents; int stride = Math.max(dataLength, byteStride); int end = count * stride + byteOffset; stream.skipBytes(byteOffset); while (index < end) { for (int i = 0; i < numComponents; i++) { buffer.put(stream.readShort()); } if (dataLength < stride) { stream.skipBytes(stride - dataLength); } index += stride; } System.err.println(""); }