sears.file
Class FileConversion

java.lang.Object
  extended by sears.file.FileConversion

public abstract class FileConversion
extends java.lang.Object

This class must be implemented each time a java.io.File object will have to be converted to a sears.file.SubtitleFile object
It wrap a BufferedReader and gives method to access to it with respect of the Sears constraints


Field Summary
protected  java.io.File file
           
protected  int lineCount
           
 
Constructor Summary
FileConversion(java.io.File file, java.lang.String charset)
          Constructs a new instance
 
Method Summary
protected  void closeReader()
          Closes the reader and reset line count
protected  void ensureStringIsValid(java.lang.String str)
          Tests the validity of str return true if str is not null and if it is not an empty String, false if not
protected abstract  Subtitle getSubtitle(java.lang.String line)
          Constructs and returns the Subtitle object which represents subtitles information begin at line given in parameters
This method is used by the non abstract parse(ArrayList) method
protected  java.lang.String getTheNextNonEmptyLine()
          Place the 'read head' on the next non empty line and returns it
 void parse(java.util.ArrayList<Subtitle> subtitleList)
          
Principal method:
parses file and fill the array list given in parameters with founded subtitles informations
If there's no subtitles found, the array list stays as it was before
protected  java.lang.String readLine()
          Reads and returns the next line in the buffer and increment the line count
protected static java.lang.String subString(java.lang.String str)
          If str length is more than 100 characters, str is cut and returned
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

protected java.io.File file

lineCount

protected int lineCount
Constructor Detail

FileConversion

public FileConversion(java.io.File file,
                      java.lang.String charset)
               throws FileConversionException
Constructs a new instance

Parameters:
file - the file to parse
charset - the charset used to read the file
Throws:
java.lang.NullPointerException - if file or/and charset are null
FileConversionException
Method Detail

parse

public void parse(java.util.ArrayList<Subtitle> subtitleList)
           throws FileConversionException

Principal method:
parses file and fill the array list given in parameters with founded subtitles informations
If there's no subtitles found, the array list stays as it was before

Parameters:
subtitleList - the array of subtitles to fill
Throws:
FileConversionException - if an error occurs during the conversion

getSubtitle

protected abstract Subtitle getSubtitle(java.lang.String line)
                                 throws FileConversionException
Constructs and returns the Subtitle object which represents subtitles information begin at line given in parameters
This method is used by the non abstract parse(ArrayList) method

Parameters:
line - the first line...
Returns:
the founded subtitle or null if there's no subtitle found
Throws:
FileConversionException - if an error occurs during the conversion

readLine

protected java.lang.String readLine()
                             throws FileConversionException
Reads and returns the next line in the buffer and increment the line count

Returns:
the next line or null if there's no more line to read
Throws:
FileConversionException - if a basic IOException occurs when attempts to read in the buffer

getTheNextNonEmptyLine

protected java.lang.String getTheNextNonEmptyLine()
                                           throws FileConversionException
Place the 'read head' on the next non empty line and returns it

Returns:
the next non empty line or null if there's no more line to read
Throws:
FileConversionException

closeReader

protected void closeReader()
                    throws FileConversionException
Closes the reader and reset line count

Throws:
FileConversionException - if a basic IOException occurs when attempts to close the the buffer reader

ensureStringIsValid

protected void ensureStringIsValid(java.lang.String str)
                            throws FileConversionException
Tests the validity of str return true if str is not null and if it is not an empty String, false if not

Throws:
java.io.IOException
FileConversionException

subString

protected static java.lang.String subString(java.lang.String str)
If str length is more than 100 characters, str is cut and returned

Parameters:
str - the string to cut
Returns:
str or a sub string of this array