au.gov.tas.dpiwe.mr.tool
Class HeaderTool

java.lang.Object
  extended by au.gov.tas.dpiwe.mr.tool.HeaderTool

public class HeaderTool
extends Object

This tool adds headers to files in a specified directory in accordance with a mapping in a specified properties file.

It was originally intended to add header lines giving field name metadata to TSV files produced by an Ingres data export script.

Since:
Mr Architecture 3.1
Version:
1.0.0.4
Author:
Kade Hansson

Field Summary
protected static ThreadLocal returnCode
           
 
Constructor Summary
HeaderTool()
           
 
Method Summary
static void addHeader(Reader input, PrintWriter output, String header)
          Add a header to a stream.
static boolean addHeaders(String filename, String mapFilename)
          Adds headers to files in a directory according to a map.
static void generateError(String bundleName, String messageToken)
          Generates the error message for the specified token.
static void main(String[] argv)
          Initiates the header tool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

returnCode

protected static ThreadLocal returnCode
Constructor Detail

HeaderTool

public HeaderTool()
Method Detail

main

public static void main(String[] argv)
                 throws Exception
Initiates the header tool. Two parameters are required:
  1. The directory containing the files which are to have headers added.
  2. The properties file containing the map of headers.

Throws:
IOException - if the input files could not be read or the output files could not be written.
SecurityException - if the configured security policy is too restrictive.
Exception - if something else goes wrong.

generateError

public static void generateError(String bundleName,
                                 String messageToken)
Generates the error message for the specified token.

Parameters:
bundleName - identifies the bundle.
messageToken - identifies the error message.

addHeaders

public static boolean addHeaders(String filename,
                                 String mapFilename)
                          throws IOException,
                                 SecurityException
Adds headers to files in a directory according to a map.

Parameters:
filename - the directory containing the files to have headers added.
mapFilename - a properties file where the keys are filenames (add .txt extension) and the values are headers (spaces become tabs.)
Returns:
true if the files were successfully amended, false if some files were unchanged.
Throws:
IOException - if the input files could not be read or the output file could not be written.
SecurityException - if the configured security policy is too restrictive.

addHeader

public static void addHeader(Reader input,
                             PrintWriter output,
                             String header)
                      throws IOException
Add a header to a stream. The files are closed once read/written.

If the header is entirely lower case, then the rest of the file is uppercased. This ensures XMap is not as likely to affect the data at a later stage.

Parameters:
input - the Reader from which the original text should be read.
output - the PrintWriter to which the header plus original text should be written.
header - the header text.
Throws:
IOException - if the input file could not be read or the output file could not be written.