Package org.javacc.utils
Class OutputFile
- java.lang.Object
-
- org.javacc.utils.OutputFile
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
class OutputFile extends java.lang.Object implements java.io.CloseableThis class handles the creation and maintenance of the boiler-plate classes, such as Token.java, JavaCharStream.java etc. It is responsible for:- Writing the JavaCC header lines to the file.
- Writing the checksum line.
- Using the checksum to determine if an existing file has been changed by the user (and so should be left alone).
- Checking any existing file's version (if the file can not be overwritten).
- Checking any existing file's creation options (if the file can not be overwritten).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classOutputFile.TrapClosePrintWriterTheOutputFile.TrapClosePrintWriterimplements aPrintWriter, avoiding to close the relatedOutputStreamwith anOutputFile.TrapClosePrintWriter.close().
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringcompatibleVersionprivate java.security.DigestOutputStreamdigestStreamprivate java.io.Filefileprivate booleanneedToWriteprivate java.util.List<java.lang.String>optionsprivate java.lang.StringtoolNameprivate OutputFile.TrapClosePrintWriterwriter
-
Constructor Summary
Constructors Constructor Description OutputFile(java.io.File file, java.lang.String toolName, java.lang.String compatibleVersion, java.util.List<java.lang.String> options, Context context)Create a new OutputFile.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the OutputFile, writing any necessary trailer information (such as a checksum).java.io.PrintWritergetPrintWriter()Return a PrintWriter object that may be used to write to this file.booleanisNeedToWrite()Returntrueif the file needs to be written.
-
-
-
Field Detail
-
file
private final java.io.File file
-
options
private final java.util.List<java.lang.String> options
-
toolName
private final java.lang.String toolName
-
compatibleVersion
private final java.lang.String compatibleVersion
-
needToWrite
private final boolean needToWrite
-
writer
private OutputFile.TrapClosePrintWriter writer
-
digestStream
private java.security.DigestOutputStream digestStream
-
-
Constructor Detail
-
OutputFile
OutputFile(java.io.File file, java.lang.String toolName, java.lang.String compatibleVersion, java.util.List<java.lang.String> options, Context context) throws java.io.IOExceptionCreate a new OutputFile.- Parameters:
file- the file to write to.toolName- the name of the generating tool.compatibleVersion- the minimum compatible JavaCC version.options- if the file already exists, and cannot be overwritten, this is a list of options (such s STATIC=false) to check for changes.- Throws:
java.io.IOException
-
-
Method Detail
-
isNeedToWrite
public final boolean isNeedToWrite()
Returntrueif the file needs to be written.
-
getPrintWriter
public final java.io.PrintWriter getPrintWriter() throws java.io.IOExceptionReturn a PrintWriter object that may be used to write to this file. Any necessary header information is written by this method.- Throws:
java.io.IOException
-
close
public final void close() throws java.io.IOExceptionClose the OutputFile, writing any necessary trailer information (such as a checksum).- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-