Android Open Source - RPGWorld File Importer






From Project

Back to project page RPGWorld.

License

The source code is released under:

MIT License

If you think the Android project RPGWorld 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

/**FileImporter.java
 * Daniel Pok/*from w  w w .  j  a  v a2  s  .co m*/
 * AP Java 6th
 * May 24, 2013
 */
package com.nokarateclass.rpgworld.io;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @author dh.dpok
 *
 */
public class FileImporter {
  //variables
  private String fileName;
  private FileInputStream fileIn;
  private ObjectInputStream oIn;
  boolean ready = false;
  
  //Constructor
  public FileImporter(String file){
    fileName = file;
    try {
      fileIn = new FileInputStream(file);
      oIn = new ObjectInputStream(fileIn);
      ready = true;
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      System.err.println("Could not find file \'" + file + "\'.");
      ready = false;
    } catch (IOException e) {
      // TODO Auto-generated catch block
      System.err.println("Could not open file \'" + file + "\'.");
      ready = false;
    }
  }
  
  //getFileName
  public String getFileName(){
    return fileName;
  }
  
  //isReady
  public boolean isReady(){
    return ready;
  }
  
  //Closes the streams associated with this object
  public void close(){
    ready = false;
    try{
      oIn.close();
    } catch(IOException ex){}
    finally{
      oIn = null;
      fileIn = null;
      fileName = "";
    }
  }
  
  //Opens a file, returns ready state
  public boolean open(String file){
    close();
    fileName = file;
    try {
      fileIn = new FileInputStream(file);
      oIn = new ObjectInputStream(fileIn);
      ready = true;
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      System.err.println("Could not find file \'" + file + "\'.");
      ready = false;
    } catch (IOException e) {
      // TODO Auto-generated catch block
      System.err.println("Could not open file \'" + file + "\'.");
      ready = false;
    }
    return isReady();
  }
  
  public Object readObject(){
    try {
      return oIn.readObject();
    } catch (IOException e) {
      System.err.println("Could not read file \'" + fileName + "\'.");
      e.printStackTrace();
      return null;
    } catch (ClassNotFoundException e) {
      System.err.println("Could not read object from \'" + fileName + "\'.");
      return null;
    }
  }
  
  public static Object readObjectFromFile(String file){
    FileImporter in = new FileImporter(file);
    if(in.isReady()){
      Object obj = in.readObject();
      in.close();
      return obj;
    } else {
      return null;
    }
  }
    
}




Java Source Code List

com.nokarateclass.rpgworld.Grid.java
com.nokarateclass.rpgworld.MapEditor.java
com.nokarateclass.rpgworld.backgrounds.BackgroundCharacter.java
com.nokarateclass.rpgworld.backgrounds.GrassBackground.java
com.nokarateclass.rpgworld.backgrounds.SandBackground.java
com.nokarateclass.rpgworld.characters.AndroidCharacter.java
com.nokarateclass.rpgworld.characters.CactusCharacter.java
com.nokarateclass.rpgworld.characters.CharacterActor.java
com.nokarateclass.rpgworld.characters.HeroCharacter.java
com.nokarateclass.rpgworld.characters.MonsterCharacter.java
com.nokarateclass.rpgworld.characters.Player.java
com.nokarateclass.rpgworld.characters.RockCharacter.java
com.nokarateclass.rpgworld.characters.Status.java
com.nokarateclass.rpgworld.characters.TreeCharacter.java
com.nokarateclass.rpgworld.editor.CharacterFactory.java
com.nokarateclass.rpgworld.editor.EditorGrid.java
com.nokarateclass.rpgworld.grid.BackgroundGrid.java
com.nokarateclass.rpgworld.grid.BeatTask.java
com.nokarateclass.rpgworld.grid.CharacterGrid.java
com.nokarateclass.rpgworld.grid.Location.java
com.nokarateclass.rpgworld.grid.MainCharacterGrid.java
com.nokarateclass.rpgworld.io.FileExporter.java
com.nokarateclass.rpgworld.io.FileIO.java
com.nokarateclass.rpgworld.io.FileImporter.java
com.nokarateclass.rpgworld.io.GridSerializer.java
com.nokarateclass.rpgworld.io.SettingsHolder.java
com.nokarateclass.rpgworld.ui.GridClickListener.java
com.nokarateclass.rpgworld.ui.ImageGridView.java
com.nokarateclass.rpgworld.world.Region.java
com.nokarateclass.rpgworld.world.World.java
com.nokarateclass.rpgworld.world.Zone.java