Created
June 29, 2017 07:44
-
-
Save bugparty/6d1f1084485d61eb91b616b7cd14e023 to your computer and use it in GitHub Desktop.
Write Exception object to string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.support.annotation.NonNull; | |
import java.io.ByteArrayOutputStream; | |
import java.io.IOException; | |
import java.io.OutputStream; | |
import java.io.PrintStream; | |
import java.io.PrintWriter; | |
import java.io.UnsupportedEncodingException; | |
import java.io.Writer; | |
import static java.nio.charset.StandardCharsets.UTF_8; | |
/** | |
* Created by bowman_apple on 2017/5/22. | |
*/ | |
public class ExceptionWriter{ | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(128); | |
public PrintWriter getPrintWriter() { | |
return new PrintWriter(baos); | |
} | |
public void append(CharSequence cs){ | |
PrintWriter pw = new PrintWriter(baos).append(cs); | |
pw.flush(); | |
pw.close(); | |
} | |
public void append(String str) { | |
append((CharSequence) str); | |
} | |
public String toString(){ | |
try { | |
return baos.toString("UTF-8"); | |
} catch (UnsupportedEncodingException e) { | |
return "UnsupportedEncodingException" + e.getMessage(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment