01: /*
02: * Hammurapi
03: * Automated Java code review system.
04: * Copyright (C) 2004 Hammurapi Group
05: *
06: * This program is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU General Public License as published by
08: * the Free Software Foundation; either version 2 of the License, or
09: * (at your option) any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19: *
20: * URL: http://www.hammurapi.org
21: * e-Mail: support@hammurapi.biz
22: */
23:
24: // --- FIX ---
25: package org.hammurapi.inspectors.testcases.fixes;
26:
27: import java.io.FileInputStream;
28: import java.io.InputStream;
29:
30: import org.hammurapi.inspectors.testcases.HammurapiTestCasesException;
31:
32: /**
33: * MaxLinesInFileRule
34: * @author Pavel Vlasov
35: * @version $Revision: 1.1 $
36: */
37: public class MaxLinesInFileRuleFixTestCase {
38:
39: private static org.apache.log4j.Logger logger = org.apache.log4j.Logger
40: .getRootLogger();
41:
42: private static final String FILE_ERROR_TXT = "File error";
43: private static final int POS_1 = 1;
44: private static final int POS_2 = 2;
45: private static final int POS_3 = 3;
46: private static final int POS_4 = 4;
47:
48: /** Java doc automaticaly generated by Hammurapi */
49: public int getFirstByte(final String fName)
50: throws HammurapiTestCasesException {
51:
52: return getByte(fName, POS_1);
53: }
54:
55: /** Java doc automaticaly generated by Hammurapi */
56: public int getSecondByte(final String fName)
57: throws HammurapiTestCasesException {
58:
59: return getByte(fName, POS_2);
60: }
61:
62: /** Java doc automaticaly generated by Hammurapi */
63: public int getThirdByte(final String fName)
64: throws HammurapiTestCasesException {
65:
66: return getByte(fName, POS_2);
67: }
68:
69: /** Java doc automaticaly generated by Hammurapi */
70: public int getFourthByte(final String fName)
71: throws HammurapiTestCasesException {
72:
73: return getByte(fName, POS_2);
74: }
75:
76: private int getByte(final String fName, final int pos)
77: throws HammurapiTestCasesException {
78:
79: try {
80: InputStream is = new FileInputStream(fName);
81: int retVal = 0;
82: int i = 0;
83: while (i < pos) {
84: retVal = is.read();
85: }
86: return retVal;
87:
88: } catch (Exception e) {
89: logger.fatal(FILE_ERROR_TXT, e);
90: throw new HammurapiTestCasesException(e);
91: }
92: }
93: }
94: // --- END FIX ---
|