Package com.stuffwithstuff.magpie.util

Examples of com.stuffwithstuff.magpie.util.FileReader


  @Def("(is File) close()")
  @Doc("Closes the file.")
  public static class Close implements Intrinsic {
    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("Opens the file at the given path.")
  public static class Open implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      String path = right.asString();
     
      FileReader reader;
      try {
        reader = new FileReader(path);
        return context.instantiate(sFileClass, reader);
      } catch (IOException e) {
        throw context.error("IOError", "Could not open file.");
      }
    }
View Full Code Here

 
  @Def("(is File) isOpen")
  @Doc("Returns true if the file is open.")
  public static class IsOpen implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      FileReader reader = (FileReader)left.getValue();
      return context.toObj(reader.isOpen());
    }
View Full Code Here

 
  @Def("(is File) read()")
  @Doc("Reads the contents of the file as a string.")
  public static class Read implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      FileReader reader = (FileReader)left.getValue();
      try {
        String contents = reader.readAll();
        if (contents == null) return context.nothing();
        return context.toObj(contents);
      } catch (IOException e) {
        throw context.error("IOError", "Could not read.");
      }
View Full Code Here

  @Def("(is File) readLine()")
  @Doc("Reads a single line of text from the file. Returns nothing if at\n" +
       "the end of the file.")
  public static class ReadLine implements Intrinsic {
    public Obj invoke(Context context, Obj left, Obj right) {
      FileReader reader = (FileReader)left.getValue();
      try {
        String line = reader.readLine();
        if (line == null) return context.nothing();
        return context.toObj(line);
      } catch (IOException e) {
        throw context.error("IOError", "Could not read.");
      }
View Full Code Here

TOP

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

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.