ER-041 Method is too long

Severity2
Enabledyes
Waivable
Configuration
Allowed maximum line length of the methods:
max-lines: 100
Violation
public int getByte(final String fName,  final String which)throws HammurapiTestCasesException {
	if (CASE_TXT1.compareTo(which)==0) {
		try {
			InputStream is = new FileInputStream(fName);
			return is.read();
		} catch (IOException e) {
			logger.error(FILE_ERROR_TXT, e);
			throw new HammurapiTestCasesException(e);
		}
	} else if (CASE_TXT2.compareTo(which)==0) {
		try {
			InputStream is = new FileInputStream(fName);
			is.read();
			return is.read();
		} catch (IOException e) {
			logger.error(FILE_ERROR_TXT, e);
			throw new HammurapiTestCasesException(e);
		}
	} else if (CASE_TXT3.compareTo(which)==0) {
		try {
			InputStream is = new FileInputStream(fName);
			is.read();
			is.read();
			return is.read();
		} catch (IOException e) {
			logger.error(FILE_ERROR_TXT, e);
			throw new HammurapiTestCasesException(e);
		}
	} else {
		try {
			InputStream is = new FileInputStream(fName);
			is.read();
			is.read();
			is.read();
			return is.read();
		} catch (IOException e) {
			logger.error(FILE_ERROR_TXT, e);
			throw new HammurapiTestCasesException(e);
		}
	}
}
Fix
public int getByte(final String fName,  final String which) throws HammurapiTestCasesException {
	if (CASE_TXT1.compareTo(which)==0) {
		return getByte(fName, CASE_NBR1);
	} else if (CASE_TXT2.compareTo(which)==0) {
		return getByte(fName, CASE_NBR2);
	} else if (CASE_TXT3.compareTo(which)==0) {
		return getByte(fName, CASE_NBR3);
	} else {
		return getByte(fName, CASE_NBR4);
	}
}
public int getByte(final String fName,  final int nbr)throws HammurapiTestCasesException {
	try {
		InputStream is = new FileInputStream(fName);
		int c = 0;
		int retVal = 0;
		while (c


Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.