uk.ac.umist.co.brailletrans.utils
Class Translator

java.lang.Object
  |
  +--uk.ac.umist.co.brailletrans.utils.Translator
Direct Known Subclasses:
OutputTest, OutputTestAll, Translate256, TranslateC, TranslateCDummy, TranslateInt, TranslateUni

public class Translator
extends java.lang.Object

Superclass of translation tools that use the Language programs. Contains various commonly-used utilities for reading from disk, converting arrays and so forth.


Field Summary
static int DISK_ERROR
          Error code for disk error.
static int END_OF_FILE
          The int returned by input streams in Java that indicates that the stream has not been completely read.
static int FILE_SIZE_ERROR_LEEWAY
          Some of the Translator methods test for file size: this is added to any result in case of discrepancies in reality/JVM perception.
static int SUCCESS
          Report code indicating successful operation.
static int UNKNOWN_ERROR
          Error code for errors with multiple possible causes.
 
Constructor Summary
Translator()
           
 
Method Summary
static int[] readIntArrayFromDisk(java.lang.String filename)
          Reads an array of ints from a local file using BufferedInputStream.
static java.lang.String readStringFromDisk(java.lang.String filename)
          Reads text as a String from a local file using java.io.BufferedReader.
static byte[] turnIntoByteArray(int[] toConvert)
          Converts an arrays of ints into an array of bytes
static java.lang.String turnIntoString(byte[] toConvert)
          Converts an array of bytes into a String
static java.lang.String turnIntoString(int[] toConvert)
          Converts an array of ints into a String
static void writeIntArrayToDisk(int[] toWrite, java.lang.String filename)
          Saves an array of integers to disk using FileOutputStream
static void writeStringToDisk(java.lang.String filename, java.lang.String toWrite)
          Writes a String to a local file using BufferedWriter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FILE_SIZE_ERROR_LEEWAY

public static final int FILE_SIZE_ERROR_LEEWAY
Some of the Translator methods test for file size: this is added to any result in case of discrepancies in reality/JVM perception.

END_OF_FILE

public static final int END_OF_FILE
The int returned by input streams in Java that indicates that the stream has not been completely read.

UNKNOWN_ERROR

public static final int UNKNOWN_ERROR
Error code for errors with multiple possible causes.

DISK_ERROR

public static final int DISK_ERROR
Error code for disk error.

SUCCESS

public static final int SUCCESS
Report code indicating successful operation.
Constructor Detail

Translator

public Translator()
Method Detail

writeStringToDisk

public static void writeStringToDisk(java.lang.String filename,
                                     java.lang.String toWrite)
                              throws java.io.IOException
Writes a String to a local file using BufferedWriter
Parameters:
filename - String containing full path and name of file to write to.
toWrite - String to be written to file in filename.

readStringFromDisk

public static java.lang.String readStringFromDisk(java.lang.String filename)
                                           throws java.io.FileNotFoundException,
                                                  java.io.IOException
Reads text as a String from a local file using java.io.BufferedReader.
Parameters:
filename - String containing the full path and filename of the local file to read text from.
Returns:
toReturn The String read from the local file.

readIntArrayFromDisk

public static int[] readIntArrayFromDisk(java.lang.String filename)
                                  throws java.io.FileNotFoundException,
                                         java.io.IOException
Reads an array of ints from a local file using BufferedInputStream.
Parameters:
filename - String containing the full path and filename of the local file to read from.
Returns:
toReturn An int[] containing ints read from file.

turnIntoByteArray

public static byte[] turnIntoByteArray(int[] toConvert)
Converts an arrays of ints into an array of bytes
Parameters:
toConvert - int[] to be converted into byte[]
Returns:
toReturn byte[] result of conversion from int[]

turnIntoString

public static java.lang.String turnIntoString(int[] toConvert)
Converts an array of ints into a String
Parameters:
toConvert - int[] to be converted into String
Returns:
toReturn String from toConvert

turnIntoString

public static java.lang.String turnIntoString(byte[] toConvert)
Converts an array of bytes into a String
Parameters:
toConvert - byte[] to be converted into String
Returns:
toReturn String from toConvert

writeIntArrayToDisk

public static void writeIntArrayToDisk(int[] toWrite,
                                       java.lang.String filename)
                                throws java.io.IOException
Saves an array of integers to disk using FileOutputStream
Parameters:
toWrite - Array of ints to write to disk.
filename - String holding the full path and filename to write to.