バイトストリームファイルには、複数のファイルを含むzipファイルを使用して生成されます

 

入力ストリーム[] inputStreamsList =新しい入力ストリーム[jsonArr.size()]。
文字列[] fileNameList =新しいString [jsonArr.size()]。

ここでは、ファイルの情報を取得するためにフロントデスクがあり、対応するファイルストリームを照会するfastdfs

以下のために(INT I = 0; I <jsonArr.size(); I ++){
JSONObject jsonObj =(JSONObject)jsonArr.get(I)。

文字列fileNameに= jsonObj.getString( "ファイル名");
文字列fastdir = jsonObj.getString( "fastdir")。
。。ストリングconf_filename = this.getClass()のgetResource( "/ db.properties")ある、getPath();
ClientGlobal.init(conf_filename)。
TrackerClientトラッカー= NULL;
トラッカーは、新しいTrackerClientを()=;
TrackerServer trackerServer = NULL;
trackerServer = tracker.getConnection()。
StorageServer storageServer = NULL;
StorageClient storageClient = NULL;
storageClient =新しいStorageClient(trackerServer、storageServer)。
バイト[] B = storageClient.download_file( "GROUP1"、fastdir)。

InputStream InputStreamは=新しいれるByteArrayInputStream(B)。
inputStreamsList [I] =のinputStream。
fileNameList [I] =ファイル名;

}

 

//调用ジップ打包方法
のpublic static無効ジップ(String []型fileNameListは、のInputStream [] InputStreamの、文字列のzipathは)例外を{スロー
(fileNameList == nullの|| fileNameList.length == 0)場合は{
fileNameListがある」(新しいIllegalArgumentExceptionをスローし空の !");
}
(!fileNameList.length = inputStream.length)場合は{
( "!fileNameList長がInputStreamの長さに等しいされていない")新たをスロー。
}
(InputStreamの== nullの|| inputStream.length == 0){場合
新しいIllegalArgumentExceptionをスローし( "InputStreamが空であります!");
}

ZipOutputStream zipOut = NULL;
{試します

//空白のZIPの作成
createNewzip(zipathを)。

ファイルDIR =新しいファイル(zipath)。
OutputStreamをアウト=新しいのFileOutputStream(DIR);
zipOut =新しいZipOutputStream(アウト)。
以下のために(; I <fileNameList.length、整数iが0 = I ++){
IF(ヌル==のinputStream [I]){
リターン。
}
試み{
zipOut.putNextEntry(新しいまたはZipEntry(fileNameList [I]))。
バイト[] B =新しいバイト[1024];
int型のlen = 0;
(!(LEN = InputStreamの[I] .read(B))= -1){一方
zipOut.write(B、0、LEN)。
}
zipOut.flush()。
}キャッチ(例外e){
e.printStackTrace();
}最後に{
IF(!のinputStream [I] = NULL){
InputStreamの[I] .close();
}
}
}
}最後に{
{みてください
zipOut.close();
}キャッチ(IOExceptionを電子){
e.printStackTrace();
}
}
}

 

 

//空白のzipの参照を作成します

https://www.cnblogs.com/nje19951205/p/11991395.html

おすすめ

転載: www.cnblogs.com/nje19951205/p/11991432.html