THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
public voidslashSlashComments(boolean flag)

If flag is true, the tokenizer recognizes // to end-of-line comments. This
occurs independently of the settings for any comment characters. The default
is false.

public voidlowerCaseMode(boolean flag)

If flag is TRue, all characters in TT_WORD tokens are converted to their
lowercase equivalent if they have one (using String.toLowerCase).
The default is false. Because of the case issues described in "Character" on
page 192, you cannot reliably use this for Unicode string equivalencetwo
tokens might be equivalent but have different lowercase representations. Use
String.equalsIgnoreCase for reliable case-insensitive comparison.

There are three miscellaneous methods:


public voidpushBack()

Pushes the previously returned token back into the stream. The next
invocation of nextToken returns the same token again instead of
proceeding to the next token. There is only a one-token pushback; multiple
consecutive invocations to pushBack are equivalent to one invocation.

public intlineno()

Returns the current line number. Usually used for reporting errors you detect.

public StringtoString()

Returns a String representation of the last returned stream token, including
its line number.

Exercise 20.6: Write a program that takes input of the form name op value, where name is one of three
words of your choosing, op is +, -, or =, and value is a number. Apply each operator to the named value.
When input is exhausted, print the three values. For extra credit, use the HashMap class that was used for
AttributedImpl so that you can use an arbitrary number of named values.


20.6. The Data Byte Streams


Reading and writing text characters is useful, but you also frequently need to transmit the binary data of
specific types across a stream. The DataInput and DataOutput interfaces define methods that transmit
primitive types across a stream. The classes DataInputStream and DataOutputStream provide a
default implementation for each interface. We cover the interfaces first, followed by their implementations.


20.6.1. DataInput and DataOutput


The interfaces for data input and output streams are almost mirror images. The parallel read and write
methods for each type are


Read Write Type
Free download pdf