1 23 24 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 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 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 49 public int getFirstByte(final String fName) 50 throws HammurapiTestCasesException { 51 52 return getByte(fName, POS_1); 53 } 54 55 56 public int getSecondByte(final String fName) 57 throws HammurapiTestCasesException { 58 59 return getByte(fName, POS_2); 60 } 61 62 63 public int getThirdByte(final String fName) 64 throws HammurapiTestCasesException { 65 66 return getByte(fName, POS_2); 67 } 68 69 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 96 | Popular Tags |