/** * @param superClass * @param classloader * @param classes * @param packagePath * @throws FileNotFoundException * @throws IOException */ private static void enumerateCompressedPackage( String prefix, Class superClass, ClassLoader classloader, LinkedList<Class> classes, File packagePath) throws FileNotFoundException, IOException { FileInputStream fileinputstream = new FileInputStream(packagePath); ZipInputStream zipinputstream = new ZipInputStream(fileinputstream); ZipEntry zipentry = null; do { zipentry = zipinputstream.getNextEntry(); if (zipentry != null && zipentry.getName().endsWith(".class")) { String classFileName = zipentry.getName(); String className = classFileName.lastIndexOf('/') > -1 ? classFileName.substring(classFileName.lastIndexOf('/') + 1) : classFileName; if (prefix == null || className.startsWith(prefix)) { try { String fullClassName = classFileName.substring(0, classFileName.length() - 6).replaceAll("/", "."); checkAndAddClass(classloader, superClass, classes, fullClassName); } catch (Exception ex) { } } } } while (zipentry != null); fileinputstream.close(); }
private static void checkLogRecords(File log) throws Exception { System.out.println("Checking log records in file: " + log); FileInputStream in = new FileInputStream(log); String EXPECTED_LOG = "SEVERE: Log message 1 string"; try { BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String line; String[] record = new String[2]; int count = 0; int i = 0; while ((line = reader.readLine()) != null) { line = line.trim(); System.out.println(line); record[i++] = line; if (i == 2) { i = 0; // check log message if (!record[1].equals(EXPECTED_LOG)) { // it can sometime happen that some static initializer // in the system will log an error message - due to e.g. // some kind of misconfiguration or system settings. // For instance - somethink like: // INFO: currency.properties entry for FR ignored // because the value format is not recognized. // instead of failing if we get such an unexpected // message, we will simply print that out. System.out.println("*** WARNING: Unexpected log: " + record[1]); continue; } count++; // check source class name and method String[] ss = record[0].split("\\s+"); int len = ss.length; if (!ss[len - 2].equals("SourceClassName") || !ss[len - 1].equals("writeLogRecords")) { throw new RuntimeException("Unexpected source: " + ss[len - 2] + " " + ss[len - 1]); } } } if (count != 3) { throw new RuntimeException("Unexpected number of records: " + count); } } finally { in.close(); } }