You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2011/11/10 07:13:21 UTC
svn commit: r1200175 - in
/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector: InputBuffer.java
MapperListener.java OutputBuffer.java
Author: kkolinko
Date: Thu Nov 10 06:13:21 2011
New Revision: 1200175
URL: http://svn.apache.org/viewvc?rev=1200175&view=rev
Log:
Merged revision 1187753 from tomcat/trunk:
Clean-up. No functional change.
Part 3.
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java
tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/OutputBuffer.java
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java?rev=1200175&r1=1200174&r2=1200175&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/InputBuffer.java Thu Nov 10 06:13:21 2011
@@ -5,16 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
-
+ */
package org.apache.catalina.connector;
import java.io.IOException;
@@ -35,7 +34,7 @@ import org.apache.tomcat.util.res.String
/**
* The buffer used by Tomcat request. This is a derivative of the Tomcat 3.3
- * OutputBuffer, adapted to handle input instead of output. This allows
+ * OutputBuffer, adapted to handle input instead of output. This allows
* complete recycling of the facade objects (the ServletInputStream and the
* BufferedReader).
*
@@ -55,7 +54,7 @@ public class InputBuffer extends Reader
// -------------------------------------------------------------- Constants
- public static final String DEFAULT_ENCODING =
+ public static final String DEFAULT_ENCODING =
org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING;
public static final int DEFAULT_BUFFER_SIZE = 8*1024;
@@ -71,7 +70,7 @@ public class InputBuffer extends Reader
/**
* The byte buffer.
*/
- private ByteChunk bb;
+ private final ByteChunk bb;
/**
@@ -150,7 +149,7 @@ public class InputBuffer extends Reader
/**
* Alternate constructor which allows specifying the initial buffer size.
- *
+ *
* @param size Buffer size to use
*/
public InputBuffer(int size) {
@@ -173,7 +172,7 @@ public class InputBuffer extends Reader
/**
* Associated Coyote request.
- *
+ *
* @param coyoteRequest Associated Coyote request
*/
public void setRequest(Request coyoteRequest) {
@@ -183,7 +182,7 @@ public class InputBuffer extends Reader
/**
* Get associated Coyote request.
- *
+ *
* @return the associated Coyote request
*/
@Deprecated
@@ -199,9 +198,9 @@ public class InputBuffer extends Reader
* Recycle the output buffer.
*/
public void recycle() {
-
+
state = INITIAL_STATE;
-
+
// If usage of mark made the buffer too big, reallocate it
if (cb.getChars().length > size) {
cb = new CharChunk(size);
@@ -213,16 +212,16 @@ public class InputBuffer extends Reader
cb.recycle();
}
markPos = -1;
- bb.recycle();
+ bb.recycle();
closed = false;
-
+
if (conv != null) {
conv.recycle();
}
-
+
gotEnc = false;
enc = null;
-
+
}
@@ -232,11 +231,11 @@ public class InputBuffer extends Reader
public void clearEncoders() {
encoders.clear();
}
-
-
+
+
/**
* Close the input buffer.
- *
+ *
* @throws IOException An underlying IOException occurred
*/
@Override
@@ -264,26 +263,29 @@ public class InputBuffer extends Reader
// ------------------------------------------------- Bytes Handling Methods
- /**
+ /**
* Reads new bytes in the byte chunk.
- *
+ *
* @param cbuf Byte buffer to be written to the response
* @param off Offset
* @param len Length
- *
+ *
* @throws IOException An underlying IOException occurred
*/
@Override
public int realReadBytes(byte cbuf[], int off, int len)
throws IOException {
- if (closed)
+ if (closed) {
return -1;
- if (coyoteRequest == null)
+ }
+ if (coyoteRequest == null) {
return -1;
+ }
- if(state == INITIAL_STATE)
+ if(state == INITIAL_STATE) {
state = BYTE_STATE;
+ }
int result = coyoteRequest.doRead(bb);
@@ -295,8 +297,9 @@ public class InputBuffer extends Reader
public int readByte()
throws IOException {
- if (closed)
+ if (closed) {
throw new IOException(sm.getString("inputBuffer.streamClosed"));
+ }
return bb.substract();
}
@@ -305,8 +308,9 @@ public class InputBuffer extends Reader
public int read(byte[] b, int off, int len)
throws IOException {
- if (closed)
+ if (closed) {
throw new IOException(sm.getString("inputBuffer.streamClosed"));
+ }
return bb.substract(b, off, len);
}
@@ -322,7 +326,7 @@ public class InputBuffer extends Reader
* mark is lost.
*/
@Override
- public void realWriteChars(char c[], int off, int len)
+ public void realWriteChars(char c[], int off, int len)
throws IOException {
markPos = -1;
cb.setOffset(0);
@@ -339,8 +343,9 @@ public class InputBuffer extends Reader
public int realReadChars(char cbuf[], int off, int len)
throws IOException {
- if (!gotEnc)
+ if (!gotEnc) {
setConverter();
+ }
if (bb.getLength() <= 0) {
int nRead = realReadBytes(bb.getBytes(), 0, bb.getBytes().length);
@@ -354,8 +359,9 @@ public class InputBuffer extends Reader
cb.setEnd(0);
}
int limit = bb.getLength()+cb.getStart();
- if ( cb.getLimit() < limit )
+ if ( cb.getLimit() < limit ) {
cb.setLimit(limit);
+ }
state = CHAR_STATE;
conv.convert(bb, cb, bb.getLength());
bb.setOffset(bb.getEnd());
@@ -369,8 +375,9 @@ public class InputBuffer extends Reader
public int read()
throws IOException {
- if (closed)
+ if (closed) {
throw new IOException(sm.getString("inputBuffer.streamClosed"));
+ }
return cb.substract();
}
@@ -380,8 +387,9 @@ public class InputBuffer extends Reader
public int read(char[] cbuf)
throws IOException {
- if (closed)
+ if (closed) {
throw new IOException(sm.getString("inputBuffer.streamClosed"));
+ }
return read(cbuf, 0, cbuf.length);
}
@@ -391,8 +399,9 @@ public class InputBuffer extends Reader
public int read(char[] cbuf, int off, int len)
throws IOException {
- if (closed)
+ if (closed) {
throw new IOException(sm.getString("inputBuffer.streamClosed"));
+ }
return cb.substract(cbuf, off, len);
}
@@ -403,8 +412,9 @@ public class InputBuffer extends Reader
throws IOException {
- if (closed)
+ if (closed) {
throw new IOException(sm.getString("inputBuffer.streamClosed"));
+ }
if (n < 0) {
throw new IllegalArgumentException();
@@ -425,8 +435,9 @@ public class InputBuffer extends Reader
toRead = (int) (n - nRead);
}
int nb = realReadChars(cb.getChars(), 0, toRead);
- if (nb < 0)
+ if (nb < 0) {
break;
+ }
}
}
@@ -439,8 +450,9 @@ public class InputBuffer extends Reader
public boolean ready()
throws IOException {
- if (closed)
+ if (closed) {
throw new IOException(sm.getString("inputBuffer.streamClosed"));
+ }
return (available() > 0);
}
@@ -456,16 +468,17 @@ public class InputBuffer extends Reader
public void mark(int readAheadLimit)
throws IOException {
- if (closed)
+ if (closed) {
throw new IOException(sm.getString("inputBuffer.streamClosed"));
+ }
if (cb.getLength() <= 0) {
cb.setOffset(0);
cb.setEnd(0);
} else {
- if ((cb.getBuffer().length > (2 * size))
+ if ((cb.getBuffer().length > (2 * size))
&& (cb.getLength()) < (cb.getStart())) {
- System.arraycopy(cb.getBuffer(), cb.getStart(),
+ System.arraycopy(cb.getBuffer(), cb.getStart(),
cb.getBuffer(), 0, cb.getLength());
cb.setEnd(cb.getLength());
cb.setOffset(0);
@@ -480,8 +493,9 @@ public class InputBuffer extends Reader
public void reset()
throws IOException {
- if (closed)
+ if (closed) {
throw new IOException(sm.getString("inputBuffer.streamClosed"));
+ }
if (state == CHAR_STATE) {
if (markPos < 0) {
@@ -497,11 +511,12 @@ public class InputBuffer extends Reader
}
- public void checkConverter()
+ public void checkConverter()
throws IOException {
- if (!gotEnc)
+ if (!gotEnc) {
setConverter();
+ }
}
@@ -509,12 +524,14 @@ public class InputBuffer extends Reader
protected void setConverter()
throws IOException {
- if (coyoteRequest != null)
+ if (coyoteRequest != null) {
enc = coyoteRequest.getCharacterEncoding();
+ }
gotEnc = true;
- if (enc == null)
+ if (enc == null) {
enc = DEFAULT_ENCODING;
+ }
conv = encoders.get(enc);
if (conv == null) {
if (SecurityUtil.isPackageProtectionEnabled()){
@@ -528,11 +545,12 @@ public class InputBuffer extends Reader
}
}
- );
+ );
}catch(PrivilegedActionException ex){
Exception e = ex.getException();
- if (e instanceof IOException)
- throw (IOException)e;
+ if (e instanceof IOException) {
+ throw (IOException)e;
+ }
}
} else {
conv = new B2CConverter(enc);
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java?rev=1200175&r1=1200174&r2=1200175&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/MapperListener.java Thu Nov 10 06:13:21 2011
@@ -5,15 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.apache.catalina.connector;
import org.apache.catalina.Container;
@@ -53,7 +53,7 @@ public class MapperListener extends Life
* Associated mapper.
*/
private Mapper mapper = null;
-
+
/**
* Associated connector
*/
@@ -69,7 +69,7 @@ public class MapperListener extends Life
/**
* The domain (effectively the engine) this mapper is associated with
*/
- private String domain = null;
+ private final String domain = null;
// ----------------------------------------------------------- Constructors
@@ -90,7 +90,7 @@ public class MapperListener extends Life
return this.connector.toString();
}
-
+
// ------------------------------------------------------- Lifecycle Methods
@Override
@@ -102,10 +102,10 @@ public class MapperListener extends Life
// MBean listener won't be notified as those components will have
// already registered their MBeans
findDefaultHost();
-
+
Engine engine = (Engine) connector.getService().getContainer();
addListeners(engine);
-
+
Container[] conHosts = engine.findChildren();
for (Container conHost : conHosts) {
Host host = (Host) conHost;
@@ -115,7 +115,7 @@ public class MapperListener extends Life
}
}
}
-
+
@Override
public void stopInternal() throws LifecycleException {
@@ -195,55 +195,55 @@ public class MapperListener extends Life
String hostName = wrapper.getParent().getParent().getName();
String mapping = (String) event.getData();
-
+
mapper.removeWrapper(hostName, contextPath, version, mapping);
} else if (Context.ADD_WELCOME_FILE_EVENT.equals(event.getType())) {
// Handle dynamically adding welcome files
Context context = (Context) event.getSource();
-
+
String hostName = context.getParent().getName();
String contextPath = context.getPath();
if ("/".equals(contextPath)) {
contextPath = "";
}
-
+
String welcomeFile = (String) event.getData();
-
+
mapper.addWelcomeFile(hostName, contextPath,
context.getWebappVersion(), welcomeFile);
} else if (Context.REMOVE_WELCOME_FILE_EVENT.equals(event.getType())) {
// Handle dynamically removing welcome files
Context context = (Context) event.getSource();
-
+
String hostName = context.getParent().getName();
String contextPath = context.getPath();
if ("/".equals(contextPath)) {
contextPath = "";
}
-
+
String welcomeFile = (String) event.getData();
-
+
mapper.removeWelcomeFile(hostName, contextPath,
context.getWebappVersion(), welcomeFile);
} else if (Context.CLEAR_WELCOME_FILES_EVENT.equals(event.getType())) {
// Handle dynamically clearing welcome files
Context context = (Context) event.getSource();
-
+
String hostName = context.getParent().getName();
String contextPath = context.getPath();
if ("/".equals(contextPath)) {
contextPath = "";
}
-
+
mapper.clearWelcomeFiles(hostName, contextPath,
context.getWebappVersion());
}
}
-
+
// ------------------------------------------------------ Protected Methods
private void findDefaultHost() {
@@ -255,14 +255,14 @@ public class MapperListener extends Life
if (defaultHost != null && defaultHost.length() >0) {
Container[] containers = engine.findChildren();
-
+
for (Container container : containers) {
Host host = (Host) container;
if (defaultHost.equalsIgnoreCase(host.getName())) {
found = true;
break;
}
-
+
String[] aliases = host.findAliases();
for (String alias : aliases) {
if (defaultHost.equalsIgnoreCase(alias)) {
@@ -281,15 +281,15 @@ public class MapperListener extends Life
}
}
-
+
/**
* Register host.
*/
private void registerHost(Host host) {
-
+
String[] aliases = host.findAliases();
mapper.addHost(host.getName(), aliases, host);
-
+
for (Container container : host.findChildren()) {
if (container.getState().isAvailable()) {
registerContext((Context) container);
@@ -308,15 +308,16 @@ public class MapperListener extends Life
private void unregisterHost(Host host) {
String hostname = host.getName();
-
+
mapper.removeHost(hostname);
- if(log.isDebugEnabled())
+ if(log.isDebugEnabled()) {
log.debug(sm.getString("mapperListener.unregisterHost", hostname,
domain, connector));
+ }
}
-
+
/**
* Unregister wrapper.
*/
@@ -332,18 +333,18 @@ public class MapperListener extends Life
String hostName = wrapper.getParent().getParent().getName();
String[] mappings = wrapper.findMappings();
-
+
for (String mapping : mappings) {
mapper.removeWrapper(hostName, contextPath, version, mapping);
}
-
+
if(log.isDebugEnabled()) {
log.debug(sm.getString("mapperListener.unregisterWrapper",
wrapperName, contextPath, connector));
}
}
-
+
/**
* Register context.
*/
@@ -354,7 +355,7 @@ public class MapperListener extends Life
contextPath = "";
}
Container host = context.getParent();
-
+
javax.naming.Context resources = context.getResources();
String[] welcomeFiles = context.findWelcomeFiles();
@@ -388,9 +389,10 @@ public class MapperListener extends Life
}
String hostName = context.getParent().getName();
- if(log.isDebugEnabled())
+ if(log.isDebugEnabled()) {
log.debug(sm.getString("mapperListener.unregisterContext",
contextPath, connector));
+ }
mapper.removeContextVersion(hostName, contextPath,
context.getWebappVersion());
@@ -410,7 +412,7 @@ public class MapperListener extends Life
}
String version = ((Context) wrapper.getParent()).getWebappVersion();
String hostName = context.getParent().getName();
-
+
String[] mappings = wrapper.findMappings();
for (String mapping : mappings) {
@@ -453,7 +455,7 @@ public class MapperListener extends Life
/**
* Add this mapper to the container and all child containers
- *
+ *
* @param container
*/
private void addListeners(Container container) {
@@ -467,7 +469,7 @@ public class MapperListener extends Life
/**
* Remove this mapper from the container and all child containers
- *
+ *
* @param container
*/
private void removeListeners(Container container) {
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/OutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/OutputBuffer.java?rev=1200175&r1=1200174&r2=1200175&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/OutputBuffer.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/connector/OutputBuffer.java Thu Nov 10 06:13:21 2011
@@ -5,16 +5,15 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
-
+ */
package org.apache.catalina.connector;
@@ -34,7 +33,7 @@ import org.apache.tomcat.util.buf.C2BCon
/**
* The buffer used by Tomcat response. This is a derivative of the Tomcat 3.3
- * OutputBuffer, with the removal of some of the state handling (which in
+ * OutputBuffer, with the removal of some of the state handling (which in
* Coyote is mostly the Processor's responsibility).
*
* @author Costin Manolache
@@ -47,7 +46,7 @@ public class OutputBuffer extends Writer
// -------------------------------------------------------------- Constants
- public static final String DEFAULT_ENCODING =
+ public static final String DEFAULT_ENCODING =
org.apache.coyote.Constants.DEFAULT_CHARACTER_ENCODING;
public static final int DEFAULT_BUFFER_SIZE = 8*1024;
@@ -58,7 +57,7 @@ public class OutputBuffer extends Writer
/**
* The byte buffer.
*/
- private ByteChunk bb;
+ private final ByteChunk bb;
/**
@@ -94,7 +93,7 @@ public class OutputBuffer extends Writer
/**
* Byte chunk used to output bytes.
*/
- private ByteChunk outputChunk = new ByteChunk();
+ private final ByteChunk outputChunk = new ByteChunk();
/**
@@ -149,7 +148,7 @@ public class OutputBuffer extends Writer
/**
* Alternate constructor which allows specifying the initial buffer size.
- *
+ *
* @param size Buffer size to use
*/
public OutputBuffer(int size) {
@@ -166,7 +165,7 @@ public class OutputBuffer extends Writer
/**
* Associated Coyote response.
- *
+ *
* @param coyoteResponse Associated Coyote response
*/
public void setResponse(Response coyoteResponse) {
@@ -176,7 +175,7 @@ public class OutputBuffer extends Writer
/**
* Get associated Coyote response.
- *
+ *
* @return the associated Coyote response
*/
@Deprecated
@@ -187,7 +186,7 @@ public class OutputBuffer extends Writer
/**
* Is the response output suspended ?
- *
+ *
* @return suspended flag value
*/
public boolean isSuspended() {
@@ -197,7 +196,7 @@ public class OutputBuffer extends Writer
/**
* Set the suspended flag.
- *
+ *
* @param suspended New suspended flag value
*/
public void setSuspended(boolean suspended) {
@@ -207,7 +206,7 @@ public class OutputBuffer extends Writer
/**
* Is the response output closed ?
- *
+ *
* @return closed flag value
*/
public boolean isClosed() {
@@ -222,23 +221,23 @@ public class OutputBuffer extends Writer
* Recycle the output buffer.
*/
public void recycle() {
-
+
initial = true;
bytesWritten = 0;
charsWritten = 0;
-
- bb.recycle();
+
+ bb.recycle();
closed = false;
doFlush = false;
suspended = false;
-
+
if (conv!= null) {
conv.recycle();
}
-
+
gotEnc = false;
enc = null;
-
+
}
@@ -248,24 +247,26 @@ public class OutputBuffer extends Writer
public void clearEncoders() {
encoders.clear();
}
-
-
+
+
/**
- * Close the output buffer. This tries to calculate the response size if
+ * Close the output buffer. This tries to calculate the response size if
* the response has not been committed yet.
- *
+ *
* @throws IOException An underlying IOException occurred
*/
@Override
public void close()
throws IOException {
- if (closed)
+ if (closed) {
return;
- if (suspended)
+ }
+ if (suspended) {
return;
+ }
- if ((!coyoteResponse.isCommitted())
+ if ((!coyoteResponse.isCommitted())
&& (coyoteResponse.getContentLengthLong() == -1)) {
// If this didn't cause a commit of the response, the final content
// length can be calculated
@@ -283,7 +284,7 @@ public class OutputBuffer extends Writer
Request req = (Request) coyoteResponse.getRequest().getNote(
CoyoteAdapter.ADAPTER_NOTES);
req.inputBuffer.close();
-
+
coyoteResponse.finish();
}
@@ -291,7 +292,7 @@ public class OutputBuffer extends Writer
/**
* Flush bytes or chars contained in the buffer.
- *
+ *
* @throws IOException An underlying IOException occurred
*/
@Override
@@ -303,14 +304,15 @@ public class OutputBuffer extends Writer
/**
* Flush bytes or chars contained in the buffer.
- *
+ *
* @throws IOException An underlying IOException occurred
*/
protected void doFlush(boolean realFlush)
throws IOException {
- if (suspended)
+ if (suspended) {
return;
+ }
try {
doFlush = true;
@@ -326,7 +328,7 @@ public class OutputBuffer extends Writer
}
if (realFlush) {
- coyoteResponse.action(ActionCode.CLIENT_FLUSH,
+ coyoteResponse.action(ActionCode.CLIENT_FLUSH,
coyoteResponse);
// If some exception occurred earlier, or if some IOE occurred
// here, notify the servlet with an IOE
@@ -342,24 +344,26 @@ public class OutputBuffer extends Writer
// ------------------------------------------------- Bytes Handling Methods
- /**
+ /**
* Sends the buffer data to the client output, checking the
* state of Response and calling the right interceptors.
- *
+ *
* @param buf Byte buffer to be written to the response
* @param off Offset
* @param cnt Length
- *
+ *
* @throws IOException An underlying IOException occurred
*/
@Override
public void realWriteBytes(byte buf[], int off, int cnt)
throws IOException {
- if (closed)
+ if (closed) {
return;
- if (coyoteResponse == null)
+ }
+ if (coyoteResponse == null) {
return;
+ }
// If we really have something to write
if (cnt > 0) {
@@ -380,19 +384,21 @@ public class OutputBuffer extends Writer
public void write(byte b[], int off, int len) throws IOException {
- if (suspended)
+ if (suspended) {
return;
+ }
writeBytes(b, off, len);
}
- private void writeBytes(byte b[], int off, int len)
+ private void writeBytes(byte b[], int off, int len)
throws IOException {
- if (closed)
+ if (closed) {
return;
+ }
bb.append(b, off, len);
bytesWritten += len;
@@ -409,8 +415,9 @@ public class OutputBuffer extends Writer
public void writeByte(int b)
throws IOException {
- if (suspended)
+ if (suspended) {
return;
+ }
bb.append((byte) b);
bytesWritten++;
@@ -425,13 +432,14 @@ public class OutputBuffer extends Writer
public void write(int c)
throws IOException {
- if (suspended)
+ if (suspended) {
return;
+ }
conv.convert((char) c);
conv.flushBuffer();
charsWritten++;
-
+
}
@@ -439,8 +447,9 @@ public class OutputBuffer extends Writer
public void write(char c[])
throws IOException {
- if (suspended)
+ if (suspended) {
return;
+ }
write(c, 0, c.length);
@@ -451,8 +460,9 @@ public class OutputBuffer extends Writer
public void write(char c[], int off, int len)
throws IOException {
- if (suspended)
+ if (suspended) {
return;
+ }
conv.convert(c, off, len);
conv.flushBuffer();
@@ -468,12 +478,14 @@ public class OutputBuffer extends Writer
public void write(String s, int off, int len)
throws IOException {
- if (suspended)
+ if (suspended) {
return;
+ }
charsWritten += len;
- if (s == null)
+ if (s == null) {
s = "null";
+ }
conv.convert(s, off, len);
conv.flushBuffer();
@@ -484,15 +496,17 @@ public class OutputBuffer extends Writer
public void write(String s)
throws IOException {
- if (suspended)
+ if (suspended) {
return;
+ }
- if (s == null)
+ if (s == null) {
s = "null";
+ }
conv.convert(s);
conv.flushBuffer();
- }
+ }
public void setEncoding(String s) {
@@ -500,27 +514,30 @@ public class OutputBuffer extends Writer
}
- public void checkConverter()
+ public void checkConverter()
throws IOException {
- if (!gotEnc)
+ if (!gotEnc) {
setConverter();
+ }
}
- protected void setConverter()
+ protected void setConverter()
throws IOException {
- if (coyoteResponse != null)
+ if (coyoteResponse != null) {
enc = coyoteResponse.getCharacterEncoding();
+ }
gotEnc = true;
- if (enc == null)
+ if (enc == null) {
enc = DEFAULT_ENCODING;
+ }
conv = encoders.get(enc);
if (conv == null) {
-
+
if (Globals.IS_SECURITY_ENABLED){
try{
conv = AccessController.doPrivileged(
@@ -532,32 +549,33 @@ public class OutputBuffer extends Writer
}
}
- );
+ );
}catch(PrivilegedActionException ex){
Exception e = ex.getException();
- if (e instanceof IOException)
- throw (IOException)e;
+ if (e instanceof IOException) {
+ throw (IOException)e;
+ }
}
} else {
conv = new C2BConverter(bb, enc);
}
-
+
encoders.put(enc, conv);
}
}
-
+
// -------------------- BufferedOutputStream compatibility
public long getContentWritten() {
return bytesWritten + charsWritten;
}
-
- /**
+
+ /**
* True if this buffer hasn't been used ( since recycle() ) -
- * i.e. no chars or bytes have been added to the buffer.
+ * i.e. no chars or bytes have been added to the buffer.
*/
public boolean isNew() {
return (bytesWritten == 0) && (charsWritten == 0);
@@ -579,7 +597,7 @@ public class OutputBuffer extends Writer
gotEnc = false;
enc = null;
initial = true;
-
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org