Package com.stuffwithstuff.magpie.util

Examples of com.stuffwithstuff.magpie.util.FileWriter


  @Def("(is File) writeInt32(is Int)")
  @Doc("Writes the given int to this File.")
  public static class WriteInt implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      FileWriter writer = (FileWriter)left.getValue();
      try {
        writer.writeInt32(right.asInt());
        return right;
      } catch (IOException e) {
        throw context.error("IOError", "Could not write.");
      }
    }
View Full Code Here


  // TODO(bob): Need to support non-ints!
  @Def("(is File) writeDouble(is Int)")
  @Doc("Writes the given number to this File.")
  public static class WriteDouble implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      FileWriter writer = (FileWriter)left.getValue();
      try {
        writer.writeDouble(right.asInt());
        return right;
      } catch (IOException e) {
        throw context.error("IOError", "Could not write.");
      }
    }
View Full Code Here

  @Def("(is File) writeUInt16(is Int)")
  @Doc("Writes the given int to this File.")
  public static class WriteUInt16 implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      FileWriter writer = (FileWriter)left.getValue();
      try {
        writer.writeUInt16(right.asInt());
        return right;
      } catch (IOException e) {
        throw context.error("IOError", "Could not write.");
      }
    }
View Full Code Here

 
  @Def("(is File) writeUInt32(is Int)")
  @Doc("Writes the given int to this File.")
  public static class WriteUInt32 implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      FileWriter writer = (FileWriter)left.getValue();
      try {
        writer.writeUInt32(right.asInt());
        return right;
      } catch (IOException e) {
        throw context.error("IOError", "Could not write.");
      }
    }
View Full Code Here

    public Obj invoke(Context context, Obj left, Obj right) {
      if (left.getValue() instanceof FileReader) {
        FileReader reader = (FileReader)left.getValue();
        reader.close();
      } else {
        FileWriter writer = (FileWriter)left.getValue();
        writer.close();
      }
      return context.nothing();
    }
View Full Code Here

  @Doc("Creates a new file at the given path.")
  public static class Create implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      String path = right.asString();
     
      FileWriter writer;
      try {
        writer = new FileWriter(path);
        return context.instantiate(sFileClass, writer);
      } catch (IOException e) {
        throw context.error("IOError", "Could not open file.");
      }
    }
View Full Code Here

  @Def("(is File) writeByte(is Int)")
  @Doc("Writes the given byte (value from 0 to 255 inclusive) to this File.")
  public static class WriteByte implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      FileWriter writer = (FileWriter)left.getValue();
      try {
        writer.writeByte(right.asInt());
        return right;
      } catch (IOException e) {
        throw context.error("IOError", "Could not write.");
      }
    }
View Full Code Here

TOP

Related Classes of com.stuffwithstuff.magpie.util.FileWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.