Asset.java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.blue5alamander.planet.android;

import android.content.res.AssetManager;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class Asset {
    public static native void useManager(AssetManager assetManager);

    public static byte[] loader(AssetManager am, String fn) {
        try {
            InputStream in = am.open(fn);
            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            byte[] buffer = new byte[10240];
            for (int length = in.read(buffer); length != -1; length = in.read(buffer)) {
                stream.write(buffer, 0, length);
            }
            return stream.toByteArray();
        } catch (IOException e ) {
            return null;
        }
    }
}