@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)); }
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(); }
@Override public Object load(AssetInfo assetInfo) throws IOException { 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)); }