tribble.io
Class ASALineWriter

java.lang.Object
  extended by tribble.io.ASALineWriter

public class ASALineWriter
extends java.lang.Object

ASA line printer output stream. These methods interpret ASA (ANS) printer form control characters in the first column of each output line.

ASA (ANS) printer form control characters perform some action affecting the position of the logical printing mechanism prior to printing the remaining contents of line. The control characters are:

CR LFCR LF CR LFCR LF CR LF CR LF
Char Action ASCII Equivalent
1 Advance the page (form feed) FF
space Advance one line
0 Advance two lines
- Advance three lines
+ Do not advance any lines,
overprint the previous line
CR

In place of CR LF sequences to advance to the next line, the native newline character sequence is used (which could be CR, CR LF, or LF sequences).

The output methods are synchronized, so that when multiple threads write text lines to the same line printer stream, each line is written atomically. The resulting output will contain interspersed output lines, with no split or incomplete lines.

Source code

david.tribble.com/src/java/tribble/io/ASALineWriter.java
david.tribble.com/src/java.

Since:
API 1.0, 2007-12-12
Version:
$Revision: 1.2 $ $Date: 2007/12/16 05:25:00 $
Author:
David R. Tribble (david@tribble.com).

Copyright ©2007 by David R. Tribble, all rights reserved.
Permission is granted to any person or entity except those designated by the United States Department of State as a terrorist, or terrorist government or agency, to use and distribute this source code provided that the original copyright notice remains present and unaltered.


Field Summary
(package private) static java.lang.String REV
          Revision information.
 
Constructor Summary
ASALineWriter(java.io.Writer out)
          Constructor.
ASALineWriter(java.io.Writer out, java.lang.Object lock)
          Constructor.
 
Method Summary
 void close()
          Close the output stream.
protected  void finalize()
          Finalization.
 void flush()
          Write any pending output to the output stream.
 int getLineCount()
          Retrieve the number of lines written to the output stream.
 int getPageCount()
          Retrieve the number of pages written to the output stream.
static void main(java.lang.String[] args)
          Convert an ASA printer file into ASCII.
 void setLineCount(int n)
          Reset the line counter for the output stream.
 void setPageCount(int n)
          Reset the page counter for the output stream.
 void writeLine()
          Write an empty line to the output stream.
 int writeLine(char[] buf)
          Write a line of characters to the output stream.
 int writeLine(char[] buf, int off, int len)
          Write a line of characters to the output stream.
 void writeLine(java.lang.String line)
          Write a line of characters to the output stream.
 void writeLine(java.lang.String line, int off, int len)
          Write a line of characters to the output stream.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REV

static final java.lang.String REV
Revision information.

See Also:
Constant Field Values
Constructor Detail

ASALineWriter

public ASALineWriter(java.io.Writer out)
Constructor.

Parameters:
out - Underlying output stream. All I/O operations will synchronize on this object.
Throws:
java.lang.NullPointerException - (unchecked) Thrown if out is null.
Since:
1.1, 2007-12-12

ASALineWriter

public ASALineWriter(java.io.Writer out,
                     java.lang.Object lock)
Constructor.

Parameters:
out - Underlying output stream.
lock - All I/O operations will synchronize on this object. This can be null, in which case all I/O operations synchronize on the line printer object itself.
Throws:
java.lang.NullPointerException - (unchecked) Thrown if out is null.
Since:
1.1, 2007-12-12
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Convert an ASA printer file into ASCII.

Throws:
java.io.IOException
Since:
1.2, 2007-12-15

finalize

protected void finalize()
                 throws java.lang.Throwable
Finalization.

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable
Since:
1.1, 2007-12-12

close

public void close()
           throws java.io.IOException
Close the output stream.

Throws:
java.io.IOException - Thrown if an I/O write error occurs.
Since:
1.1, 2007-12-12

flush

public void flush()
           throws java.io.IOException
Write any pending output to the output stream.

Throws:
java.io.IOException - Thrown if an I/O write error occurs.
Since:
1.1, 2007-12-12

writeLine

public void writeLine(java.lang.String line)
               throws java.io.IOException
Write a line of characters to the output stream. Note that the characters are written as a complete text line, and that the first character (line.charAt(0)) is the ASA form control character for the line.

Parameters:
line - Text line to write. Note that other than the first character, the contents of this line are not interpreted. This implies that non-printing characters (especially '\n', '\r', and '\f' characters) will produce unexpected results.
Throws:
java.io.IOException - Thrown if an I/O write error occurs.
Since:
1.1, 2007-12-12

writeLine

public void writeLine(java.lang.String line,
                      int off,
                      int len)
               throws java.io.IOException
Write a line of characters to the output stream. Note that the characters are written as a complete text line, and that the first character (line.charAt(off)) is the ASA form control character for the line.

Parameters:
line - Text line to write. Note that other than the first character, the contents of this line are not interpreted. This implies that non-printing characters (especially '\n', '\r', and '\f' characters) will produce unexpected results.
off - Index of the first character in line to write.
len - Number of characters in line to write.
Throws:
java.io.IOException - Thrown if an I/O write error occurs.
Since:
1.1, 2007-12-12

writeLine

public void writeLine()
               throws java.io.IOException
Write an empty line to the output stream.

Throws:
java.io.IOException - Thrown if an I/O write error occurs.
Since:
1.1, 2007-12-12

writeLine

public int writeLine(char[] buf)
              throws java.io.IOException
Write a line of characters to the output stream. Note that the characters are written as a complete text line, and that the first character (buf[0]) is the ASA form control character for the line.

Parameters:
buf - Characters to write. Note that other than the first character, the contents of this line are not interpreted. This implies that non-printing characters (especially '\n', '\r', and '\f' characters) will produce unexpected results.
Returns:
The number of characters from buf that were written to the output stream.
Throws:
java.io.IOException - Thrown if an I/O write error occurs.
Since:
1.1, 2007-12-12

writeLine

public int writeLine(char[] buf,
                     int off,
                     int len)
              throws java.io.IOException
Write a line of characters to the output stream. Note that the characters are written as a complete text line, and that the first character (buf[off]) is the ASA form control character for the line.

Parameters:
buf - Characters to write. Note that other than the first character, the contents of this line are not interpreted. This implies that non-printing characters (especially '\n', '\r', and '\f' characters) will produce unexpected results.
off - Index of the first character in buf to write.
len - Number of characters in buf to write.
Returns:
The number of characters from buf that were written to the output stream.
Throws:
java.io.IOException - Thrown if an I/O write error occurs.
Since:
1.1, 2007-12-12

getLineCount

public int getLineCount()
Retrieve the number of lines written to the output stream.

Returns:
Number of lines written to the output stream so far (starting with zero).
Since:
1.1, 2007-12-12

setLineCount

public void setLineCount(int n)
Reset the line counter for the output stream.

Parameters:
n - Line number at which to begin re-counting.
Since:
1.1, 2007-12-15

getPageCount

public int getPageCount()
Retrieve the number of pages written to the output stream.

Returns:
Number of pages written to the output stream so far (starting with zero).
Since:
1.1, 2007-12-12

setPageCount

public void setPageCount(int n)
Reset the page counter for the output stream.

Parameters:
n - Page number at which to begin re-counting.
Since:
1.1, 2007-12-15