ASF Bugzilla – Attachment 28274 Details for
Bug 52579
Tomcat5.5.35+Java1.5 cannot return proper value of a request parameter
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
patch v2
patchV2.txt (text/plain), 3.23 KB, created by
Keiichi Fujino
on 2012-02-06 08:20:18 UTC
(
hide
)
Description:
patch v2
Filename:
MIME Type:
Creator:
Keiichi Fujino
Created:
2012-02-06 08:20:18 UTC
Size:
3.23 KB
patch
obsolete
>Index: java/org/apache/tomcat/util/buf/ByteChunk.java >=================================================================== >--- java/org/apache/tomcat/util/buf/ByteChunk.java (revision 1206324) >+++ java/org/apache/tomcat/util/buf/ByteChunk.java (working copy) >@@ -22,7 +22,11 @@ > import java.io.UnsupportedEncodingException; > import java.nio.ByteBuffer; > import java.nio.CharBuffer; >+import java.nio.charset.CharacterCodingException; > import java.nio.charset.Charset; >+import java.nio.charset.CharsetDecoder; >+import java.nio.charset.CoderResult; >+import java.nio.charset.CodingErrorAction; > > /* > * In a server it is very important to be able to operate on >@@ -110,6 +114,15 @@ > DEFAULT_CHARSET = c; > } > >+ /** >+ * input data threshold. >+ * This threshold means charset.decode() is better than >+ * charset.newDecoder().decode() about memory allocates. >+ */ >+ private static final int THRESHOLD =10; >+ >+ private static ThreadLocal<CharsetDecoder> charsetDecoderCache = new ThreadLocal<CharsetDecoder>(); >+ > // byte[] > private byte[] buff; > >@@ -127,7 +140,7 @@ > private ByteOutputChannel out = null; > > private boolean optimizedWrite=true; >- >+ > /** > * Creates a new, uninitialized ByteChunk object. > */ >@@ -505,18 +518,42 @@ > } > return StringCache.toString(this); > } >- >+ > public String toStringInternal() { > if (charset == null) { > charset = DEFAULT_CHARSET; > } >- // new String(byte[], int, int, Charset) takes a defensive copy of the >- // entire byte array. This is expensive if only a small subset of the >- // bytes will be used. The code below is from Apache Harmony. >- CharBuffer cb; >- cb = charset.decode(ByteBuffer.wrap(buff, start, end-start)); >- return new String(cb.array(), cb.arrayOffset(), cb.length()); >+ if (end - start > THRESHOLD) { >+ CharBuffer cb = charset.decode(ByteBuffer.wrap(buff, start, end-start)); >+ return new String(cb.array(), cb.arrayOffset(), cb.length()); >+ } >+ CharsetDecoder dec = getCharsetDecoder(charset); >+ char[] charAry = new char[(int) ((end - start) * dec.maxCharsPerByte())]; >+ >+ CharBuffer cbuff = CharBuffer.wrap(charAry); >+ CoderResult result; >+ result = dec.decode(ByteBuffer.wrap(buff, start, end - start), cbuff, true); >+ try { >+ if (!result.isUnderflow()) result.throwException(); >+ result = dec.flush(cbuff); >+ if (!result.isUnderflow()) result.throwException(); >+ } catch (CharacterCodingException e) { >+ throw new RuntimeException(e); >+ } >+ return new String(charAry, 0, cbuff.position()); > } >+ >+ private CharsetDecoder getCharsetDecoder(Charset charset) { >+ CharsetDecoder decoder = charsetDecoderCache.get(); >+ if (decoder == null || !decoder.charset().equals(charset)) { >+ decoder = charset.newDecoder().onMalformedInput( >+ CodingErrorAction.REPLACE).onUnmappableCharacter( >+ CodingErrorAction.REPLACE); >+ charsetDecoderCache.set(decoder); >+ } >+ decoder.reset(); >+ return decoder; >+ } > > public int getInt() > {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 52579
:
28251
|
28252
|
28257
| 28274