uk.ac.ebi.microarray.zooma.reports
Class ReportWriter

java.lang.Object
  extended by java.io.Writer
      extended by uk.ac.ebi.microarray.zooma.reports.ReportWriter
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable, java.lang.Appendable
Direct Known Subclasses:
TextReportWriter

public class ReportWriter
extends java.io.Writer

A writer implementation that writes all output lines supplied into a buffer, alphabetically sorts them, and flushes them to file when this writer is closed.

Author:
Tony Burdett

Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
ReportWriter(java.io.File file)
          Creates a ReportWriter that buffers written lines, sorting them alphabetically.
 
Method Summary
 void close()
          Writes the header, the footer, and the content of the buffer to disk.
 ReportWriter endReport(int exitCode)
          Finalises the report, setting the exit code of the process, sorting alphabetically and flushing to disk.
protected  java.lang.String extractOntologyTermFromURI(java.lang.String termURI)
           
protected  java.lang.String fetchOntologyName(uk.ac.ebi.ontocat.OntologyTerm term)
          Fetches the name of the ontology for the supplied term.
 void flush()
          Sorts the current buffer of report output, and flushes everything to a temporary file.
protected  org.slf4j.Logger getLog()
           
protected  java.lang.String lookupVersionFromMavenProperties()
          Retrieves the version number of the application, by locating the version property from the automatically generated maven pom.properties file.
 ReportWriter startReport()
          Initialises the report, setting useful information about the outcome such as start time, working directory etc.
 void write(char[] cbuf, int off, int len)
           
protected  void writeReportFooter(java.io.PrintWriter writer)
          Writes the footer of the report into the supplied print writer
protected  void writeReportHeader(java.io.PrintWriter writer)
          Writes the header of the report into the supplied print writer.
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReportWriter

public ReportWriter(java.io.File file)
Creates a ReportWriter that buffers written lines, sorting them alphabetically. The file is only created on completion, once this writer is closed.

Parameters:
file - the file to write the report to
Method Detail

getLog

protected org.slf4j.Logger getLog()

startReport

public ReportWriter startReport()
                         throws java.io.IOException
Initialises the report, setting useful information about the outcome such as start time, working directory etc.

Returns:
a reference to this report writer
Throws:
java.io.IOException - if something failed whilst creating the file

endReport

public ReportWriter endReport(int exitCode)
                       throws java.io.IOException
Finalises the report, setting the exit code of the process, sorting alphabetically and flushing to disk.

Parameters:
exitCode - the exit code that our mapping process should return
Returns:
a reference to this report writer
Throws:
java.io.IOException - if writing to the file failed

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws java.io.IOException
Specified by:
write in class java.io.Writer
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException
Sorts the current buffer of report output, and flushes everything to a temporary file.

Specified by:
flush in interface java.io.Flushable
Specified by:
flush in class java.io.Writer
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Writes the header, the footer, and the content of the buffer to disk. This method also flushes and closes the temporary file.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Writer
Throws:
java.io.IOException - if closing this writer failed

writeReportHeader

protected void writeReportHeader(java.io.PrintWriter writer)
Writes the header of the report into the supplied print writer. If you require columns headers at the top of your report, you should extend this method, calling super.writeReportHeader() first followed by writer.println(<my line here>);

Parameters:
writer - the writer to write the header data to

writeReportFooter

protected void writeReportFooter(java.io.PrintWriter writer)
Writes the footer of the report into the supplied print writer

Parameters:
writer - the writer to write the footer data into

lookupVersionFromMavenProperties

protected java.lang.String lookupVersionFromMavenProperties()
Retrieves the version number of the application, by locating the version property from the automatically generated maven pom.properties file.

Returns:
the application version number

fetchOntologyName

protected java.lang.String fetchOntologyName(uk.ac.ebi.ontocat.OntologyTerm term)
Fetches the name of the ontology for the supplied term. This is a convenience method. If the label of the ontology attached to the given term could not be determined, the ontology accession is used.

Parameters:
term - the term we want the ontology name for
Returns:
the ontology name, or accession if the name was null

extractOntologyTermFromURI

protected java.lang.String extractOntologyTermFromURI(java.lang.String termURI)


Copyright © 2010. All Rights Reserved.