2012-12-03 35 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文件格式精确地压缩数据)

写入一个输出流