All Packages Class Hierarchy This Package Previous Next Index
Class org.ifarchive.glk.Stream
java.lang.Object
|
+----org.ifarchive.glk.OpaqueObject
|
+----org.ifarchive.glk.Stream
- public class Stream
- extends OpaqueObject
All character output in Glk is done through streams. Every window has an
output stream associated with it. You can also write to files on disk;
every open file is represented by an output stream as well.
There are also input streams; these are used for reading from files
on disk. It is possible for a stream to be both an input and an output
stream.
It is also possible to create a stream that reads or writes to a buffer
in memory.
-
seekmode_Current
- Seek to pos characters after the current position.
-
seekmode_End
- Seek to pos characters after the beginning of the file.
-
seekmode_Start
- Seek to pos characters after the beginning of the file.
-
style_Alert
- Text which warns of a dangerous condition, or one which
the player should pay attention to.
-
style_BlockQuote
- Text which forms a quotation or otherwise abstracted text.
-
style_Emphasized
- Text which is emphasized.
-
style_Header
- Text which introduces a large section.
-
style_Input
- Text which the player has entered.
-
style_Normal
- The style of normal or body text.
-
style_Note
- Text which notifies of an interesting condition.
-
style_NUMSTYLES
- The number of styles this library supports.
-
style_Preformatted
- Text which has a particular arrangement of characters.
-
style_Subheader
- Text which introduces a smaller section within a large section.
-
style_User1
- This style has no particular semantic meaning.
-
style_User2
- This style has no particular semantic meaning.
-
stylehint_BackColor
- The background color behind the text.
-
stylehint_Indentation
- How much to indent lines of text in the given style.
-
stylehint_just_Centred
- Text will be centred.
-
stylehint_just_LeftFlush
- Text will be left aligned.
-
stylehint_just_LeftRight
- Text will be fully justified.
-
stylehint_just_RightFlush
- Text will be right aligned.
-
stylehint_Justification
- How to justify text.
-
stylehint_NUMHINTS
- The number of stylehints this library knows about.
-
stylehint_Oblique
- The value of this hint must be 1 for oblique fonts (italic),
or 0 for normal angle.
-
stylehint_ParaIndentation
- How much to indent the first line of each paragraph.
-
stylehint_Proportional
- The value of this hint must be 1 for proportional-width fonts,
or 0 for fixed-width.
-
stylehint_ReverseColor
- The value of this hint must be 0 for normal printing, 1 for reverse.
-
stylehint_Size
- How much to increase or decrease the font size.
-
stylehint_TextColor
- The foreground color of the text.
-
stylehint_Weight
- The value of this hint must be 1 for heavy-weight
fonts (boldface), 0 for normal weight, and -1 for light-weight fonts.
-
close()
- Close the stream, not bothering to read the character counts.
-
close(StreamResult)
- Close this stream.
-
finalize()
- If the Glk object is still in existence when this object is
garbage-collected, destroy it.
-
getBuffer(byte[])
- Read from the stream until the buffer passed is full or
end of file.
-
getBuffer(byte[], int, int)
- Read from the stream until the buffer passed is full or
end of file.
-
getChar()
- Read a character.
-
getLine(byte[])
- Read from the stream until the buffer passed is full or
a newline character is read.
-
getLine(char[])
- Read from the stream until the buffer passed is full or
a newline character is read.
-
getLine(char[], int, int)
- Read from the stream until the buffer passed is full or
a newline character is read.
-
getPosition()
- Get the position of the read/write mark.
-
iterate(Stream, Object[])
- Iterate over streams.
-
openMemory(byte[], int)
- Open a stream which reads from or writes to an array in memory.
-
openMemory(byte[], int, Object)
- Open a stream which reads from or writes to an array in memory.
-
putBuffer(char[])
- Print a block of characters.
-
putBuffer(char[], int, int)
- Print a block of characters.
-
putChar(char)
- Print one character.
-
putString(String)
- Print a string.
-
setHyperlink(int)
- Set the current hyperlink value in this stream.
-
setPosition(int, int)
- Set the position of the read/write mark.
-
setResourceMap()
- Tell the library to load Blorb resources from this stream.
-
setStyle(int)
- Change the style of this stream.
style_Normal
public static final int style_Normal
- The style of normal or body text. A new window or
stream always starts with style_Normal as the current style.
style_Emphasized
public static final int style_Emphasized
- Text which is emphasized.
style_Preformatted
public static final int style_Preformatted
- Text which has a particular arrangement of characters.
It will always be rendered in a fixed-width font.
style_Header
public static final int style_Header
- Text which introduces a large section. This is
suitable for the title of an entire game, or a major division such
as a chapter.
style_Subheader
public static final int style_Subheader
- Text which introduces a smaller section within a large section.
style_Alert
public static final int style_Alert
- Text which warns of a dangerous condition, or one which
the player should pay attention to.
style_Note
public static final int style_Note
- Text which notifies of an interesting condition.
style_BlockQuote
public static final int style_BlockQuote
- Text which forms a quotation or otherwise abstracted text.
style_Input
public static final int style_Input
- Text which the player has entered. You should
generally not use this style at all; the library uses it for text
which is typed during a line-input request. One case when it is
appropriate for you to use style_Input is when you are simulating
player input by reading commands from a text file.
style_User1
public static final int style_User1
- This style has no particular semantic meaning. You may
define a meaning relevant to your own work, and use it as you see fit.
style_User2
public static final int style_User2
- This style has no particular semantic meaning. You may
define a meaning relevant to your own work, and use it as you see fit.
style_NUMSTYLES
public static final int style_NUMSTYLES
- The number of styles this library supports.
stylehint_Indentation
public static final int stylehint_Indentation
- How much to indent lines of text in the given style.
May be a negative number, to shift the text out (left)
instead of in (right). The exact metric isn't precisely specified;
you can assume that +1 is the smallest indentation possible which
is clearly visible to the player.
stylehint_ParaIndentation
public static final int stylehint_ParaIndentation
- How much to indent the first line of each paragraph.
This is in addition to the indentation specified by
stylehint_Indentation. This too may be negative, and is measured in
the same units as stylehint_Indentation.
stylehint_Justification
public static final int stylehint_Justification
- How to justify text.
- See Also:
- stylehint_just_LeftFlush, stylehint_just_LeftRight, stylehint_just_RightFlush, stylehint_just_Centred
stylehint_Size
public static final int stylehint_Size
- How much to increase or decrease the font size. This
is relative; 0 means the interpreter's default font size will be used,
positive numbers increase it, and negative numbers decrease it. Again,
+1 is the smallest size increase which is easily visible.
stylehint_Weight
public static final int stylehint_Weight
- The value of this hint must be 1 for heavy-weight
fonts (boldface), 0 for normal weight, and -1 for light-weight fonts.
stylehint_Oblique
public static final int stylehint_Oblique
- The value of this hint must be 1 for oblique fonts (italic),
or 0 for normal angle.
stylehint_Proportional
public static final int stylehint_Proportional
- The value of this hint must be 1 for proportional-width fonts,
or 0 for fixed-width.
stylehint_TextColor
public static final int stylehint_TextColor
- The foreground color of the text. This is
encoded in the 32-bit hint value: the top 8 bits must be zero, the
next 8 bits are the red value, the next 8 bits are the green value,
and the bottom 8 bits are the blue value. Color values range from 0
to 255.
stylehint_BackColor
public static final int stylehint_BackColor
- The background color behind the text. This
is encoded the same way as stylehint_TextColor.
- See Also:
- stylehint_TextColor
stylehint_ReverseColor
public static final int stylehint_ReverseColor
- The value of this hint must be 0 for normal printing, 1 for reverse.
stylehint_NUMHINTS
public static final int stylehint_NUMHINTS
- The number of stylehints this library knows about.
stylehint_just_LeftFlush
public static final int stylehint_just_LeftFlush
- Text will be left aligned.
stylehint_just_LeftRight
public static final int stylehint_just_LeftRight
- Text will be fully justified.
stylehint_just_Centred
public static final int stylehint_just_Centred
- Text will be centred.
stylehint_just_RightFlush
public static final int stylehint_just_RightFlush
- Text will be right aligned.
seekmode_Start
public static final int seekmode_Start
- Seek to pos characters after the beginning of the file.
seekmode_Current
public static final int seekmode_Current
- Seek to pos characters after the current position.
(pos can be negative to move backwards).
seekmode_End
public static final int seekmode_End
- Seek to pos characters after the beginning of the file.
(pos should always be 0 or negative).
iterate
public static Stream iterate(Stream s,
Object r[])
- Iterate over streams.
- See Also:
- iterate
openMemory
public static Stream openMemory(byte buf[],
int fmode)
- Open a stream which reads from or writes to an array in memory.
- Parameters:
- buf - The array to use.
- fmode - The mode to open in (FileRef.filemode_*)
- Returns:
- A stream that uses this array, or null if there isn't one.
- See Also:
- openMemory
openMemory
public static Stream openMemory(byte buf[],
int fmode,
Object jrock)
- Open a stream which reads from or writes to an array in memory.
When outputting, if more than buflen characters are written to the stream,
all of them beyond the buffer length will be thrown away, so as not to
overwrite the buffer. (The character count of the stream will still be
maintained correctly. That is, it will count the number of characters
written into the stream, not the number that fit in the buffer.)
If buf is null, then everything
written to the stream is thrown away. This may be useful if you are
interested in the character count.
When inputting, if more than buflen characters are read from the stream,
the stream will start returning -1 (signalling end-of-file.) If buf is
NULL, the stream will always return end-of-file.
The data are written to the buffer exactly as they were passed to the
printing functions (glk_put_char(), etc); input functions will read the
data exactly as it exists in memory. No platform-dependent cookery will
be done on it.
Whether reading or writing, the contents of the buffer are undefined
until the stream is closed. The library may store the data there as it
is written, or deposit it all in a lump when the stream is closed. It
is illegal to change the contents of the buffer while the stream is open.
- Parameters:
- buf - The array to use.
- fmode - The mode to open in (FileRef.filemode_*)
- jrock - The rock to give the new stream.
- Returns:
- A stream that uses this array, or null if there isn't one.
getChar
public int getChar()
- Read a character.
- Returns:
- The character read (0-255) or -1 for end of file.
getLine
public int getLine(byte line[])
- Read from the stream until the buffer passed is full or
a newline character is read.
- Parameters:
- line - The byte array to populate.
- Returns:
- The number of bytes read, including the newline.
getLine
public int getLine(char line[])
- Read from the stream until the buffer passed is full or
a newline character is read.
- Parameters:
- line - The character array to populate.
- Returns:
- The number of bytes read, including the newline.
getLine
public int getLine(char line[],
int first,
int len)
- Read from the stream until the buffer passed is full or
a newline character is read.
- Parameters:
- line - The character array to populate.
- first - The first character to be replaced.
- len - The maximum number of characters to read.
- Returns:
- The number of bytes read, including the newline.
getBuffer
public int getBuffer(byte buf[])
- Read from the stream until the buffer passed is full or
end of file.
- Parameters:
- buf - The byte array to populate.
- Returns:
- The number of bytes read.
getBuffer
public int getBuffer(byte buf[],
int first,
int len)
- Read from the stream until the buffer passed is full or
end of file.
- Parameters:
- buf - The byte array to populate.
- first - The first byte to be replaced.
- len - The maximum number of bytes to read.
- Returns:
- The number of bytes read.
putChar
public void putChar(char c)
- Print one character.
Only characters that can be represented in the ISO Latin-1 encoding will be
printed. Others will appear as ? marks.
- Parameters:
- c - the character to write
putString
public void putString(String s)
- Print a string.
Only characters that can be represented in the ISO Latin-1 encoding will be
printed. Others will appear as ? marks.
- Parameters:
- s - the string to write
putBuffer
public void putBuffer(char buf[])
- Print a block of characters.
Only characters that can be represented in the ISO Latin-1 encoding will be
printed. Others will appear as ? marks.
- Parameters:
- buf - the characters to write
putBuffer
public void putBuffer(char buf[],
int first,
int len)
- Print a block of characters.
Only characters that can be represented in the ISO Latin-1 encoding will be
printed. Others will appear as ? marks.
- Parameters:
- buf - the characters to write
- first - the index of the first character to be written
- last - the index of the last character to be written
setStyle
public void setStyle(int style)
- Change the style of this stream.
If the style is not recognised, style_Normal is assumed.
- Parameters:
- style - the new style to use
finalize
protected void finalize()
- If the Glk object is still in existence when this object is
garbage-collected, destroy it.
- Overrides:
- finalize in class OpaqueObject
close
public void close()
- Close the stream, not bothering to read the character counts.
- See Also:
- close
close
public void close(StreamResult r)
- Close this stream.
If this is the current output stream, the current output stream is set to null.
- Parameters:
- r - Will be populated with character counts if not null.
setPosition
public void setPosition(int pos,
int seekMode)
- Set the position of the read/write mark.
It is illegal to specify a position before the beginning
or after the end of the file.
In binary files, the mark position is exact -- it corresponds with
the number of characters you have read or written. In text files, this
mapping can vary, because of linefeed conversions or other character-set
approximations. setPosition() and getPosition() measure positions
in the platform's native encoding -- after character cookery.
Therefore, in a text stream, it is safest to use setPosition() only
to move to the beginning or end of a file, or to a position
determined by getPosition().
- Parameters:
- pos - The meaning of this depends on seekMode.
- seekMode - How to calculate the new position.
- See Also:
- seekmode_Start, seekmode_Current, seekmode_End
getPosition
public long getPosition()
- Get the position of the read/write mark.
For memory streams and binary
file streams, this is exactly the number of bytes read or written
from the beginning of the stream (unless you have moved the mark with
setPosition().) For text file streams, matters are more
ambiguous, since (for example) writing one byte to a text file may store
more than one character in the platform's native encoding. You can only
be sure that the position increases as you read or write to the file.
- Returns:
- The position of the mark.
- See Also:
- setPosition
setHyperlink
public void setHyperlink(int linkval)
- Set the current hyperlink value in this stream.
A link value is any non-zero * integer; zero indicates no link.
Subsequent text output is considered to make up the body of the
link, which continues until the link value is changed
(or set to zero).
- Parameters:
- linkval - The link value, 0 for no hyperlink.
setResourceMap
public void setResourceMap() throws BlorbException
- Tell the library to load Blorb resources from this stream.
Whenever your program calls an image or sound
function, such as Window.imageDraw(), the library will
search this file for the resource you request.
The stream must be open for reading in binary mode.
Do not close the stream after calling this
function. The library is responsible for closing the stream
at shutdown time.
All Packages Class Hierarchy This Package Previous Next Index