欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

草稿

程序员文章站 2022-06-05 16:04:57
...
private void sendAsChunked(OutputStream outputStream, PrintWriter pw) throws IOException {  
            pw.print("Transfer-Encoding: chunked\r\n");  
            pw.print("\r\n");  
            pw.flush();  
            int BUFFER_SIZE = 16 * 1024;  
            byte[] CRLF = "\r\n".getBytes();  
            byte[] buff = new byte[BUFFER_SIZE];  
            int read;  
            while ((read = data.read(buff)) > 0) {  
                outputStream.write(String.format("%x\r\n", read).getBytes());  
                outputStream.write(buff, 0, read);  
                outputStream.write(CRLF);  
            }  
            outputStream.write(String.format("0\r\n\r\n").getBytes());  
        }  

private void sendAsFixedLength(OutputStream outputStream, int pending) throws IOException {  
            if (requestMethod != Method.HEAD && data != null) {  
                int BUFFER_SIZE = 16 * 1024;  
                byte[] buff = new byte[BUFFER_SIZE];  
                while (pending > 0) {  
                    int read = data.read(buff, 0, ((pending > BUFFER_SIZE) ? BUFFER_SIZE : pending));  
                    if (read <= 0) {  
                        break;  
                    }  
                    outputStream.write(buff, 0, read);  
                    pending -= read;  
                }  
            }  
        }       


相关标签: android系统