public class CommonUtils
extends Object
| Constructor and Description |
|---|
CommonUtils() |
| Modifier and Type | Method and Description |
|---|---|
static void |
closeOrLog(Closeable c,
String message)
Closes a
Closeable, ignoring any IOExceptions raised in the process. |
static void |
closeQuietly(Closeable closeable) |
static void |
copyStream(InputStream is,
OutputStream os,
byte[] buffer)
Copies all available data from the
InputStream into the OutputStream, using the
provided buffer. |
static boolean |
getBooleanResourceValue(Context context,
String key,
boolean defaultValue)
Gets a value for a boolean resource by its name.
|
static String |
getStringResourceValue(Context context,
String key,
String defaultValue)
Gets a value for a string resource by its name.
|
static void |
logControlled(Context context,
int level,
String tag,
String msg)
Used internally to log only when the com.twitter.sdk.android.TRACE_ENABLED resource value
is set to true.
|
static void |
logControlled(Context context,
String msg)
Used internally to log only when the com.twitter.sdk.android.TRACE_ENABLED resource value
is set to true.
|
static void |
logControlledError(Context context,
String msg,
Throwable tr)
Used internally to log errors only when the com.twitter.sdk.android.TRACE_ENABLED resource
value is set to true.
|
static void |
logOrThrowIllegalStateException(String logTag,
String errorMsg)
If
Twitter.isDebug(), throws an IllegalStateException,
else logs a warning. |
static String |
streamToString(InputStream is) |
public static String streamToString(InputStream is)
throws IOException
IOExceptionpublic static void copyStream(InputStream is,
OutputStream os,
byte[] buffer)
throws IOException
InputStream into the OutputStream, using the
provided buffer. Neither stream is closed during this call.IOExceptionpublic static void closeQuietly(Closeable closeable)
public static void closeOrLog(Closeable c,
String message)
Closeable, ignoring any IOExceptions raised in the process.
Does nothing if the Closeable is null.c - Closeable to closepublic static boolean getBooleanResourceValue(Context context,
String key,
boolean defaultValue)
Gets a value for a boolean resource by its name. If a key is not present, the provided default value will be returned.
Tries to look up a boolean value two ways:
bool resource. A discovered value is returned as-is.string resource. A discovered value is turned into a boolean with
Boolean.parseBoolean(String) before being returned.context - Context to use when accessing resourceskey - String name of the boolean value to look updefaultValue - value to be returned if the specified resource could be not be found.String value of the specified property, or an empty string if it could not be found.public static String getStringResourceValue(Context context,
String key,
String defaultValue)
Gets a value for a string resource by its name. If a key is not present, the provided default value will be returned.
context - Context to use when accessing resourceskey - String name of the boolean value to look updefaultValue - value to be returned if the specified resource could be not be found.String value of the specified property, or an empty string if it could not be found.public static void logControlled(Context context,
String msg)
public static void logControlledError(Context context,
String msg,
Throwable tr)
public static void logControlled(Context context,
int level,
String tag,
String msg)
public static void logOrThrowIllegalStateException(String logTag,
String errorMsg)
Twitter.isDebug(), throws an IllegalStateException,
else logs a warning.logTag - the log tag to use for loggingerrorMsg - the error message