Class FileHandles

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Term currentInputHandle
      Current input used by get_char and read
      private Term currentOutputHandle
      Current output used by put_char, nl, write and write_canonical
      private java.io.InputStream in  
      private java.util.Map<java.lang.String,​java.io.InputStream> inputHandles  
      private java.lang.Object lock  
      private java.io.PrintStream out  
      private java.util.Map<java.lang.String,​java.io.PrintStream> outputHandles  
      static Atom USER_INPUT_HANDLE
      The handle of the "standard" input stream.
      static Atom USER_OUTPUT_HANDLE
      The handle of the "standard" output stream.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileHandles()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close​(Term handle)
      Closes the stream represented by the specified Term.
      Term getCurrentInputHandle()
      Return the Term representing the current input stream.
      java.io.InputStream getCurrentInputStream()
      Return the current input stream.
      Term getCurrentOutputHandle()
      Return the Term representing the current output stream.
      java.io.PrintStream getCurrentOutputStream()
      Return the current output stream.
      boolean isHandle​(java.lang.String handle)  
      Atom openInput​(java.lang.String fileName)
      Creates an intput file stream to read from the file with the specified name
      Atom openOutput​(java.lang.String fileName)
      Creates an output file stream to write to the file with the specified name
      void setInput​(Term handle)
      Sets the current input stream to the input stream represented by the specified Term.
      void setOutput​(Term handle)
      Sets the current output stream to the output stream represented by the specified Term.
      void setUserInput​(java.io.InputStream is)
      Reassigns the "standard" input stream.
      void setUserOutput​(java.io.PrintStream ps)
      Reassigns the "standard" output stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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.

      • lock

        private final java.lang.Object lock
      • inputHandles

        private final java.util.Map<java.lang.String,​java.io.InputStream> inputHandles
      • outputHandles

        private final java.util.Map<java.lang.String,​java.io.PrintStream> outputHandles
      • currentInputHandle

        private Term currentInputHandle
        Current input used by get_char and read
      • currentOutputHandle

        private Term currentOutputHandle
        Current output used by put_char, nl, write and write_canonical
      • in

        private java.io.InputStream in
      • out

        private java.io.PrintStream out
    • Constructor Detail

      • FileHandles

        public FileHandles()
    • Method Detail

      • 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 java.io.InputStream getCurrentInputStream()
        Return the current input stream.

        By default this will be System.in.

      • getCurrentOutputStream

        public java.io.PrintStream getCurrentOutputStream()
        Return the current output stream.

        By default this will be System.out.

      • setUserInput

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

        public void setUserOutput​(java.io.PrintStream ps)
        Reassigns the "standard" output stream.
        See Also:
        USER_OUTPUT_HANDLE
      • 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​(java.lang.String fileName)
                       throws java.io.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
        java.io.IOException - if the file cannot be opened for reading
      • openOutput

        public Atom openOutput​(java.lang.String fileName)
                        throws java.io.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
        java.io.IOException - if the file cannot be opened
      • close

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

        public boolean isHandle​(java.lang.String handle)