/** * Method toString ... * * @return String */ @Override public String toString() { try { return "TDHSResponse{" + "status=" + getStatus() + ", errorCode=" + getErrorCode() + ", dbErrorCode=" + getDbErrorCode() + ", MySQLHandlerErrorCode=" + getMySQLHandlerErrorCode() + ", fieldNumber=" + getFieldNumber() + ", fieldTypes=" + getFieldTypes() + ", fieldData=" + getFieldData() + '}'; } catch (TDHSException e) { PrintWriter pw = new PrintWriter(new StringWriter()); e.printStackTrace(pw); return "TDHSResponse parse failed!\n" + pw.toString(); } }
public void write(Exception e, String str) { // TODO 自动生成的方法存根 FileWriter fw = null; try { fw = new FileWriter(filename); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e.printStackTrace(pw); fw.write(pw.toString() + "\n" + str); fw.flush(); fw.close(); } catch (IOException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } finally { try { fw.flush(); fw.close(); } catch (IOException e1) { // TODO 自动生成的 catch 块 e1.printStackTrace(); } } }
@Override public void uncaughtException(Thread thread, Throwable ex) { if (this.defaultUncaughtExceptionHandler != null) { if (mContext != null) { PackageManager manager = mContext.getPackageManager(); PackageInfo info = null; try { info = manager.getPackageInfo(mContext.getPackageName(), 0); } catch (PackageManager.NameNotFoundException e) { Log.e("error", e.toString()); } Writer writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); Log.e("info", printWriter.toString()); // at this point we can log into local files and send information to crashlytics and other // stuffs final AlarmServiceVo userDataCollectorServiceVo = new AlarmServiceVo( Constants.AlarmManager.AlarmManagerRequestCode.COLLECT_USER_DATA, Constants.AlarmManager.COLLECT_USER_DATA_DELAY_MILLISECONDS, Constants.AlarmManager.COLLECT_USER_DATA_PERIODIC_TIME_MILLISECONDS); new UserDataAlarmManager(mContext, PointwiseService.class) .setUpAlarmManager(userDataCollectorServiceVo); final AlarmServiceVo userDataPeekerServiceVo = new AlarmServiceVo( Constants.AlarmManager.AlarmManagerRequestCode.PEEK_USER_DATA, Constants.AlarmManager.PEEK_USER_DATA_DELAY_MILLISECONDS, Constants.AlarmManager.PEEK_USER_DATA_PERIODIC_TIME_MILLISECONDS); new UserDataAlarmManager(mContext, PointwiseSyncService.class) .setUpAlarmManager(userDataPeekerServiceVo); } } }
public void runCommandLoop() { while (true) { int cmd = readInt(); if (cmd == -1) { loader.init(); // init intercom_return(); } else if (cmd == -2) { // shutdown intercom_return(); return; } else // callback { CallbackInfo cb = callbacks.get(cmd); ArrayList<Object> args = new ArrayList<Object>(); for (InterprocType type : cb.getTypes()) { switch (type) { case boolType: args.add(readBool()); break; case int8: args.add(readByte()); break; case int16: args.add(readShort()); break; case int32: args.add(readInt()); break; case int64: args.add(readLong()); break; case floatType: args.add(readFloat()); break; case string: args.add(readString()); break; } } boolean retval = false; try { retval = (Boolean) cb.getMethod().invoke(cb.getObject(), args.toArray()); } catch (Throwable e) { logger_log( LogType.LOG_CRITICAL, "msJavaPlugin-java", "An unhandled exception was thrown in a callback function."); PrintWriter pw = new PrintWriter(new StringWriter()); e.printStackTrace(pw); logger_log(LogType.LOG_CRITICAL, "msJavaPlugin-java", pw.toString()); } intercom_return(retval); } } }
/** * Method getErrorMessage returns the errorMessage of this TDHSResponse object. * * @return the errorMessage (type String) of this TDHSResponse object. */ public String getErrorMessage() { try { return "status=" + getStatus() + ", errorCode=" + getErrorCode() + ", dbErrorCode=" + getDbErrorCode() + ", MySQLHandlerErrorCode=" + getMySQLHandlerErrorCode(); } catch (TDHSException e) { PrintWriter pw = new PrintWriter(new StringWriter()); e.printStackTrace(pw); return "TDHSResponse parse failed!\n" + pw.toString(); } }
public static String printStackToString(Exception e) { PrintWriter printWriter = new PrintWriter(new StringWriter()); e.printStackTrace(printWriter); return printWriter.toString(); }
@Override public String toString() { return out.toString(); }
/** Internal method. Get and check response packet from searchd. */ private byte[] _GetResponse(Socket sock) { /* connect */ DataInputStream sIn = null; InputStream SockInput = null; try { SockInput = sock.getInputStream(); sIn = new DataInputStream(SockInput); } catch (IOException e) { _error = "getInputStream() failed: " + e; return null; } /* read response */ byte[] response = null; short status = 0, ver = 0; int len = 0; try { /* read status fields */ status = sIn.readShort(); ver = sIn.readShort(); len = sIn.readInt(); /* read response if non-empty */ if (len <= 0) { _error = "invalid response packet size (len=" + len + ")"; return null; } response = new byte[len]; sIn.readFully(response, 0, len); /* check status */ if (status == SEARCHD_WARNING) { DataInputStream in = new DataInputStream(new ByteArrayInputStream(response)); int iWarnLen = in.readInt(); _warning = new String(response, 4, iWarnLen); System.arraycopy(response, 4 + iWarnLen, response, 0, response.length - 4 - iWarnLen); } else if (status == SEARCHD_ERROR) { _error = "searchd error: " + new String(response, 4, response.length - 4); return null; } else if (status == SEARCHD_RETRY) { _error = "temporary searchd error: " + new String(response, 4, response.length - 4); return null; } else if (status != SEARCHD_OK) { _error = "searched returned unknown status, code=" + status; return null; } } catch (IOException e) { if (len != 0) { /* get trace, to provide even more failure details */ PrintWriter ew = new PrintWriter(new StringWriter()); e.printStackTrace(ew); ew.flush(); ew.close(); String sTrace = ew.toString(); /* build error message */ _error = "failed to read searchd response (status=" + status + ", ver=" + ver + ", len=" + len + ", trace=" + sTrace + ")"; } else { _error = "received zero-sized searchd response (searchd crashed?): " + e.getMessage(); } return null; } finally { if (_socket == null) { try { if (sIn != null) sIn.close(); if (sock != null && !sock.isConnected()) sock.close(); } catch (IOException e) { /* silently ignore close failures; nothing could be done anyway */ } } } return response; }
public static String print(Exception ex) { PrintWriter writer = new PrintWriter(new BufferedOutputStream(new ByteArrayOutputStream())); ex.printStackTrace(writer); return writer.toString(); }
public String getResponseString() { return writer.toString(); }
public synchronized String toString() { return actual.toString(); }