[jboss-remoting-commits] JBoss Remoting SVN: r5187 - remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http.
jboss-remoting-commits at lists.jboss.org
jboss-remoting-commits at lists.jboss.org
Sun May 10 02:47:12 EDT 2009
Author: ron.sigal at jboss.com
Date: 2009-05-10 02:47:12 -0400 (Sun, 10 May 2009)
New Revision: 5187
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java
Log:
JBREM-1079: Implements line preservation feature.
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java 2009-05-10 06:43:28 UTC (rev 5186)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java 2009-05-10 06:47:12 UTC (rev 5187)
@@ -46,8 +46,10 @@
static final long serialVersionUID = 1085086661310576768L;
public final static String DATATYPE = "http";
+
+ public final static String PRESERVE_LINES = "preserveLines";
- protected final Logger log = Logger.getLogger(getClass());
+ protected final static Logger log = Logger.getLogger(HTTPUnMarshaller.class);
/**
* Will try to unmarshall data from inputstream. Will try to convert to either an object
@@ -79,6 +81,7 @@
int bufferSize = 1024;
byte[] byteBuffer = new byte[bufferSize];
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
+ boolean preserveLines = false;
boolean isChunked = false;
// check the metadat to see if is entry for content length
@@ -116,6 +119,15 @@
}
}
+ value = metadata.get(PRESERVE_LINES);
+ if (value != null)
+ {
+ if (value instanceof String)
+ {
+ preserveLines = Boolean.valueOf((String) value).booleanValue();
+ }
+ }
+
value = metadata.get("transfer-encoding");
if (value instanceof String && "chunked".equalsIgnoreCase((String)value))
{
@@ -154,19 +166,34 @@
BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(totalByteArray)));
StringBuffer buffer = new StringBuffer();
- String str = null;
- while((str = reader.readLine()) != null)
+
+ if (preserveLines)
{
- buffer.append(str);
+ if (log.isTraceEnabled()) log.trace("preserving cr/lf");
+ int len = 0;
+ char[] chars = new char[bufferSize];
+ while ((len = reader.read(chars)) > -1)
+ {
+ buffer.append(chars, 0, len);
+ }
}
+ else
+ {
+ if (log.isTraceEnabled()) log.trace("deleting cr/lf");
+ String str = null;
+ while((str = reader.readLine()) != null)
+ {
+ buffer.append(str);
+ }
+ }
+
reader.close();
-
ret = buffer.toString();
}
catch(Exception e)
{
- log.error("Can not unmarshall inputstream. Tried to unmarshall as both an object and string type.", e);
+ log.debug("Can not unmarshall inputstream. Tried to unmarshall as both an object and string type.", e);
throw new IOException("Can not unmarshall inputstream.");
}
More information about the jboss-remoting-commits
mailing list