Android Open Source - misty Assets






From Project

Back to project page misty.

License

The source code is released under:

MIT License

If you think the Android project misty listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.misty.utils;
//  w w  w  . j a  va 2s .c  o  m
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.content.res.AssetFileDescriptor;

public class Assets
{
  private static Context context;
  
  public static void initialize(Context context)
  {
    Assets.context = context;
  }
  
  public static InputStream getInputStream(String path) throws IOException
  {
    return Assets.context.getAssets().open(path);
  }
  
  public static AssetFileDescriptor getAssetFileDescriptor(String path) throws IOException
  {
    return Assets.context.getAssets().openFd(path);
  }
  
  public static JSONObject getJsonObject(String path) throws IOException, JSONException
  {
    String content = Assets.readFile(path);
    
    return new JSONObject(content);
  }
  
  public static String readFile(String path) throws IOException
  {
    String result = "";
    
    InputStream inputStream = null;
    
    try
    {
      inputStream = Assets.getInputStream(path);
      result = Assets.readInputStreamAsString(inputStream);
    }
    finally
    {
      Assets.close(inputStream);
    }
    
    return result;
  }
  
  private static String readInputStreamAsString(InputStream inputStream) throws IOException
  {
    String result = "";
    
    Reader reader = null;
    
    try
    {
      reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
      StringBuilder builder = new StringBuilder();
      int data = 0;
      
      while ((data = reader.read()) != -1)
      {
        builder.append((char)data);
      }
      
      result = builder.toString();
    }
    finally
    {
      Assets.close(reader);
    }
    
    return result;
  }
  
  public static void close(Closeable resource)
  {
    if (resource != null)
    {
      try
      {
        resource.close();
      }
      catch (IOException e)
      {
      }
    }
  }
}




Java Source Code List

com.misty.audio.AudioManager.java
com.misty.debug.FPS.java
com.misty.debug.TimeCounter.java
com.misty.graphics.Animation.java
com.misty.graphics.Camera.java
com.misty.graphics.CollisionGrid.java
com.misty.graphics.Renderer.java
com.misty.graphics.ScreenResolution.java
com.misty.graphics.textures.TextureManager.java
com.misty.graphics.textures.Texture.java
com.misty.input.TouchEvent.java
com.misty.kernel.Alarm.java
com.misty.kernel.Engine.java
com.misty.kernel.Misty.java
com.misty.kernel.Process.java
com.misty.math.Rectangle.java
com.misty.math.Utils.java
com.misty.math.Vector.java
com.misty.utils.Assets.java