Android Open Source - RPGWorld File Exporter






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

/**FileExporter.java
 * Daniel Pok/* www  . ja v  a  2  s .  c  om*/
 * AP Java 6th
 * May 24, 2013
 */
package com.nokarateclass.rpgworld.io;

import java.io.Externalizable;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * @author dh.dpok
 *
 */
public class FileExporter {
  //variables
  private String fileName;
  private FileOutputStream fileOut;
  private ObjectOutputStream oOut;
  boolean ready = false;
  
  //Constructor
  public FileExporter(String file){
    fileName = file;
    try {
      fileOut = new FileOutputStream(file);
      oOut = new ObjectOutputStream(fileOut);
      ready = true;
    } 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{
      oOut.close();
    } catch(IOException ex){}
    finally{
      oOut = null;
      fileOut = null;
      fileName = "";
    }
  }
  
  //Opens a file, returns ready state
  public boolean open(String file){
    close();
    fileName = file;
    try {
      fileOut = new FileOutputStream(file);
      oOut = new ObjectOutputStream(fileOut);
      ready = true;
    } catch (IOException e) {
      // TODO Auto-generated catch block
      System.err.println("Could not open file \'" + file + "\'.");
      ready = false;
    }
    return isReady();
  }
  
  public boolean writeObject(Object obj){
    if(!(obj instanceof Serializable || obj instanceof Externalizable)){
      System.err.println("The object cannot be written to the stream because it is not serializable or externalizable.");
    }
    try {
      //System.out.println("Stream is " + (isReady()? "ready" : "not ready"));
      oOut.writeObject(obj);
      oOut.flush();
      return true;
    } catch (IOException e) {
      System.err.println("Could not write file \'" + fileName + "\'.");
      e.printStackTrace();
      return false;
    }
  }
  
  public static boolean writeObjectToFile(String file, Object obj){
    FileExporter out = new FileExporter(file);
    if(out.isReady()){
      Boolean result = out.writeObject(obj);
      out.close();
      return result;
    } else {
      return false;
    }
  }
}




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