StreamUtil
public
class
StreamUtil
extends Object
| java.lang.Object | |
| ↳ | com.android.tradefed.util.StreamUtil |
用於管理輸入串流的公用程式類別。
摘要
公用方法 | |
|---|---|
static
String
|
calculateBase64Md5(InputStream inputSource)
Helper method to calculate base64 md5 for a inputStream. |
static
long
|
calculateCrc32(InputStream inStream)
Helper method to calculate CRC-32 for an |
static
String
|
calculateMd5(InputStream inputSource)
計算 inputStream 的 md5 的輔助方法。 |
static
void
|
cancel(InputStreamSource outputSource)
如果不是空值,則取消指定的 |
static
void
|
close(Closeable closeable)
關閉指定的 |
static
void
|
closeGZipStream(GZIPOutputStream outStream)
Closes given gzip output stream. |
static
void
|
closeStream(InputStream in)
這個方法已淘汰,
請改用 |
static
void
|
closeStream(OutputStream out)
這個方法已淘汰,
請改用 |
static
void
|
closeZipStream(ZipOutputStream outStream)
Closes given zip output stream. |
static
void
|
copyFileToStream(File file, OutputStream outStream)
Copies contents of file to outStream. |
static
void
|
copyStreamToWriter(InputStream inStream, Writer writer)
Copies contents of inStream to writer. |
static
void
|
copyStreams(InputStream inStream, OutputStream outStream)
Copies contents of origStream to destStream. |
static
void
|
copyStreams(InputStream inStream, OutputStream outStream, long offset, long size)
將 origStream 的內容複製到 destStream,從指定位移開始,複製特定大小的內容。 |
static
void
|
copyStreams(InputStream inStream, OutputStream outStream, int offset)
Copies contents of origStream to destStream. |
static
int
|
countLinesFromSource(InputStreamSource source)
計算 |
static
void
|
flushAndCloseStream(OutputStream outStream)
Attempts to flush the given output stream, and then closes it. |
static
BufferedReader
|
getBufferedReaderFromStreamSrc(InputStreamSource stream)
傳回 BuffferedReader,從指定的 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)
計算 inputStream 的 base64 md5 的輔助方法。inputStream 會耗用並關閉。
| 參數 | |
|---|---|
inputSource |
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:用於建立輸入串流 |
| 傳回 | |
|---|---|
String |
串流的 md5 |
| 擲回 | |
|---|---|
|
java.io.IOException |
IOException |
|
取消
public static void cancel (InputStreamSource outputSource)
如果不是空值,則取消指定的 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 為空值,則不採取任何動作。 |
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 為空值,則不採取任何動作。 |
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)Copies contents of inStream to 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 為空值,則不採取任何動作。 |
getBufferedReaderFromStreamSrc
public static BufferedReader getBufferedReaderFromStreamSrc (InputStreamSource stream)
傳回 BuffferedReader,從指定的 InputStreamSource 讀取內容。
| 參數 | |
|---|---|
stream |
InputStreamSource:InputStreamSource |
| 傳回 | |
|---|---|
BufferedReader |
BufferedReader |
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 |
|