KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hammurapi > inspectors > testcases > fixes > MaxLinesInFileRuleFixTestCase


1 /*
2  * Hammurapi
3  * Automated Java code review system.
4  * Copyright (C) 2004 Hammurapi Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (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 JavaDoc;
28 import java.io.InputStream JavaDoc;
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 =
40         org.apache.log4j.Logger.getRootLogger();
41
42     private static final String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc fName)
71         throws HammurapiTestCasesException {
72     
73         return getByte(fName, POS_2);
74     }
75
76     private int getByte(final String JavaDoc fName, final int pos)
77         throws HammurapiTestCasesException {
78             
79         try {
80             InputStream JavaDoc is = new FileInputStream JavaDoc(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 JavaDoc e) {
89             logger.fatal(FILE_ERROR_TXT, e);
90             throw new HammurapiTestCasesException(e);
91         }
92     }
93 }
94 // --- END FIX ---
95

96
Popular Tags