Class Scanner


  • public class Scanner
    extends java.lang.Object
    Splits up a character stream into tokens and returns them as String objects.
    • Constructor Summary

      Constructors 
      Constructor Description
      Scanner​(java.io.File file)
      Deprecated.
      This method is deprecated because it leaves the input file open
      Scanner​(java.io.File file, java.lang.String encoding)
      Deprecated.
      This method is deprecated because it leaves the input file open
      Scanner​(java.lang.String fileName)
      Deprecated.
      This method is deprecated because it leaves the input file open
      Scanner​(java.lang.String fileName, java.io.InputStream is)
      Sets up a scanner that reads tokens from the given InputStream in the platform default encoding.
      Scanner​(java.lang.String fileName, java.io.InputStream is, java.lang.String encoding)
      Sets up a scanner that reads tokens from the given InputStream with the given encoding (null means platform default encoding).
      Scanner​(java.lang.String fileName, java.io.Reader in)
      Sets up a scanner that reads tokens from the given Reader.
      Scanner​(java.lang.String fileName, java.io.Reader in, int initialLineNumber, int initialColumnNumber)
      Creates a Scanner that counts lines and columns from non-default initial values.
      Scanner​(java.lang.String fileName, java.lang.String encoding)
      Deprecated.
      This method is deprecated because it leaves the input file open
    • Field Detail

      • SYSTEM_PROPERTY_SOURCE_DEBUGGING_ENABLE

        public static final java.lang.String SYSTEM_PROPERTY_SOURCE_DEBUGGING_ENABLE
        Setting this system property to 'true' enables source-level debugging. Typically, this means that compilation is executed with "-g:all" instead of "-g:none".
        See Also:
        Constant Field Values
      • SYSTEM_PROPERTY_SOURCE_DEBUGGING_DIR

        public static final java.lang.String SYSTEM_PROPERTY_SOURCE_DEBUGGING_DIR
        If the source code is not read from a file, debuggers have a hard time locating the source file for source-level debugging. As a workaround, a copy of the source code is written to a temporary file, which must be included in the debugger's source path. If this system property is set, the temporary source file is created in that directory, otherwise in the default temporary-file directory.
        See Also:
        File.createTempFile(String, String, File), Constant Field Values
      • SYSTEM_PROPERTY_SOURCE_DEBUGGING_KEEP

        public static final java.lang.String SYSTEM_PROPERTY_SOURCE_DEBUGGING_KEEP
        If set to "true", then the temporary source code files are not deleted on exit. That may be useful to interpret stack traces offline.
        See Also:
        Constant Field Values
    • Constructor Detail

      • Scanner

        @Deprecated
        public Scanner​(java.lang.String fileName)
                throws java.io.IOException
        Deprecated.
        This method is deprecated because it leaves the input file open
        Throws:
        java.io.IOException
      • Scanner

        @Deprecated
        public Scanner​(java.lang.String fileName,
                       java.lang.String encoding)
                throws java.io.IOException
        Deprecated.
        This method is deprecated because it leaves the input file open
        Throws:
        java.io.IOException
      • Scanner

        @Deprecated
        public Scanner​(java.io.File file)
                throws java.io.IOException
        Deprecated.
        This method is deprecated because it leaves the input file open
        Throws:
        java.io.IOException
      • Scanner

        @Deprecated
        public Scanner​(java.io.File file,
                       @Nullable
                       java.lang.String encoding)
                throws java.io.IOException
        Deprecated.
        This method is deprecated because it leaves the input file open
        Throws:
        java.io.IOException
      • Scanner

        public Scanner​(@Nullable
                       java.lang.String fileName,
                       java.io.InputStream is)
                throws java.io.IOException
        Sets up a scanner that reads tokens from the given InputStream in the platform default encoding.

        The fileName is solely used for reporting in thrown exceptions.

        Throws:
        java.io.IOException
      • Scanner

        public Scanner​(@Nullable
                       java.lang.String fileName,
                       java.io.InputStream is,
                       @Nullable
                       java.lang.String encoding)
                throws java.io.IOException
        Sets up a scanner that reads tokens from the given InputStream with the given encoding (null means platform default encoding).

        The fileName is used for reporting errors during compilation and for source level debugging, and should name an existing file. If null is passed, and the system property org.codehaus.janino.source_debugging.enable is set to "true", then a temporary file in org.codehaus.janino.source_debugging.dir or the system's default temp dir is created in order to make the source code available to a debugger.

        Throws:
        java.io.IOException
      • Scanner

        public Scanner​(@Nullable
                       java.lang.String fileName,
                       java.io.Reader in)
                throws java.io.IOException
        Sets up a scanner that reads tokens from the given Reader.

        The fileName is used for reporting errors during compilation and for source level debugging, and should name an existing file. If null is passed, and the system property org.codehaus.janino.source_debugging.enable is set to "true", then a temporary file in org.codehaus.janino.source_debugging.dir or the system's default temp dir is created in order to make the source code available to a debugger.

        Throws:
        java.io.IOException
      • Scanner

        public Scanner​(@Nullable
                       java.lang.String fileName,
                       java.io.Reader in,
                       int initialLineNumber,
                       int initialColumnNumber)
                throws java.io.IOException
        Creates a Scanner that counts lines and columns from non-default initial values.
        Throws:
        java.io.IOException
    • Method Detail

      • setIgnoreWhiteSpace

        public void setIgnoreWhiteSpace​(boolean value)
        If value is true, then white space in the input stream is ignored, rather than scanned as a TokenType.WHITE_SPACE token. Since white space is typically quite numerous, this optimization may save considerable overhead.
      • getFileName

        @Nullable
        public java.lang.String getFileName()
        Returns:
        The file name optionally passed to the constructor
      • close

        @Deprecated
        public void close()
                   throws java.io.IOException
        Deprecated.
        This method is deprecated, because the concept described above is confusing. An application should close the underlying InputStream or Reader itself
        Closes the character source (file, InputStream, Reader) associated with this object. The results of future calls to produce() are undefined.
        Throws:
        java.io.IOException
      • location

        public Location location()
        Returns:
        The Location of the previously read (or peeked) token.