FileDocCategorySizeDatePackage
CDReleaseDataAccessImportExport.javaAPI DocExample2401Thu May 05 05:27:58 BST 2005com.samscdrental.importexport

CDReleaseDataAccessImportExport

public class CDReleaseDataAccessImportExport extends Object

Title: Sams CD Rental Store

Description:

Copyright: Copyright (c) 2004

Company:

author
Ken Pugh
version
1.0

Fields Summary
private CDReleaseDataAccess
theCDReleaseCollection
private static final String
ERROR_OPENING_CDRELEASE_FILE
private static final String
ERROR_CLOSING_CDRELEASE_FILE
private static final String
ERROR_READING_CDRELEASE_FILE
Constructors Summary
public CDReleaseDataAccessImportExport(CDReleaseDataAccess aCDReleaseStateCollection)

		theCDReleaseCollection = aCDReleaseStateCollection;
	
Methods Summary
public voidaddCDReleasesFromFile(java.lang.String filename)

		BufferedReader in = null;
		FileReader fileReader = null;
		StringBuffer errorString = new StringBuffer();
		boolean errorOccurred = false;

		try
		{
			fileReader = new FileReader( filename );
			in = new BufferedReader( fileReader );
		}
		catch ( FileNotFoundException exception )
		{
			throw new ImportFileDeviation(
				ERROR_OPENING_CDRELEASE_FILE +
				filename, exception );
		}
		try
		{
			String line = null;
			// Keep reading till the end of the file
			while ( ( line = in.readLine() ) != null )
			{
				if ( line.length() > 0 )
				{
					try
					{
						CDRelease aCDRelease = CDReleaseImportExport.parseLine(
							line );
						theCDReleaseCollection.add( aCDRelease );
					}
					catch ( ParseLineDeviation e )
					{
						errorString.append( e.getMessage() );
						errorOccurred = true;
					}
				}
			}
		}
		catch ( IOException exception )
		{
			throw new ImportFileDeviation( ERROR_READING_CDRELEASE_FILE +
										   filename, exception );

		}
		finally
		{
			try
			{
				in.close();
			}
			catch ( IOException exception )
			{
				throw new SeriousErrorException(
					ERROR_CLOSING_CDRELEASE_FILE +
					filename, exception );
			}
		}
		if ( errorOccurred )
		{
			throw new ImportFormatDeviation( errorString.toString() );
		}
		return;