StreamUtil
public
class
StreamUtil
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.util.StreamUtil |
用于管理输入流的实用程序类。
摘要
公共方法 | |
|---|---|
static
String
|
calculateBase64Md5(InputStream inputSource)
用于计算 InputStream 的 base64 md5 的辅助方法。 |
static
long
|
calculateCrc32(InputStream inStream)
用于计算 |
static
String
|
calculateMd5(InputStream inputSource)
用于计算输入流的 MD5 的辅助方法。 |
static
void
|
cancel(InputStreamSource outputSource)
如果给定的 |
static
void
|
close(Closeable closeable)
关闭给定的 |
static
void
|
closeGZipStream(GZIPOutputStream outStream)
关闭指定的 gzip 输出流。 |
static
void
|
closeStream(InputStream in)
此方法已废弃。
请改用 |
static
void
|
closeStream(OutputStream out)
此方法已废弃。
请改用 |
static
void
|
closeZipStream(ZipOutputStream outStream)
关闭给定的 ZIP 输出流。 |
static
void
|
copyFileToStream(File file, OutputStream outStream)
将文件内容复制到 outStream。 |
static
void
|
copyStreamToWriter(InputStream inStream, Writer writer)
将 inStream 的内容复制到 writer。 |
static
void
|
copyStreams(InputStream inStream, OutputStream outStream)
将 origStream 的内容复制到 destStream。 |
static
void
|
copyStreams(InputStream inStream, OutputStream outStream, long offset, long size)
将 origStream 的内容复制到 destStream,从给定的偏移量开始,复制特定大小的内容。 |
static
void
|
copyStreams(InputStream inStream, OutputStream outStream, int offset)
将 origStream 的内容复制到 destStream。 |
static
int
|
countLinesFromSource(InputStreamSource source)
统计 |
static
void
|
flushAndCloseStream(OutputStream outStream)
尝试刷新给定的输出流,然后将其关闭。 |
static
BufferedReader
|
getBufferedReaderFromStreamSrc(InputStreamSource stream)
返回一个 BufferedReader,以从给定的 InputStreamSource 读取内容。 |
static
ByteArrayList
|
getByteArrayListFromSource(InputStreamSource source)
从 |
static
ByteArrayList
|
getByteArrayListFromStream(InputStream stream)
从字节流中检索 |
static
String
|
getStackTrace(Throwable throwable)
以 |
static
String
|
getStringFromSource(InputStreamSource source)
从 |
static
String
|
getStringFromStream(InputStream stream, long length)
从字符流中检索 |
static
String
|
getStringFromStream(InputStream stream)
从字符流中检索 |
static
OutputStream
|
nullOutputStream()
创建一个会舍弃所有写入的 |
公共方法
calculateBase64Md5
public static String calculateBase64Md5 (InputStream inputSource)
用于计算输入流的 base64 md5 的辅助方法。inputStream 将被使用并关闭。
| 参数 | |
|---|---|
inputSource |
InputStream:用于创建 inputStream |
| 返回 | |
|---|---|
String |
相应流的 base64 md5 |
| 抛出 | |
|---|---|
|
java.io.IOException |
IOException |
|
calculateCrc32
public static long calculateCrc32 (InputStream inStream)
用于计算 InputStream 的 CRC-32 的辅助方法。系统将使用并关闭该流。建议提供缓冲的流。
| 参数 | |
|---|---|
inStream |
InputStream:InputStream |
| 返回 | |
|---|---|
long |
数据流的 CRC-32 |
| 抛出 | |
|---|---|
|
java.io.IOException |
IOException |
|
calculateMd5
public static String calculateMd5 (InputStream inputSource)
用于计算 InputStream 的 MD5 的辅助方法。inputStream 将被使用并关闭。
| 参数 | |
|---|---|
inputSource |
InputStream:用于创建 inputStream |
| 返回 | |
|---|---|
String |
数据流的 MD5 |
| 抛出 | |
|---|---|
|
java.io.IOException |
IOException |
|
取消
public static void cancel (InputStreamSource outputSource)
如果给定的 InputStreamSource 不为 null,则取消该 InputStreamSource。
| 参数 | |
|---|---|
outputSource |
InputStreamSource |
关闭
public static void close (Closeable closeable)
关闭给定的 Closeable。
| 参数 | |
|---|---|
closeable |
Closeable:Closeable。如果值为 null,则不采取任何操作。 |
closeGZipStream
public static void closeGZipStream (GZIPOutputStream outStream)
关闭给定的 gzip 输出流。
| 参数 | |
|---|---|
outStream |
GZIPOutputStream:ZipOutputStream。如果 outStream 为 null,则不采取任何操作。 |
closeStream
public static void closeStream (InputStream in)
此方法已废弃。
请改用 close(Closeable)。
| 参数 | |
|---|---|
in |
InputStream |
closeStream
public static void closeStream (OutputStream out)
此方法已废弃。
请改用 close(Closeable)。
| 参数 | |
|---|---|
out |
OutputStream |
closeZipStream
public static void closeZipStream (ZipOutputStream outStream)
关闭给定的 ZIP 输出流。
| 参数 | |
|---|---|
outStream |
ZipOutputStream:ZipOutputStream。如果 outStream 为 null,则不采取任何操作。 |
copyFileToStream
public static void copyFileToStream (File file,
OutputStream outStream)将文件的内容复制到 outStream。建议提供缓冲的流。
| 参数 | |
|---|---|
file |
File:File |
outStream |
OutputStream:OutputStream |
| 抛出 | |
|---|---|
|
java.io.IOException |
IOException |
|
copyStreamToWriter
public static void copyStreamToWriter (InputStream inStream,
Writer writer)将 inStream 的内容复制到 writer。
建议为输入和输出提供缓冲流
| 参数 | |
|---|---|
inStream |
InputStream:InputStream |
writer |
Writer:Writer 目的地 |
| 抛出 | |
|---|---|
|
java.io.IOException |
IOException |
|
copyStreams
public static void copyStreams (InputStream inStream,
OutputStream outStream)将 origStream 的内容复制到 destStream。
建议为输入和输出提供缓冲流
| 参数 | |
|---|---|
inStream |
InputStream:InputStream |
outStream |
OutputStream:OutputStream |
| 抛出 | |
|---|---|
|
java.io.IOException |
IOException |
|
copyStreams
public static void copyStreams (InputStream inStream,
OutputStream outStream,
long offset,
long size)将 origStream 的内容复制到 destStream,从给定的偏移量开始,复制特定大小的内容。
建议为输入和输出提供缓冲流
| 参数 | |
|---|---|
inStream |
InputStream:InputStream |
outStream |
OutputStream:OutputStream |
offset |
long:开始复制数据的时间偏移量。 |
size |
long:要复制的字节数。负值表示复制所有内容。 |
| 抛出 | |
|---|---|
|
java.io.IOException |
IOException |
|
copyStreams
public static void copyStreams (InputStream inStream,
OutputStream outStream,
int offset)将 origStream 的内容复制到 destStream。
建议为输入和输出提供缓冲流
| 参数 | |
|---|---|
inStream |
InputStream:InputStream |
outStream |
OutputStream:OutputStream |
offset |
int:开始复制数据的时间偏移量。 |
| 抛出 | |
|---|---|
|
java.io.IOException |
IOException |
|
countLinesFromSource
public static int countLinesFromSource (InputStreamSource source)
统计 InputStreamSource 中的行数
| 参数 | |
|---|---|
source |
InputStreamSource:InputStreamSource |
| 返回 | |
|---|---|
int |
行数 |
| 抛出 | |
|---|---|
IOException |
如果读取流时发生故障 |
flushAndCloseStream
public static void flushAndCloseStream (OutputStream outStream)
尝试刷新给定的输出流,然后将其关闭。
| 参数 | |
|---|---|
outStream |
OutputStream:OutputStream。如果 outStream 为 null,则不采取任何操作。 |
getBufferedReaderFromStreamSrc
public static BufferedReader getBufferedReaderFromStreamSrc (InputStreamSource stream)
返回一个 BufferedReader,以从给定的 InputStreamSource 读取内容。
| 参数 | |
|---|---|
stream |
InputStreamSource:InputStreamSource |
| 返回 | |
|---|---|
BufferedReader |
一个 BuffferedReader |
getByteArrayListFromSource
public static ByteArrayList getByteArrayListFromSource (InputStreamSource source)
从 InputStreamSource 中检索 ByteArrayList。
| 参数 | |
|---|---|
source |
InputStreamSource:InputStreamSource |
| 返回 | |
|---|---|
ByteArrayList |
包含流内容的 ByteArrayList |
| 抛出 | |
|---|---|
IOException |
如果读取流时发生故障 |
getByteArrayListFromStream
public static ByteArrayList getByteArrayListFromStream (InputStream stream)
从字节流中检索 ByteArrayList。
| 参数 | |
|---|---|
stream |
InputStream:InputStream |
| 返回 | |
|---|---|
ByteArrayList |
包含流内容的 ByteArrayList |
| 抛出 | |
|---|---|
IOException |
如果读取流时发生故障 |
getStackTrace
public static String getStackTrace (Throwable throwable)
以 String 形式获取堆栈轨迹。
| 参数 | |
|---|---|
throwable |
Throwable:要转换的 Throwable。 |
| 返回 | |
|---|---|
String |
String 堆栈轨迹 |
getStringFromSource
public static String getStringFromSource (InputStreamSource source)
从 InputStreamSource 中检索 String。
| 参数 | |
|---|---|
source |
InputStreamSource:InputStreamSource |
| 返回 | |
|---|---|
String |
包含流内容的 String |
| 抛出 | |
|---|---|
IOException |
如果读取流时发生故障 |
getStringFromStream
public static String getStringFromStream (InputStream stream,
long length)从字符流中检索 String。
| 参数 | |
|---|---|
stream |
InputStream:InputStream |
length |
long:要读取的内容的大小,设置为 0 可读取所有内容 |
| 返回 | |
|---|---|
String |
包含流内容的 String |
| 抛出 | |
|---|---|
IOException |
如果读取流时发生故障 |
getStringFromStream
public static String getStringFromStream (InputStream stream)
从字符流中检索 String。
| 参数 | |
|---|---|
stream |
InputStream:InputStream |
| 返回 | |
|---|---|
String |
包含流内容的 String |
| 抛出 | |
|---|---|
IOException |
如果读取流时发生故障 |
nullOutputStream
public static OutputStream nullOutputStream ()
创建一个会舍弃所有写入的 OutputStream。
| 返回 | |
|---|---|
OutputStream |
|