2012-12-03 33 views
-1

我正在經歷一個方法的應用程序,請指教一下它基本上做到按我的理解,它讀取XML流,並將它作爲一個字符串關於XML流

public static final int BUFFER_SIZE = 4096; 

protected Object processStream(InputStream inp) throws IOException 
    { 
    BufferedInputStream bis = new BufferedInputStream(inp); 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    GZIPOutputStream zip = new GZIPOutputStream(baos); 
    byte[] buffer = new byte[BUFFER_SIZE]; 
    int bufferLength = 0; 
    while ((bufferLength = bis.read(buffer)) != -1) 
    { 
     zip.write(buffer, 0, bufferLength); 
     zip.flush(); 
    } 
    zip.close(); 
    baos.close(); 
    return baos.toByteArray(); 

    } 
+0

該代碼與XML無關,除非'processStream()'的_caller_以XML格式發送。 'processStream()'只是將輸入流壓縮到內存中的字節數組緩衝區。 –

回答

0

它寫入輸出流iecompressed GZIP中的數據通過逐字節讀取緩衝區直到緩衝區返回空值。

但在程序緩衝器是空

0

它讀取輸入流(例如從一個文件),並以zip(壓縮)的格式(GZIP文件格式精確地壓縮數據)

寫入一個輸出流