List of usage examples for java.lang Exception getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.adito.boot.Util.java
/** * Print a TODO message to {@link System#err}, including the current class * and line number call was made along with a specified message. * <p>/*from ww w . ja va 2 s .c o m*/ * Use for temporary debug. Calling statement should be removed. * </p> * * @param message message to display */ public static void toDo(String message) { Exception e; try { throw new Exception(); } catch (Exception ex) { e = ex; } StackTraceElement[] trace = e.getStackTrace(); System.err.println( "[***TODO***] - " + trace[1].getClassName() + ":" + trace[1].getLineNumber() + " - " + message); }
From source file:com.adito.boot.Util.java
/** * Dump an exception to {@link System#err}. * //from w w w .j av a 2 s .c om * @param exception exception to dump */ public static void printStackTrace(Throwable exception) { Exception e; try { throw new Exception(); } catch (Exception ex) { e = ex; } StackTraceElement[] trace = e.getStackTrace(); System.err.println("[REMOVE-ME] - " + trace[1].getClassName() + ":" + trace[1].getLineNumber()); exception.printStackTrace(); }
From source file:com.adito.boot.Util.java
/** * Print some temporary debug to {@link System#err}, including the current * class and line number call was made along with a specified message. * <p>/*from w w w . j a v a 2 s .c om*/ * Use for temporary debug. Calling statement should be removed. * </p> * * @param message message to display */ public static void removeMe(String message) { Exception e; try { throw new Exception(); } catch (Exception ex) { e = ex; } StackTraceElement[] trace = e.getStackTrace(); System.err.println( "[REMOVE-ME] - " + trace[1].getClassName() + ":" + trace[1].getLineNumber() + " - " + message); }
From source file:mp.paschalis.WatchBookActivity.java
/** * Creates a sharing {@link Intent}.//from w ww . j ava 2s. com * * @return The sharing intent. */ private Intent createShareIntent() { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.setType("text/plain"); String root = Environment.getExternalStorageDirectory() + ".SmartLib/Images"; new File(root).mkdirs(); File file = new File(root, app.selectedBook.isbn); try { FileOutputStream os = new FileOutputStream(file); bitmapBookCover.compress(CompressFormat.PNG, 80, os); os.flush(); os.close(); Uri uri = Uri.fromFile(file); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); } catch (Exception e) { Log.e(TAG, e.getStackTrace().toString()); } String bookInfo = "\n\n\n\n " + getString(R.string.bookInfo) + ":\n" + getString(R.string.title) + ": \t\t\t\t" + app.selectedBook.title + "\n" + getString(R.string.author) + ": \t\t\t" + app.selectedBook.authors + "\n" + getString(R.string.isbn) + ": \t\t\t\t" + app.selectedBook.isbn + "\n" + getString(R.string.published_) + " \t" + app.selectedBook.publishedYear + "\n" + getString(R.string.pages_) + " \t\t\t" + app.selectedBook.pageCount + "\n" + getString(R.string.isbn) + ": \t\t\t\t" + app.selectedBook.isbn + "\n" + getString(R.string.status) + ": \t\t\t" + App.getBookStatusString(app.selectedBook.status, WatchBookActivity.this) + "\n\n" + "http://books.google.com/books?vid=isbn" + app.selectedBook.isbn; shareIntent.putExtra(Intent.EXTRA_TEXT, bookInfo); return shareIntent; }
From source file:com.autonomousturk.crawler.WebCrawler.java
private void processPage(WebURL curURL) { if (curURL == null) { return;// w w w . ja v a 2 s. com } PageFetchResult fetchResult = null; try { fetchResult = pageFetcher.fetchHeader(curURL); int statusCode = fetchResult.getStatusCode(); handlePageStatusCode(curURL, statusCode, CustomFetchStatus.getStatusDescription(statusCode)); if (statusCode != HttpStatus.SC_OK) { if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) { if (myController.getConfig().isFollowRedirects()) { String movedToUrl = fetchResult.getMovedToUrl(); if (movedToUrl == null) { return; } int newDocId = docIdServer.getDocId(movedToUrl); if (newDocId > 0) { // Redirect page is already seen return; } WebURL webURL = new WebURL(); webURL.setURL(movedToUrl); webURL.setParentDocid(curURL.getParentDocid()); webURL.setParentUrl(curURL.getParentUrl()); webURL.setDepth(curURL.getDepth()); webURL.setDocid(-1); webURL.setAnchor(curURL.getAnchor()); if (shouldVisit(webURL) && robotstxtServer.allows(webURL)) { webURL.setDocid(docIdServer.getNewDocID(movedToUrl)); frontier.schedule(webURL); } } } else if (fetchResult.getStatusCode() == CustomFetchStatus.PageTooBig) { logger.info("Skipping a page which was bigger than max allowed size: " + curURL.getURL()); } return; } if (!curURL.getURL().equals(fetchResult.getFetchedUrl())) { if (docIdServer.isSeenBefore(fetchResult.getFetchedUrl())) { // Redirect page is already seen return; } curURL.setURL(fetchResult.getFetchedUrl()); curURL.setDocid(docIdServer.getNewDocID(fetchResult.getFetchedUrl())); } Page page = new Page(curURL); int docid = curURL.getDocid(); if (!fetchResult.fetchContent(page)) { onContentFetchError(curURL); return; } if (!parser.parse(page, curURL.getURL())) { onParseError(curURL); return; } ParseData parseData = page.getParseData(); if (parseData instanceof HtmlParseData) { HtmlParseData htmlParseData = (HtmlParseData) parseData; List<WebURL> toSchedule = new ArrayList<>(); int maxCrawlDepth = myController.getConfig().getMaxDepthOfCrawling(); for (WebURL webURL : htmlParseData.getOutgoingUrls()) { webURL.setParentDocid(docid); webURL.setParentUrl(curURL.getURL()); int newdocid = docIdServer.getDocId(webURL.getURL()); if (newdocid > 0) { // This is not the first time that this Url is // visited. So, we set the depth to a negative // number. webURL.setDepth((short) -1); webURL.setDocid(newdocid); } else { webURL.setDocid(-1); webURL.setDepth((short) (curURL.getDepth() + 1)); if (maxCrawlDepth == -1 || curURL.getDepth() < maxCrawlDepth) { if (shouldVisit(webURL) && robotstxtServer.allows(webURL)) { webURL.setDocid(docIdServer.getNewDocID(webURL.getURL())); toSchedule.add(webURL); } } } } frontier.scheduleAll(toSchedule); } try { visit(page); } catch (Exception e) { logger.error("Exception while running the visit method. Message: '" + e.getMessage() + "' at " + e.getStackTrace()[0]); } } catch (Exception e) { logger.error(e.getMessage() + ", while processing: " + curURL.getURL()); } finally { if (fetchResult != null) { fetchResult.discardContentIfNotConsumed(); } } }
From source file:edu.uci.ics.crawler4j.crawler.WebCrawler.java
private void processPage(WebURL curURL) { if (curURL == null) { return;//from ww w . j a v a 2 s.c om } PageFetchResult fetchResult = null; try { fetchResult = pageFetcher.fetchHeader(curURL); int statusCode = fetchResult.getStatusCode(); handlePageStatusCode(curURL, statusCode, CustomFetchStatus.getStatusDescription(statusCode)); if (statusCode != HttpStatus.SC_OK) { if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) { if (myController.getConfig().isFollowRedirects()) { String movedToUrl = fetchResult.getMovedToUrl(); if (movedToUrl == null) { return; } int newDocId = docIdServer.getDocId(movedToUrl); if (newDocId > 0) { // Redirect page is already seen return; } WebURL webURL = new WebURL(); webURL.setURL(movedToUrl); webURL.setParentDocid(curURL.getParentDocid()); webURL.setParentUrl(curURL.getParentUrl()); webURL.setDepth(curURL.getDepth()); webURL.setDocid(-1); webURL.setAnchor(curURL.getAnchor()); if (shouldVisit(webURL) && robotstxtServer.allows(webURL)) { webURL.setDocid(docIdServer.getNewDocID(movedToUrl)); frontier.schedule(webURL); } } } else if (fetchResult.getStatusCode() == CustomFetchStatus.PageTooBig) { LOG.info("Skipping a page which was bigger than max allowed size: " + curURL.getURL()); } return; } if (!curURL.getURL().equals(fetchResult.getFetchedUrl())) { if (docIdServer.isSeenBefore(fetchResult.getFetchedUrl())) { // Redirect page is already seen return; } curURL.setURL(fetchResult.getFetchedUrl()); curURL.setDocid(docIdServer.getNewDocID(fetchResult.getFetchedUrl())); } Page page = new Page(curURL); int docid = curURL.getDocid(); if (!fetchResult.fetchContent(page)) { onContentFetchError(curURL); return; } if (!parser.parse(page, curURL.getURL())) { onParseError(curURL); return; } ParseData parseData = page.getParseData(); if (parseData instanceof HtmlParseData) { HtmlParseData htmlParseData = (HtmlParseData) parseData; List<WebURL> toSchedule = new ArrayList<WebURL>(); int maxCrawlDepth = myController.getConfig().getMaxDepthOfCrawling(); for (WebURL webURL : htmlParseData.getOutgoingUrls()) { webURL.setParentDocid(docid); webURL.setParentUrl(curURL.getURL()); int newdocid = docIdServer.getDocId(webURL.getURL()); if (newdocid > 0) { // This is not the first time that this Url is // visited. So, we set the depth to a negative // number. webURL.setDepth((short) -1); webURL.setDocid(newdocid); } else { webURL.setDocid(-1); webURL.setDepth((short) (curURL.getDepth() + 1)); if (maxCrawlDepth == -1 || curURL.getDepth() < maxCrawlDepth) { if (shouldVisit(webURL) && robotstxtServer.allows(webURL)) { webURL.setDocid(docIdServer.getNewDocID(webURL.getURL())); toSchedule.add(webURL); } } } } frontier.scheduleAll(toSchedule); } try { visit(page); } catch (Exception e) { LOG.error("Exception while running the visit method. Message: '" + e.getMessage() + "' at " + e.getStackTrace()[0]); } } catch (Exception e) { LOG.error(e.getMessage() + ", while processing: " + curURL.getURL()); } finally { if (fetchResult != null) { fetchResult.discardContentIfNotConsumed(); } } }
From source file:gov.llnl.lc.smt.command.fabric.SmtFabric.java
private void showWhatsUp(Map<String, String> map) throws Exception { OsmSession ParentSession = null;/*w w w . j a v a2 s.c om*/ OsmServiceManager OsmService = OsmServiceManager.getInstance(); OsmAdminApi adminInterface = null; String hostNam = map.get(SmtProperty.SMT_HOST.getName()); String portNum = map.get(SmtProperty.SMT_PORT.getName()); try { ParentSession = OsmService.openSession(hostNam, portNum, null, null); adminInterface = ParentSession.getAdminApi(); } catch (Exception e) { logger.severe(e.getStackTrace().toString()); System.exit(0); } if (adminInterface != null) { WhatsUpInfo whatsUp = adminInterface.getWhatsUpInfo(); OSM_Nodes nodes = OMService.getFabric().getOsmNodes(); if (whatsUp != null) { OMS_WhatsUpInfo owu = new OMS_WhatsUpInfo(whatsUp, nodes); OSM_Fabric Fabric = OMService.getFabric(); System.out.println("Whats up on " + Fabric.getFabricName() + "?"); System.out.println(owu.toInfo(" ")); } } }
From source file:gov.nih.nci.cagrid.identifiers.test.StressTestUtil.java
public void testOnlyRegisterGSID(long numberOfTests) { List<String> identifiers = new ArrayList<String>(); String suggestedIdentifier = null; int randomNumber; for (long i = 0l; i < numberOfTests; i++) { randomNumber = rand.nextInt(20); String parentIdentifiers[] = null; // 2 parents 5% if (randomNumber == 0 && identifiers.size() > 2) { int firstIdIndex = rand.nextInt(identifiers.size()); int secondIdIndex = rand.nextInt(identifiers.size()); while (secondIdIndex == firstIdIndex) secondIdIndex = rand.nextInt(identifiers.size()); parentIdentifiers = new String[] { identifiers.get(firstIdIndex), identifiers.get(secondIdIndex) }; }//from www . jav a 2 s . c o m // 1 parent 25 % else if (identifiers.size() > 0 && randomNumber % 4 == 1) { int firstIdIndex = rand.nextInt(identifiers.size()); parentIdentifiers = new String[] { identifiers.get(firstIdIndex) }; } try { String identifier = testUtil.registerGSID(suggestedIdentifier, parentIdentifiers); // if(i%100==0) // System.out.println(i); addElement2List(identifiers, identifier); writeToFile(identifier); } catch (Exception e) { System.out.println("exception occured1 " + e.getMessage()); e.printStackTrace(); StringBuffer sb = new StringBuffer(); for (StackTraceElement temp : e.getStackTrace()) sb.append(temp.getClassName() + "[" + temp.getLineNumber() + "]\n"); log.debug("exception occured \n" + sb.toString()); } } }
From source file:com.actian.services.dataflow.operators.UserAgentParser.java
@Override protected void execute(ExecutionContext context) { RecordInput recordInput = getInput().getInput(context); recordOutput = getOutput().getOutput(context); RecordOutput recordReject = getReject().getOutput(context); ScalarValued[] allInputs = recordInput.getFields(); ScalarSettable[] outputs = TokenUtils.selectFields(recordOutput, recordInput.getType().getNames()); ScalarSettable[] rejects = TokenUtils.selectFields(recordReject, recordInput.getType().getNames()); // Quit early if the operator configuration isn't valid if (checkConfig() == false) { recordOutput.pushEndOfData();//from w w w. ja v a 2 s. c om recordReject.pushEndOfData(); return; } // Create the field name map createNameMap(); // Get an UserAgentStringParser and analyze the requesting client UserAgentStringParser parser = UADetectorServiceFactory.getResourceModuleParser(); while (recordInput.stepNext()) { try { // Copy the original input record fields to the corresponding output record fields TokenUtils.transfer(allInputs, outputs); String userAgentSting = recordInput.getField(getInputField()).toString(); ReadableUserAgent agent = parser.parse(userAgentSting); // Set the values for the user agent fields setOutputField("name", agent.getName()); setOutputField("devicecategory_name", agent.getDeviceCategory().getName()); setOutputField("devicecategory_icon", agent.getDeviceCategory().getIcon()); setOutputField("devicecategory_infourl", agent.getDeviceCategory().getInfoUrl()); setOutputField("useragentfamily", agent.getFamily().getName()); setOutputField("icon", agent.getIcon()); setOutputField("operatingsystem_name", agent.getOperatingSystem().getName()); setOutputField("operatingsystem_icon", agent.getOperatingSystem().getIcon()); setOutputField("operatingsystem_producer", agent.getOperatingSystem().getProducer()); setOutputField("operatingsystem_producerurl", agent.getOperatingSystem().getProducerUrl()); setOutputField("operatingsystem_url", agent.getOperatingSystem().getUrl()); setOutputField("operatingsystem_version", agent.getOperatingSystem().getVersionNumber().toVersionString()); setOutputField("producer", agent.getProducer()); setOutputField("producerurl", agent.getProducerUrl()); setOutputField("typename", agent.getTypeName()); setOutputField("url", agent.getUrl()); setOutputField("version", agent.getVersionNumber().toVersionString()); recordOutput.push(); } catch (Exception e) { // Copy the original input record fields to the corresponding reject record fields TokenUtils.transfer(allInputs, rejects); StringSettable errorField = (StringSettable) recordReject.getField("ErrorText"); errorField.set(e.getMessage() + "\n" + Arrays.toString(e.getStackTrace())); recordReject.push(); } } recordOutput.pushEndOfData(); recordReject.pushEndOfData(); }
From source file:net.mybox.mybox.ServerClientConnection.java
/** * /* www . j av a 2s . co m*/ * @param operation is the original command from the master client * @param arg */ public void sendCatchup(Common.Signal operation, String arg) { if (operation == (Common.Signal.c2s)) { try { System.out.println("catchup s2c to client (" + handle + "): " + arg); File localFile = new File(localDir + "/" + arg); if (localFile.exists()) { sendCommandToClient(Common.Signal.s2c); ByteStream.toStream(outStream, arg); ByteStream.toStream(outStream, localFile.lastModified() + ""); ByteStream.toStream(outStream, localFile); } } catch (Exception e) { System.out.println("catchup s2c to client failed: " + e.getMessage() + e.getStackTrace()); } } else if (operation == Common.Signal.deleteOnServer) { // handles files and directories? try { System.out.println("catchup delete to client (" + handle + "): " + arg); sendCommandToClient(Common.Signal.deleteOnClient); ByteStream.toStream(outStream, arg); } catch (Exception e) { System.out.println("catchup delete to client failed: " + e.getMessage()); } } else if (operation == Common.Signal.renameOnServer) { // handles files and directories? try { System.out.println("catchup rename to client (" + handle + "): " + arg); sendCommandToClient(Common.Signal.renameOnClient); ByteStream.toStream(outStream, arg); } catch (Exception e) { System.out.println("catchup rename to client failed: " + e.getMessage()); } } else if (operation == Common.Signal.createDirectoryOnServer) { try { System.out.println("catchup createDirectoryOnClient (" + handle + "): " + arg); sendCommandToClient(Common.Signal.createDirectoryOnClient); ByteStream.toStream(outStream, arg); } catch (Exception e) { System.out.println("catchup createDirectoryOnClient failed: " + e.getMessage() + e.getStackTrace()); } } else { Server.printMessage("unknown command: " + operation); failedRequestCount++; } }