-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.java
More file actions
83 lines (71 loc) · 1.82 KB
/
Utils.java
File metadata and controls
83 lines (71 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// $Id: Utils.java,v 1.1 2010-01-04 14:29:59 falk Exp $
/**
* This module contains basic utilities.
*/
package org.efalk.util
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Closeable;
import android.util.Log;
/**
* Various utility functions.
*/
public final class Util {
static private final String TAG = "Utils";
private Util() { }
/**
* Print the top of a stack trace
*/
public static void where(Throwable t) {
StackTraceElement[] stack = t.getStackTrace();
for( int i=0; i < stack.length; ++i)
Log.e(TAG, stack[i].toString());
}
/**
* Return a specific entry from the stack trace.
*/
public static String where(Throwable t, String method) {
StackTraceElement[] stack = t.getStackTrace();
for (StackTraceElement el : stack)
if (el.getMethodName().equals(method))
return el.toString();
return stack[0].toString();
}
/**
* Read a string from an InputStream.
*/
public static String inputStreamAsString(InputStream s) throws IOException {
BufferedReader br = new BufferedReader( new InputStreamReader(s));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line).append("\n");
}
br.close();
return sb.toString();
}
/**
* Closes 'closeable', ignoring any checked exceptions.
* Does nothing if 'closeable' is null.
*/
public static void closeQuietly(Closeable closeable) {
if (closeable == null) return;
try {
closeable.close();
} catch (Exception ignored) {
}
}
/**
* Sleep, return true if interrupted.
*/
public static boolean sleep(int ms) {
try {
Thread.sleep(ms);
} catch (InterruptedException e) {
return true;
}
return false;
}
}