net.directj.jlogger
Class FileOutput

java.lang.Object
  |
  +--net.directj.jlogger.FileOutput
All Implemented Interfaces:
Output

public class FileOutput
extends java.lang.Object
implements Output

This is a simple class that print logging information into a file. The jlogger tool has the particularity that an information can be write at any moment. Because of that, using specific format that need a footer, like XML or HTML can be quite complex, and need some methods like 'stop' or 'close' that is not compatible with the jlogger's objectives. So this class use a RandomAccessFile and re-write the footer for each new information. This way can appear to be a 'barbarian' one, but it is really the more simple for the user (he don't have to take care of ending or closing the file) and it is not really less efficient than a 'classic' way. WARNING: This class just print the specified string, but without a nl character. The formatter HAVE TO take care of 'nl' ('\n' in java) char.

Version:
0.1.4
Author:
CARTAPANIS Alexandre <earendil@jprolog.net>

Nested Class Summary
private  class FileOutput.ShutdownHook
          This class is used to close the file at the end of the JVM.
 
Field Summary
private  java.lang.String fileName
          The file name.
private  byte[] footer
          The footer string, as an array of bytes.
private  byte[] header
          The header string, as an array of bytes.
private  java.io.RandomAccessFile out
          The output stream.
private  long skip
          Indicate te number of bytes to skip.
 
Constructor Summary
FileOutput()
          Creates a new FileOutput.
FileOutput(java.lang.String _name)
          Creates a new FileOutput, with a specified name.
FileOutput(java.lang.String _name, boolean _append)
          Creates a new FileOutput, with a specified name.
FileOutput(java.lang.String _name, java.lang.String _header, java.lang.String _footer, boolean _append)
          Creates a new FileOutput, with a specified name.
 
Method Summary
 boolean equals(java.lang.Object _obj)
          Indicates whether some other object is "equal to" this one.
 int hashCode()
          Returns a hash code value for the object.
 void print(java.lang.String _str)
          Prints the info, using the output.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

out

private java.io.RandomAccessFile out
The output stream.


fileName

private java.lang.String fileName
The file name.


header

private byte[] header
The header string, as an array of bytes.


footer

private byte[] footer
The footer string, as an array of bytes.


skip

private long skip
Indicate te number of bytes to skip.

Constructor Detail

FileOutput

public FileOutput()
Creates a new FileOutput. The file name will be ".log", placed into the current directory.


FileOutput

public FileOutput(java.lang.String _name)
Creates a new FileOutput, with a specified name. You may include the file's extension into the name (like ".xml" or ".html").

Parameters:
_name - The file name, with the extension.

FileOutput

public FileOutput(java.lang.String _name,
                  boolean _append)
Creates a new FileOutput, with a specified name. You may include the file's extension into the name (like ".xml" or ".html").

Parameters:
_name - The file name, with the extension.
_append - Indicates if we append the output to the file or create a new one.

FileOutput

public FileOutput(java.lang.String _name,
                  java.lang.String _header,
                  java.lang.String _footer,
                  boolean _append)
Creates a new FileOutput, with a specified name. This constructor may be used with special formatter, such as XmlFormatter or HtmlFormatter. You may include the file's extension into the name (like ".xml" or ".html").

Parameters:
_name - The file name, with the extension.
_header - The header string.
_footer - The footer string.
_append - Indicates if we append the output to the file or create a new one. If the file does not exists, this has no effects.
Method Detail

print

public void print(java.lang.String _str)
Prints the info, using the output.

Specified by:
print in interface Output
Parameters:
_str - The debugging info to print on the output.
See Also:
Formatter

equals

public boolean equals(java.lang.Object _obj)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class java.lang.Object
Parameters:
_obj - The reference object with which to compare.
Returns:
boolean - True if this object is the same as the obj argument; false otherwise.

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

Overrides:
hashCode in class java.lang.Object
Returns:
int - A hash code value for this object.


Copyright © 2002 CARTAPANIS Alexandre
This page was last updated on May 10 2003