Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/org/adblockplus/ChunkedOutputStream.java

Issue 5697499218051072: Usage of new API, cleanups (reduced) (Closed)
Left Patch Set: Adressed first batch of review issues. Created April 16, 2014, 5:36 p.m.
Right Patch Set: Even more review issues fixed. Created April 28, 2014, 10:18 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/com/github/rjeschke/neetutils/collections/Tuple.java ('k') | src/org/adblockplus/android/ABPEngine.java » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 10 matching lines...) Expand all
21 import java.io.IOException; 21 import java.io.IOException;
22 import java.io.OutputStream; 22 import java.io.OutputStream;
23 23
24 /** 24 /**
25 * ChunkedOutputStream implements chunked HTTP transfer encoding wrapper for 25 * ChunkedOutputStream implements chunked HTTP transfer encoding wrapper for
26 * OutputStream. 26 * OutputStream.
27 */ 27 */
28 public class ChunkedOutputStream extends FilterOutputStream 28 public class ChunkedOutputStream extends FilterOutputStream
29 { 29 {
30 private static final int MAX_CHUNK_SIZE = 2048; 30 private static final int MAX_CHUNK_SIZE = 2048;
31 private static final byte[] CRLF = { '\r', '\n' };
32 private static final byte[] FINAL_CHUNK = new byte[] { '0', '\r', '\n', '\r', '\n' };
33 31
32 private static final byte[] CRLF = {'\r', '\n'};
33 private static final byte[] FINAL_CHUNK = new byte[] {'0', '\r', '\n', '\r', ' \n'};
34 private boolean wroteFinalChunk = false; 34 private boolean wroteFinalChunk = false;
35 35
36 public ChunkedOutputStream(final OutputStream out) 36 public ChunkedOutputStream(final OutputStream out)
37 { 37 {
38 super(out); 38 super(out);
39 } 39 }
40 40
41 @Override 41 @Override
42 public void close() throws IOException 42 public void close() throws IOException
43 { 43 {
(...skipping 30 matching lines...) Expand all
74 throw new UnsupportedOperationException("Not implemented"); 74 throw new UnsupportedOperationException("Not implemented");
75 } 75 }
76 76
77 public void writeFinalChunk() throws IOException 77 public void writeFinalChunk() throws IOException
78 { 78 {
79 out.write(FINAL_CHUNK); 79 out.write(FINAL_CHUNK);
80 out.flush(); 80 out.flush();
81 wroteFinalChunk = true; 81 wroteFinalChunk = true;
82 } 82 }
83 83
84 private void writeChunk(final byte buffer[], final int offset, final int lengt h) 84 private void writeChunk(final byte buffer[], final int offset, final int lengt h) throws IOException
85 throws IOException
86 { 85 {
87 // Zero sized buffers are ok on slow connections but not in our case - zero 86 // Zero sized buffers are ok on slow connections but not in our case - zero
88 // chunk is used to indicate the end of transfer. 87 // chunk is used to indicate the end of transfer.
89 if (length > 0) 88 if (length > 0)
90 { 89 {
91 // Write the chunk length as a hex number 90 // Write the chunk length as a hex number
92 writeHex(length); 91 writeHex(length);
93 // Write the data 92 // Write the data
94 out.write(buffer, offset, length); 93 out.write(buffer, offset, length);
95 // Write a CRLF 94 // Write a CRLF
96 out.write(CRLF); 95 out.write(CRLF);
97 // Flush the underlying stream 96 // Flush the underlying stream
98 out.flush(); 97 out.flush();
99 } 98 }
100 } 99 }
101 100
102 private void writeHex(final int i) throws IOException 101 private void writeHex(final int i) throws IOException
103 { 102 {
104 out.write(Integer.toHexString(i).getBytes()); 103 out.write(Integer.toHexString(i).getBytes());
105 out.write(CRLF); 104 out.write(CRLF);
106 } 105 }
107 } 106 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld