ptolemy.backtrack.util
Class SourceOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FileOutputStream
          extended by ptolemy.backtrack.util.SourceOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class SourceOutputStream
extends java.io.FileOutputStream

Java source code output stream. This output stream is directly created with an output file name. Necessary parent directories are created if they do not exist yet.

Since:
Ptolemy II 5.1
Version:
$Id: SourceOutputStream.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Thomas Feng
Accepted Rating:
Red (tfeng)
Proposed Rating:
Red (tfeng)

Constructor Summary
private SourceOutputStream(java.lang.String fileName)
          Construct an output stream with the given file name.
 
Method Summary
static SourceOutputStream getStream(java.lang.String fileName, boolean overwrite)
          Get an output stream with a file name.
static SourceOutputStream getStream(java.lang.String root, java.lang.String packageName, java.lang.String fileName, boolean overwrite)
          Get an output stream with a output root directory, the name of the package which the output class is in, and an output file name.
 
Methods inherited from class java.io.FileOutputStream
close, finalize, getChannel, getFD, write, write, write
 
Methods inherited from class java.io.OutputStream
flush
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SourceOutputStream

private SourceOutputStream(java.lang.String fileName)
                    throws java.io.FileNotFoundException
Construct an output stream with the given file name. Users should use getStream(String, boolean) or getStream(String, String, String, boolean) to obtain the output stream, instead of creating it with the new operator.

Parameters:
fileName - The name of the output file.
Throws:
java.io.FileNotFoundException - If the output file cannot be created.
Method Detail

getStream

public static SourceOutputStream getStream(java.lang.String root,
                                           java.lang.String packageName,
                                           java.lang.String fileName,
                                           boolean overwrite)
                                    throws java.io.IOException
Get an output stream with a output root directory, the name of the package which the output class is in, and an output file name. If the parent directories of the final output file (computed from the given arguments) does not exist yet, they are created automatically.

Parameters:
root - The root of the output class.
packageName - The name of the package which the output class is in.
fileName - The name of the file. It may contain path information, but only the simple file name is used.
overwrite - Whether to an overwrite existing file, if any.
Returns:
The output stream of the file.
Throws:
java.io.IOException - If error occurs when creating the output stream. An IOException is thrown if overwrite is falseand the output file already exists; FileNotFoundException is thrown if the output file cannot be created for other reasons.

getStream

public static SourceOutputStream getStream(java.lang.String fileName,
                                           boolean overwrite)
                                    throws java.io.IOException
Get an output stream with a file name. If the parent directories of the output file does not exist yet, they are created automatically.

Parameters:
fileName - The output file name.
overwrite - Whether to an overwrite existing file, if any.
Returns:
The output stream of the file.
Throws:
java.io.IOException - If error occurs when creating the output stream. An IOException is thrown if overwrite is falseand the output file already exists; FileNotFoundException is thrown if the output file cannot be created for other reasons.