/** * Creates the logfile to write log-infos into. * * @return The writer object instance */ private static PrintWriter createLogFile() { String tempDir = System.getProperty("java.io.tmpdir"); File tempDirFile = new File(tempDir); try { tempDirFile.mkdirs(); } catch (RuntimeException e) { e.printStackTrace(); } String logfilename = LOGFILENAME; System.out.println("creating Logfile: '" + logfilename + "' in: '" + tempDir + "'"); File out = new File(tempDir, logfilename); PrintWriter logfile; if (tempDirFile.canWrite()) { try { BufferedWriter fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out), "UTF-8")); logfile = setLogFile(new PrintWriter(fw)); } catch (Exception e) { logfile = null; e.printStackTrace(); } } else { logfile = null; System.err.println("Fatal: cannot write File: '" + logfilename + "' into: " + tempDirFile); } return logfile; }
public static void doThis() { try { NonRTException.entry(); RTException.entry(); } catch (RuntimeException e) { e.printStackTrace(); // } catch (IOException e) { // e.printStackTrace(); } }
public static void main(String[] args) { String inputMaf = null; String outputMaf = null; // default config params boolean useCache = true; // use cache or not boolean sort = false; // sort output MAF cols or not boolean addMissing = false; // add missing standard cols or not // process program arguments int i; for (i = 0; i < args.length; i++) { if (args[i].startsWith("-")) { if (args[i].equalsIgnoreCase("-nocache")) { useCache = false; } else if (args[i].equalsIgnoreCase("-sort")) { sort = true; } else if (args[i].equalsIgnoreCase("-std")) { addMissing = true; } } else { break; } } if (args.length - i < 2) { System.out.println( "command line usage: oncotateMaf.sh [-nocache] [-sort] [-std] " + "<input_maf_file> <output_maf_file>"); System.exit(1); } inputMaf = args[i]; outputMaf = args[i + 1]; int oncoResult = 0; try { oncoResult = driver(inputMaf, outputMaf, useCache, sort, addMissing); } catch (RuntimeException e) { System.out.println("Fatal error: " + e.getMessage()); e.printStackTrace(); System.exit(1); } finally { // check errors at the end if (oncoResult != 0) { // TODO produce different error codes, for different types of errors? System.out.println("Process completed with " + oncoResult + " error(s)."); System.exit(2); } } }
/** * @param path * @return byte or null */ public byte[] getFile(String path) { Log.d(TAG, "get file " + path); // NON-NLS File f = new File(getFullCachePath(path)); if (!f.exists()) { Log.w(TAG, "file: " + f.toString() + " not exists"); // NON-NLS return null; } try { ByteArrayOutputStream out = new ByteArrayOutputStream(); FileInputStream fileInputStream = new FileInputStream(f); byte[] buf = new byte[1024]; int numRead = 0; while ((numRead = fileInputStream.read(buf)) != -1) out.write(buf, 0, numRead); fileInputStream.close(); return out.toByteArray(); } catch (FileNotFoundException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (StreamCorruptedException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (IOException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (IllegalArgumentException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (RuntimeException e) { // не позволим кэшу убить нашу программу Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (Exception e) { // не позволим кэшу убить нашу программу Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // session属于http范畴,所以要将ServletRequest转换成httpServletRequest try { HttpServletRequest req = (HttpServletRequest) request; HttpSession session = req.getSession(); if (session.getAttribute("username") != null) { chain.doFilter(request, response); } else { request.getRequestDispatcher("error.jsp").forward(request, response); } } catch (RuntimeException e) { e.printStackTrace(); } }
public JSSA(Type.Class c, DataInput in, ConstantPool cp) throws IOException { super(c, in, cp); local = new Expr[maxLocals]; stack = new Expr[maxStack]; int n = 0; if (!isStatic()) local[n++] = new Argument("this", method.getDeclaringClass()); for (int i = 0; i < this.method.getNumArgs(); i++) local[n++] = new Argument("arg" + i, this.method.getArgType(i)); for (int i = 0; i < size(); i++) { int op = get(i); Object arg = getArg(i); try { Object o = addOp(op, arg); if (o != null) { ops[numOps] = o; ofs[numOps++] = i; } } catch (RuntimeException e) { System.err.println("Had a problem at PC: " + i + " of " + method); e.printStackTrace(); throw new IOException("invalid class file"); } } }
/** * @param path * @param t * @return */ public List<?> getList(String path, java.lang.reflect.Type t) { Log.d(TAG, "get list " + path); // NON-NLS File f = new File(getFullCachePath(path)); if (!f.exists()) { Log.w(TAG, "file: " + f.toString() + " not exists"); // NON-NLS return null; } List<?> list; try { StringBuffer fileData = new StringBuffer(); BufferedReader reader = new BufferedReader(new FileReader(f)); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); } reader.close(); String json = fileData.toString(); Log.d(TAG, "cache: " + json); // NON-NLS list = gson.fromJson(json, t); } catch (FileNotFoundException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (StreamCorruptedException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (IOException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (JsonSyntaxException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (IllegalArgumentException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (RuntimeException e) { // не позволим кэшу убить нашу программу Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (Exception e) { // не позволим кэшу убить нашу программу Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } return list; }
public <T> T get(String path, Class<T> c) { Log.d(TAG, "get " + path); // NON-NLS File f = new File(getFullCachePath(path)); if (!f.exists()) { Log.w(TAG, "file: " + f.toString() + " not exists"); // NON-NLS return null; } T object; try { StringBuffer fileData = new StringBuffer(); BufferedReader reader = new BufferedReader(new FileReader(f)); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); } reader.close(); String json = fileData.toString(); Log.d(TAG, "cache: " + json); // NON-NLS object = getGson().fromJson(json, c); } catch (FileNotFoundException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (StreamCorruptedException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (IOException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (JsonSyntaxException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (IllegalArgumentException e) { Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (RuntimeException e) { // не позволим кэшу убить нашу программу Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } catch (Exception e) { // не позволим кэшу убить нашу программу Log.w(TAG, e.getMessage()); e.printStackTrace(); absoluteDelete(path); return null; } if (object.getClass().toString().equals(c.toString())) return object; else return null; }
// private static final ArrayList<String> ignoreSuffixes = new // ArrayList<>(Arrays.asList("Customizer", "BeanInfo")); // private static final int ignoreSuffixesSize = ignoreSuffixes.size(); // TODO: does this need synchronized? slows it down... private Class<?> loadClassInternal(String className, boolean resolve) throws ClassNotFoundException { /* This may not be a good idea, Groovy looks for all sorts of bogus class name but there may be a reason so not doing this or looking for other patterns: for (int i = 0; i < ignoreSuffixesSize; i++) { String ignoreSuffix = ignoreSuffixes.get(i); if (className.endsWith(ignoreSuffix)) { ClassNotFoundException cfne = new ClassNotFoundException("Ignoring Groovy style bogus class name " + className); classCache.put(className, cfne); throw cfne; } } */ Class<?> c = null; try { // classes handled opposite of resources, try parent first (avoid java.lang.LinkageError) try { ClassLoader cl = getParent(); c = cl.loadClass(className); } catch (ClassNotFoundException | NoClassDefFoundError e) { // do nothing, common that class won't be found if expected in additional JARs and class // directories } catch (RuntimeException e) { e.printStackTrace(); throw e; } if (c == null) { try { if (trackKnown) { File classFile = knownClassFiles.get(className); if (classFile != null) c = makeClass(className, classFile); if (c == null) { JarEntryInfo jei = knownClassJarEntries.get(className); if (jei != null) c = makeClass(className, jei.file, jei.entry, jei.jarLocation); } } // not found in known? search through all c = findJarClass(className); } catch (Exception e) { System.out.println( "Error loading class [" + className + "] from additional jars: " + e.toString()); e.printStackTrace(); } } // System.out.println("Loading class name [" + className + "] got class: " + c); if (c == null) { ClassNotFoundException cnfe = new ClassNotFoundException("Class " + className + " not found."); if (rememberClassNotFound) { // Groovy seems to look, then re-look, for funny names like: // groovy.lang.GroovyObject$java$io$org$moqui$entity$EntityListIterator // java.io.org$moqui$entity$EntityListIterator // groovy.util.org$moqui$context$ExecutionContext // org$moqui$context$ExecutionContext // Groovy does similar with *Customizer and *BeanInfo; so just don't remember any of these // In general it seems that anything with a '$' needs to be excluded if (!className.contains("$") && !className.endsWith("Customizer") && !className.endsWith("BeanInfo")) { ClassNotFoundException existingExc = notFoundCache.putIfAbsent(className, cnfe); if (existingExc != null) throw existingExc; } } throw cnfe; } else { classCache.put(className, c); } return c; } finally { if (c != null && resolve) resolveClass(c); } }