1 17 18 package org.apache.geronimo.console.derbylogmanager; 19 20 import java.io.BufferedReader ; 21 import java.io.File ; 22 import java.io.FileReader ; 23 import java.io.IOException ; 24 import java.io.InputStreamReader ; 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.Stack ; 28 29 import org.apache.geronimo.console.util.KernelHelper; 30 31 public class DerbyLogHelper extends KernelHelper { 32 private static ArrayList logs = new ArrayList (); 33 34 private static boolean cached = false; 35 36 private static int lineCount = 0; 37 38 private static final String DERBY_SYSTEM_HOME = "derby.system.home"; 39 40 private static final String LOG_FILENAME = "derby.log"; 41 42 public static Collection getLogs() throws IOException { 43 if (!cached) { 44 refresh(); 45 } 46 return logs; 47 } 48 49 public static void refresh() throws IOException { 50 cached = false; 51 logs.clear(); 52 BufferedReader in = new BufferedReader (getFileReader()); 53 lineCount = 0; 54 Stack holder = new Stack (); 55 for (String line = in.readLine(); line != null; line = in.readLine()) { 56 holder.push(line); 57 lineCount++; 58 } 59 logs.addAll(holder); 60 cached = true; 61 } 62 63 public static int getLineCount() { 64 return lineCount; 65 } 66 67 private static InputStreamReader getFileReader() throws IOException { 68 String pathToFile = getSystemHome() + File.separator + LOG_FILENAME; 69 return new FileReader (new File (pathToFile)); 70 } 71 72 public static String getSystemHome() { 73 return System.getProperty(DERBY_SYSTEM_HOME); 74 } 75 76 77 } 78 | Popular Tags |