You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by vi...@apache.org on 2016/09/25 14:03:14 UTC
svn commit: r1762201 - in
/tomcat/trunk/java/org/apache/coyote/http11/filters:
ChunkedOutputFilter.java GzipOutputFilter.java
Author: violetagg
Date: Sun Sep 25 14:03:14 2016
New Revision: 1762201
URL: http://svn.apache.org/viewvc?rev=1762201&view=rev
Log:
Remove usage of ByteChunk. This is in preparation to deprecate and remove doWrite(ByteChunk) method.
Modified:
tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
Modified: tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java?rev=1762201&r1=1762200&r2=1762201&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java Sun Sep 25 14:03:14 2016
@@ -35,20 +35,8 @@ public class ChunkedOutputFilter impleme
// -------------------------------------------------------------- Constants
- /**
- * End chunk.
- */
- protected static final ByteChunk END_CHUNK = new ByteChunk();
-
-
- // ----------------------------------------------------- Static Initializer
-
-
- static {
- byte[] END_CHUNK_BYTES = {(byte) '0', (byte) '\r', (byte) '\n',
- (byte) '\r', (byte) '\n'};
- END_CHUNK.setBytes(END_CHUNK_BYTES, 0, END_CHUNK_BYTES.length);
- }
+ private static final byte[] END_CHUNK_BYTES = {(byte) '0', (byte) '\r', (byte) '\n',
+ (byte) '\r', (byte) '\n'};
// ------------------------------------------------------------ Constructor
@@ -58,8 +46,8 @@ public class ChunkedOutputFilter impleme
* Default constructor.
*/
public ChunkedOutputFilter() {
- chunkLength[8] = (byte) '\r';
- chunkLength[9] = (byte) '\n';
+ chunkHeader.put(8, (byte) '\r');
+ chunkHeader.put(9, (byte) '\n');
}
@@ -73,15 +61,15 @@ public class ChunkedOutputFilter impleme
/**
- * Buffer used for chunk length conversion.
+ * Chunk header.
*/
- protected final byte[] chunkLength = new byte[10];
+ protected final ByteBuffer chunkHeader = ByteBuffer.allocate(10);
/**
- * Chunk header.
+ * End chunk.
*/
- protected final ByteChunk chunkHeader = new ByteChunk();
+ protected final ByteBuffer endChunk = ByteBuffer.wrap(END_CHUNK_BYTES);
// ------------------------------------------------------------- Properties
@@ -100,12 +88,12 @@ public class ChunkedOutputFilter impleme
int pos = calculateChunkHeader(result);
- chunkHeader.setBytes(chunkLength, pos + 1, 9 - pos);
+ chunkHeader.position(pos + 1).limit(chunkHeader.position() + 9 - pos);
buffer.doWrite(chunkHeader);
buffer.doWrite(chunk);
- chunkHeader.setBytes(chunkLength, 8, 2);
+ chunkHeader.position(8).limit(10);
buffer.doWrite(chunkHeader);
return result;
@@ -124,12 +112,12 @@ public class ChunkedOutputFilter impleme
int pos = calculateChunkHeader(result);
- chunkHeader.setBytes(chunkLength, pos + 1, 9 - pos);
+ chunkHeader.position(pos + 1).limit(chunkHeader.position() + 9 - pos);
buffer.doWrite(chunkHeader);
buffer.doWrite(chunk);
- chunkHeader.setBytes(chunkLength, 8, 2);
+ chunkHeader.position(8).limit(10);
buffer.doWrite(chunkHeader);
return result;
@@ -144,7 +132,7 @@ public class ChunkedOutputFilter impleme
while (current > 0) {
int digit = current % 16;
current = current / 16;
- chunkLength[pos--] = HexUtils.getHex(digit);
+ chunkHeader.put(pos--, HexUtils.getHex(digit));
}
return pos;
}
@@ -188,7 +176,8 @@ public class ChunkedOutputFilter impleme
throws IOException {
// Write end chunk
- buffer.doWrite(END_CHUNK);
+ buffer.doWrite(endChunk);
+ endChunk.flip();
return 0;
Modified: tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java?rev=1762201&r1=1762200&r2=1762201&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/GzipOutputFilter.java Sun Sep 25 14:03:14 2016
@@ -168,22 +168,19 @@ public class GzipOutputFilter implements
protected class FakeOutputStream
extends OutputStream {
- protected final ByteChunk outputChunk = new ByteChunk();
- protected final byte[] singleByteBuffer = new byte[1];
+ protected final ByteBuffer outputChunk = ByteBuffer.allocate(1);
@Override
public void write(int b)
throws IOException {
// Shouldn't get used for good performance, but is needed for
// compatibility with Sun JDK 1.4.0
- singleByteBuffer[0] = (byte) (b & 0xff);
- outputChunk.setBytes(singleByteBuffer, 0, 1);
+ outputChunk.put(0, (byte) (b & 0xff));
buffer.doWrite(outputChunk);
}
@Override
public void write(byte[] b, int off, int len)
throws IOException {
- outputChunk.setBytes(b, off, len);
- buffer.doWrite(outputChunk);
+ buffer.doWrite(ByteBuffer.wrap(b, off, len));
}
@Override
public void flush() throws IOException {/*NOOP*/}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org