Package org.projog.core.io
Class FileHandles
- java.lang.Object
-
- org.projog.core.io.FileHandles
-
public final class FileHandles extends java.lang.ObjectCollection of input and output streams.Each
KnowledgeBasehas a single uniqueFileHandlesinstance.- See Also:
KnowledgeBase.getFileHandles()
-
-
Field Summary
Fields Modifier and Type Field Description private TermcurrentInputHandleCurrent input used by get_char and readprivate TermcurrentOutputHandleCurrent output used by put_char, nl, write and write_canonicalprivate java.io.InputStreaminprivate java.util.Map<java.lang.String,java.io.InputStream>inputHandlesprivate java.lang.Objectlockprivate java.io.PrintStreamoutprivate java.util.Map<java.lang.String,java.io.PrintStream>outputHandlesstatic AtomUSER_INPUT_HANDLEThe handle of the "standard" input stream.static AtomUSER_OUTPUT_HANDLEThe 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 voidclose(Term handle)Closes the stream represented by the specifiedTerm.TermgetCurrentInputHandle()Return theTermrepresenting the current input stream.java.io.InputStreamgetCurrentInputStream()Return the current input stream.TermgetCurrentOutputHandle()Return theTermrepresenting the current output stream.java.io.PrintStreamgetCurrentOutputStream()Return the current output stream.booleanisHandle(java.lang.String handle)AtomopenInput(java.lang.String fileName)Creates an intput file stream to read from the file with the specified nameAtomopenOutput(java.lang.String fileName)Creates an output file stream to write to the file with the specified namevoidsetInput(Term handle)Sets the current input stream to the input stream represented by the specifiedTerm.voidsetOutput(Term handle)Sets the current output stream to the output stream represented by the specifiedTerm.voidsetUserInput(java.io.InputStream is)Reassigns the "standard" input stream.voidsetUserOutput(java.io.PrintStream ps)Reassigns the "standard" output stream.
-
-
-
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
-
-
Method Detail
-
getCurrentInputHandle
public Term getCurrentInputHandle()
Return theTermrepresenting the current input stream.By default this will be an
Atomwith the name "user_input".
-
getCurrentOutputHandle
public Term getCurrentOutputHandle()
Return theTermrepresenting the current output stream.By default this will be an
Atomwith 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 specifiedTerm.- Throws:
ProjogException- if the specifiedTermdoes not represent anAtom
-
setOutput
public void setOutput(Term handle)
Sets the current output stream to the output stream represented by the specifiedTerm.- Throws:
ProjogException- if the specifiedTermdoes not represent anAtom
-
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)andclose(Term)) - Throws:
ProjogException- if this object's collection of input streams already includes the specified filejava.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)andclose(Term)) - Throws:
ProjogException- if this object's collection of output streams already includes the specified filejava.io.IOException- if the file cannot be opened
-
close
public void close(Term handle) throws java.io.IOException
Closes the stream represented by the specifiedTerm.- Throws:
ProjogException- if the specifiedTermdoes not represent anAtomjava.io.IOException- if an I/O error occurs
-
isHandle
public boolean isHandle(java.lang.String handle)
-
-