List of usage examples for java.lang Throwable printStackTrace
public void printStackTrace()
From source file:com.frostwire.gui.bittorrent.HttpBTDownload.java
static boolean copyPlayingTemp(File temp, File dest) { boolean r;//ww w . j av a2 s .co m System.out.println(temp); try { FileUtils.copyFile(temp, dest); r = true; } catch (Throwable e) { e.printStackTrace(); r = false; } return r; }
From source file:com.moss.greenshell.wizard.catastrophe.PostMortemScreen.java
public static void submitErrorReport(final Throwable cause, final ErrorReportDecorator... decorators) throws Exception { List<ErrorReportChunk> chunks = new LinkedList<ErrorReportChunk>(); try {/*ww w . j a v a2 s .c o m*/ if (cause instanceof InternalErrorException) { InternalErrorException ie = (InternalErrorException) cause; ErrorReportChunk chunk = new ErrorReportChunk("internal-error-id", "text/plain", ie.id().getBytes("UTF8")); chunks.add(chunk); } else if (cause instanceof SOAPFaultException) { SOAPFaultException soapFault = (SOAPFaultException) cause; String content = soapFault.getFault().getFirstChild().getTextContent(); String prefix = "Internal Service Error Occurred: "; if (content.startsWith(prefix)) { String id = content.substring(prefix.length()); ErrorReportChunk chunk = new ErrorReportChunk("internal-error-id", "text/plain", id.getBytes("UTF8")); chunks.add(chunk); } } } catch (Throwable t) { t.printStackTrace(); } // STACK TRACE ByteArrayOutputStream stackBytes = new ByteArrayOutputStream(); PrintStream stackPrintStream = new PrintStream(stackBytes); cause.printStackTrace(stackPrintStream); stackPrintStream.close(); stackBytes.close(); ErrorReportChunk chunk = new ErrorReportChunk("stack trace", "text/plain", stackBytes.toByteArray()); chunks.add(chunk); // THREAD DUMP ByteArrayOutputStream dumpBytes = new ByteArrayOutputStream(); PrintStream out = new PrintStream(dumpBytes); Map<Thread, StackTraceElement[]> traceMap = Thread.getAllStackTraces(); for (Map.Entry<Thread, StackTraceElement[]> next : traceMap.entrySet()) { out.println(); out.println(next.getKey().getName()); for (StackTraceElement line : next.getValue()) { String className = emptyIfNull(line.getClassName()); String methodName = emptyIfNull(line.getMethodName()); String fileName = emptyIfNull(line.getFileName()); out.println(" " + className + "." + methodName + " (" + fileName + " line " + line.getLineNumber() + ")"); } } out.flush(); out.close(); ErrorReportChunk stackDump = new ErrorReportChunk("thread dump", "text/plain", dumpBytes.toByteArray()); chunks.add(stackDump); // SYSTEM PROPERTIES ByteArrayOutputStream propsBytes = new ByteArrayOutputStream(); PrintStream propsOut = new PrintStream(propsBytes); for (Map.Entry<Object, Object> next : System.getProperties().entrySet()) { propsOut.println(" " + next.getKey() + "=" + next.getValue()); } propsOut.flush(); propsOut.close(); chunks.add(new ErrorReportChunk("system properties", "text/plain", propsBytes.toByteArray())); // LOCAL CLOCK chunks.add(new ErrorReportChunk("local clock", "text/plain", new DateTime().toString().getBytes())); // NETWORKING StringBuffer networking = new StringBuffer(); Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces(); while (ifaces.hasMoreElements()) { NetworkInterface iface = ifaces.nextElement(); networking.append("INTERFACE: " + iface.getName() + " (" + iface.getDisplayName() + ")\n"); Enumeration<InetAddress> addresses = iface.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); networking.append(" Address:" + address.getHostAddress() + "\n"); networking.append(" Cannonical Host Name: " + address.getCanonicalHostName() + "\n"); networking.append(" Host Name: " + address.getHostName() + "\n"); } } chunks.add(new ErrorReportChunk("network configuration", "text/plain", networking.toString().getBytes())); // DECORATORS if (decorators != null) { for (ErrorReportDecorator decorator : decorators) { chunks.addAll(decorator.makeChunks(cause)); } } ErrorReport report = new ErrorReport(chunks); Reporter reporter = new Reporter(); ReportId id = reporter.submitReport(report); }
From source file:models.utils.FileIoUtils.java
/** * This will display all files except for empty.txt refined 20130918 * //w ww. java 2s . c o m * @param folderName * @return */ public static List<String> getFileNamesInFolder(String folderName) { List<String> fileNameList = new ArrayList<String>(); try { VirtualFile virtualDir = VirtualFile.fromRelativePath(folderName); List<VirtualFile> virtualFileList = virtualDir.list(); if (virtualFileList == null) { models.utils.LogUtils.printLogError( "virtualFileList is NULL! in getFileNamesInFolder()" + DateUtils.getNowDateTimeStrSdsm()); } models.utils.LogUtils.printLogNormal( "Under folder: " + folderName + ", File/dir count is " + virtualFileList.size()); for (int i = 0; i < virtualFileList.size(); i++) { if (virtualFileList.get(i).getRealFile().isFile()) { String fileName = virtualFileList.get(i).getName(); if ((!fileName.equalsIgnoreCase(VarUtils.FILE_NAME_APP_LOG_EMPTY))) { if (VarUtils.IN_DETAIL_DEBUG) { models.utils.LogUtils.printLogNormal("File " + fileName); } fileNameList.add(fileName); } } else if (virtualFileList.get(i).getRealFile().isDirectory()) { models.utils.LogUtils.printLogNormal("Directory " + virtualFileList.get(i).getName()); } } // end for } catch (Throwable t) { t.printStackTrace(); } return fileNameList; }
From source file:com.taobao.android.builder.tasks.manager.transform.TransformManager.java
public static <T extends Transform> T createTransform(AppVariantContext appVariantContext, BaseVariantOutputData vod, Class<T> clazz) { if (null == clazz) { return null; }/*from w w w . j a v a2 s .c om*/ try { return (T) getConstructor(appVariantContext, clazz).newInstance(appVariantContext, vod); } catch (Throwable e) { e.printStackTrace(); } return null; }
From source file:io.fabric8.forge.ipaas.repository.NexusConnectionRepository.java
private static String loadCamelConnectorJSonSchema(URL url) { try {/*from w w w .ja v a 2 s.c o m*/ // is it a JAR file URLClassLoader child = new URLClassLoader(new URL[] { url }); InputStream is = child.getResourceAsStream("camel-connector.json"); if (is != null) { return loadText(is); } IOHelpers.close(is); } catch (Throwable e) { e.printStackTrace(); // ignore } return null; }
From source file:DeliverWork.java
public static boolean syncTheFile(String projectId, String projectForm) { String resultBody = getResultBody("http://59.215.226.169/web/leavePoorFileService?id=" + projectForm); if (resultBody != null) { RemoteResult<RemoteFile> remoteFileRemoteResult = null; try {/* w ww . j av a 2 s. com*/ remoteFileRemoteResult = JSON.parseObject(resultBody, new TypeReference<RemoteResult<RemoteFile>>() { }); if (remoteFileRemoteResult != null && remoteFileRemoteResult.getCode().equals("OK")) { for (RemoteFile item : remoteFileRemoteResult.getData()) { String result = saveIntoWeed(item, projectId); String sync = "1"; if (!"success".equals(result)) { sync = result; //? } //2 // projectApplyMapper.insertProjectBak(projectForm, JSON.toJSONString(item), "2", sync); } } } catch (Throwable throwable) { throwable.printStackTrace(); } } return true; }
From source file:com.frostwire.android.gui.UniversalScanner.java
private static Uri nativeScanFile(Context context, String path) { try {/* w w w . ja v a 2 s . c o m*/ File f = new File(path); Class<?> clazz = Class.forName("android.media.MediaScanner"); Constructor<?> mediaScannerC = clazz.getDeclaredConstructor(Context.class); Object scanner = mediaScannerC.newInstance(context); try { Method setLocaleM = clazz.getDeclaredMethod("setLocale", String.class); setLocaleM.invoke(scanner, Locale.US.toString()); } catch (Throwable e) { e.printStackTrace(); } Field mClientF = clazz.getDeclaredField("mClient"); mClientF.setAccessible(true); Object mClient = mClientF.get(scanner); Method scanSingleFileM = clazz.getDeclaredMethod("scanSingleFile", String.class, String.class, String.class); Uri fileUri = (Uri) scanSingleFileM.invoke(scanner, f.getAbsolutePath(), "external", "data/raw"); int n = context.getContentResolver().delete(fileUri, null, null); if (n > 0) { LOG.debug("Deleted from Files provider: " + fileUri); } Field mNoMediaF = mClient.getClass().getDeclaredField("mNoMedia"); mNoMediaF.setAccessible(true); mNoMediaF.setBoolean(mClient, false); // This is only for HTC (tested only on HTC One M8) try { Field mFileCacheF = clazz.getDeclaredField("mFileCache"); mFileCacheF.setAccessible(true); mFileCacheF.set(scanner, new HashMap<String, Object>()); } catch (Throwable e) { // no an HTC, I need some time to refactor this hack } try { Field mFileCacheF = clazz.getDeclaredField("mNoMediaPaths"); mFileCacheF.setAccessible(true); mFileCacheF.set(scanner, new HashMap<String, String>()); } catch (Throwable e) { e.printStackTrace(); } Method doScanFileM = mClient.getClass().getDeclaredMethod("doScanFile", String.class, String.class, long.class, long.class, boolean.class, boolean.class, boolean.class); Uri mediaUri = (Uri) doScanFileM.invoke(mClient, f.getAbsolutePath(), null, f.lastModified(), f.length(), false, true, false); Method releaseM = clazz.getDeclaredMethod("release"); releaseM.invoke(scanner); return mediaUri; } catch (Throwable e) { e.printStackTrace(); return null; } }
From source file:models.utils.FileIoUtils.java
/** * Output both This will display all files except for empty.txt refined * 20130918//from ww w . ja v a2 s . co m * * @param folderName * @return */ public static void getFileAndDirNamesInFolder(String folderName, List<String> fileNames, List<String> dirNames) { if (fileNames == null) { fileNames = new ArrayList<String>(); } if (dirNames == null) { dirNames = new ArrayList<String>(); } try { VirtualFile virtualDir = VirtualFile.fromRelativePath(folderName); List<VirtualFile> virtualFileList = virtualDir.list(); if (virtualFileList == null) { models.utils.LogUtils.printLogError( "virtualFileList is NULL! in getFileNamesInFolder()" + DateUtils.getNowDateTimeStrSdsm()); } models.utils.LogUtils.printLogNormal( "Under folder: " + folderName + ", File/dir count is " + virtualFileList.size()); for (int i = 0; i < virtualFileList.size(); i++) { String fileOrDirName = virtualFileList.get(i).getName(); if (virtualFileList.get(i).getRealFile().isFile()) { if ((!fileOrDirName.equalsIgnoreCase(VarUtils.FILE_NAME_APP_LOG_EMPTY))) { if (VarUtils.IN_DETAIL_DEBUG) { models.utils.LogUtils.printLogNormal("File " + fileOrDirName); } fileNames.add(fileOrDirName); } } else if (virtualFileList.get(i).getRealFile().isDirectory()) { models.utils.LogUtils.printLogNormal("Directory " + fileOrDirName); dirNames.add(fileOrDirName); } } // end for } catch (Throwable t) { t.printStackTrace(); } }
From source file:models.utils.FileIoUtils.java
/** * This will delete all files and folder under the path. Very careful * 20130918/* w w w . ja v a 2s .c om*/ * * SAFE GUARD: only with adhoc logs * * @param folderName * @return */ public static boolean deleteAllFileAndDirInFolder(String folderName) { boolean success = true; // safeguard: if (!(folderName.contains("adhoc") || folderName.contains("logs"))) { models.utils.LogUtils.printLogError( "Looks like this folder is not logs folder in deleteAllFileAndDirInFolder(). Safeguard activated. " + "NO OPS on this case. Return. ForderName:" + folderName); return success; } try { VirtualFile virtualDir = VirtualFile.fromRelativePath(folderName); List<VirtualFile> virtualFileList = virtualDir.list(); if (virtualFileList == null) { models.utils.LogUtils.printLogError( "virtualFileList is NULL! in getFileNamesInFolder()" + DateUtils.getNowDateTimeStrSdsm()); } models.utils.LogUtils.printLogNormal( "Delete: Under folder: " + folderName + ", File/dir count is " + virtualFileList.size()); for (int i = 0; i < virtualFileList.size(); i++) { if (virtualFileList.get(i).getRealFile().isFile()) { String fileName = virtualFileList.get(i).getName(); if ((!fileName.equalsIgnoreCase(VarUtils.FILE_NAME_APP_LOG_EMPTY))) { if (VarUtils.IN_DETAIL_DEBUG) { models.utils.LogUtils.printLogNormal("File " + fileName); } FileUtils.forceDelete(virtualFileList.get(i).getRealFile()); } } else if (virtualFileList.get(i).getRealFile().isDirectory()) { models.utils.LogUtils.printLogNormal("Directory " + virtualFileList.get(i).getName()); FileUtils.deleteDirectory(virtualFileList.get(i).getRealFile()); } } // end for } catch (Throwable t) { t.printStackTrace(); success = false; } return success; }
From source file:io.cloudine.rhq.plugins.worker.ResourceUtils.java
/** * ? ? . ? ? ? ? ? ? ? ? ? ? ? <tt>null</tt>?? ? ? * ? ? .//from w w w . j a v a 2 s.c om * * @return ? ? */ private static ClassLoader getDefaultClassLoader() { ClassLoader cl = null; try { cl = Thread.currentThread().getContextClassLoader(); } catch (Throwable e) { e.printStackTrace(); System.out.println("Cannot access context loader of thread. Use system class loader"); } if (cl == null) { // ? ? ? ? -> ? ?? ? ? cl = ResourceUtils.class.getClassLoader(); } return cl; }