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.


Variable Index

 o seekmode_Current
Seek to pos characters after the current position.
 o seekmode_End
Seek to pos characters after the beginning of the file.
 o seekmode_Start
Seek to pos characters after the beginning of the file.
 o style_Alert
Text which warns of a dangerous condition, or one which the player should pay attention to.
 o style_BlockQuote
Text which forms a quotation or otherwise abstracted text.
 o style_Emphasized
Text which is emphasized.
 o style_Header
Text which introduces a large section.
 o style_Input
Text which the player has entered.
 o style_Normal
The style of normal or body text.
 o style_Note
Text which notifies of an interesting condition.
 o style_NUMSTYLES
The number of styles this library supports.
 o style_Preformatted
Text which has a particular arrangement of characters.
 o style_Subheader
Text which introduces a smaller section within a large section.
 o style_User1
This style has no particular semantic meaning.
 o style_User2
This style has no particular semantic meaning.
 o stylehint_BackColor
The background color behind the text.
 o stylehint_Indentation
How much to indent lines of text in the given style.
 o stylehint_just_Centred
Text will be centred.
 o stylehint_just_LeftFlush
Text will be left aligned.
 o stylehint_just_LeftRight
Text will be fully justified.
 o stylehint_just_RightFlush
Text will be right aligned.
 o stylehint_Justification
How to justify text.
 o stylehint_NUMHINTS
The number of stylehints this library knows about.
 o stylehint_Oblique
The value of this hint must be 1 for oblique fonts (italic), or 0 for normal angle.
 o stylehint_ParaIndentation
How much to indent the first line of each paragraph.
 o stylehint_Proportional
The value of this hint must be 1 for proportional-width fonts, or 0 for fixed-width.
 o stylehint_ReverseColor
The value of this hint must be 0 for normal printing, 1 for reverse.
 o stylehint_Size
How much to increase or decrease the font size.
 o stylehint_TextColor
The foreground color of the text.
 o 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.

Method Index

 o close()
Close the stream, not bothering to read the character counts.
 o close(StreamResult)
Close this stream.
 o finalize()
If the Glk object is still in existence when this object is garbage-collected, destroy it.
 o getBuffer(byte[])
Read from the stream until the buffer passed is full or end of file.
 o getBuffer(byte[], int, int)
Read from the stream until the buffer passed is full or end of file.
 o getChar()
Read a character.
 o getLine(byte[])
Read from the stream until the buffer passed is full or a newline character is read.
 o getLine(char[])
Read from the stream until the buffer passed is full or a newline character is read.
 o getLine(char[], int, int)
Read from the stream until the buffer passed is full or a newline character is read.
 o getPosition()
Get the position of the read/write mark.
 o iterate(Stream, Object[])
Iterate over streams.
 o openMemory(byte[], int)
Open a stream which reads from or writes to an array in memory.
 o openMemory(byte[], int, Object)
Open a stream which reads from or writes to an array in memory.
 o putBuffer(char[])
Print a block of characters.
 o putBuffer(char[], int, int)
Print a block of characters.
 o putChar(char)
Print one character.
 o putString(String)
Print a string.
 o setHyperlink(int)
Set the current hyperlink value in this stream.
 o setPosition(int, int)
Set the position of the read/write mark.
 o setResourceMap()
Tell the library to load Blorb resources from this stream.
 o setStyle(int)
Change the style of this stream.

Variables

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

 o style_Emphasized
 public static final int style_Emphasized
Text which is emphasized.

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

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

 o style_Subheader
 public static final int style_Subheader
Text which introduces a smaller section within a large section.

 o style_Alert
 public static final int style_Alert
Text which warns of a dangerous condition, or one which the player should pay attention to.

 o style_Note
 public static final int style_Note
Text which notifies of an interesting condition.

 o style_BlockQuote
 public static final int style_BlockQuote
Text which forms a quotation or otherwise abstracted text.

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

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

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

 o style_NUMSTYLES
 public static final int style_NUMSTYLES
The number of styles this library supports.

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

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

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

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

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

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

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

 o 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
 o stylehint_ReverseColor
 public static final int stylehint_ReverseColor
The value of this hint must be 0 for normal printing, 1 for reverse.

 o stylehint_NUMHINTS
 public static final int stylehint_NUMHINTS
The number of stylehints this library knows about.

 o stylehint_just_LeftFlush
 public static final int stylehint_just_LeftFlush
Text will be left aligned.

 o stylehint_just_LeftRight
 public static final int stylehint_just_LeftRight
Text will be fully justified.

 o stylehint_just_Centred
 public static final int stylehint_just_Centred
Text will be centred.

 o stylehint_just_RightFlush
 public static final int stylehint_just_RightFlush
Text will be right aligned.

 o seekmode_Start
 public static final int seekmode_Start
Seek to pos characters after the beginning of the file.

 o seekmode_Current
 public static final int seekmode_Current
Seek to pos characters after the current position. (pos can be negative to move backwards).

 o 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).

Methods

 o iterate
 public static Stream iterate(Stream s,
                              Object r[])
Iterate over streams.

See Also:
iterate
 o 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
 o 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.
 o getChar
 public int getChar()
Read a character.

Returns:
The character read (0-255) or -1 for end of file.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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.
 o 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
 o 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
 o 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
 o 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
 o 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
 o 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
 o close
 public void close()
Close the stream, not bothering to read the character counts.

See Also:
close
 o 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.
 o 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
 o 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
 o 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.
 o 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