Class FileHandles

java.lang.Object
org.projog.core.io.FileHandles

public final class FileHandles extends Object
Collection of input and output streams.

Each KnowledgeBase has a single unique FileHandles instance.

See Also:
  • Field Details

    • USER_OUTPUT_HANDLE

      public static final Atom USER_OUTPUT_HANDLE
      The handle of the "standard" output stream.

      By default the "standard" output stream will be System.out.

    • USER_INPUT_HANDLE

      public static final Atom USER_INPUT_HANDLE
      The handle of the "standard" input stream.

      By default the "standard" input stream will be System.in.

  • Constructor Details

    • FileHandles

      public FileHandles()
  • Method Details

    • getCurrentInputHandle

      public Term getCurrentInputHandle()
      Return the Term representing the current input stream.

      By default this will be an Atom with the name "user_input".

    • getCurrentOutputHandle

      public Term getCurrentOutputHandle()
      Return the Term representing the current output stream.

      By default this will be an Atom with the name "user_output".

    • getCurrentInputStream

      public InputStream getCurrentInputStream()
      Return the current input stream.

      By default this will be System.in.

    • getCurrentOutputStream

      public PrintStream getCurrentOutputStream()
      Return the current output stream.

      By default this will be System.out.

    • setUserInput

      public void setUserInput(InputStream is)
      Reassigns the "standard" input stream.
      See Also:
    • setUserOutput

      public void setUserOutput(PrintStream ps)
      Reassigns the "standard" output stream.
      See Also:
    • setInput

      public void setInput(Term handle)
      Sets the current input stream to the input stream represented by the specified Term.
      Throws:
      ProjogException - if the specified Term does not represent an Atom
    • setOutput

      public void setOutput(Term handle)
      Sets the current output stream to the output stream represented by the specified Term.
      Throws:
      ProjogException - if the specified Term does not represent an Atom
    • openInput

      public Atom openInput(String fileName) throws IOException
      Creates an intput file stream to read from the file with the specified name
      Parameters:
      fileName - the system-dependent filename
      Returns:
      a reference to the newly created stream (as required by setInput(Term) and close(Term))
      Throws:
      ProjogException - if this object's collection of input streams already includes the specified file
      IOException - if the file cannot be opened for reading
    • openOutput

      public Atom openOutput(String fileName) throws IOException
      Creates an output file stream to write to the file with the specified name
      Parameters:
      fileName - the system-dependent filename
      Returns:
      a reference to the newly created stream (as required by setOutput(Term) and close(Term))
      Throws:
      ProjogException - if this object's collection of output streams already includes the specified file
      IOException - if the file cannot be opened
    • close

      public void close(Term handle) throws IOException
      Closes the stream represented by the specified Term.
      Throws:
      ProjogException - if the specified Term does not represent an Atom
      IOException - if an I/O error occurs
    • isHandle

      public boolean isHandle(String handle)