cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject cxf git commit: Few minor optimizations in AttachmentSerializer
Date Thu, 09 Apr 2015 16:25:56 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 3c1a37d7a -> d9f4142e8


Few minor optimizations in AttachmentSerializer


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/d9f4142e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/d9f4142e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/d9f4142e

Branch: refs/heads/master
Commit: d9f4142e87bc8a4f31c1bd1560a01a18b5c66407
Parents: 3c1a37d
Author: Alessio Soldano <asoldano@redhat.com>
Authored: Thu Apr 9 18:23:50 2015 +0200
Committer: Alessio Soldano <asoldano@redhat.com>
Committed: Thu Apr 9 18:23:50 2015 +0200

----------------------------------------------------------------------
 .../cxf/attachment/AttachmentSerializer.java    | 33 +++++++-------------
 1 file changed, 12 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/d9f4142e/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java b/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
index 408db87..24b4766 100644
--- a/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
+++ b/core/src/main/java/org/apache/cxf/attachment/AttachmentSerializer.java
@@ -72,7 +72,6 @@ public class AttachmentSerializer {
         bodyBoundary = AttachmentUtil.getUniqueBoundaryValue();
 
         String bodyCt = (String) message.get(Message.CONTENT_TYPE);
-        bodyCt = bodyCt.replaceAll("\"", "\\\"");
         
         // The bodyCt string is used enclosed within "", so if it contains the character
", it
         // should be adjusted, like in the following case:
@@ -107,17 +106,15 @@ public class AttachmentSerializer {
         // type is a required parameter for multipart/related only
         if (xopOrMultipartRelated
             && requestMimeType.indexOf("type=") == -1) {
-            ct.append("; ");
             if (xop) {
-                ct.append("type=\"application/xop+xml\"");
+                ct.append("; type=\"application/xop+xml\"");
             } else {
-                ct.append("type=\"").append(bodyCt).append("\"");
+                ct.append("; type=\"").append(bodyCt).append("\"");
             }    
         }
         
         // boundary
-        ct.append("; ")
-            .append("boundary=\"")
+        ct.append("; boundary=\"")
             .append(bodyBoundary)
             .append("\"");
             
@@ -127,8 +124,7 @@ public class AttachmentSerializer {
         // for simpler multipart/related payloads but is not needed for
         // multipart/mixed, multipart/form-data
         if (xopOrMultipartRelated) {
-            ct.append("; ")
-                .append("start=\"<")
+            ct.append("; start=\"<")
                 .append(checkAngleBrackets(rootContentId))
                 .append(">\"");
         }
@@ -136,8 +132,7 @@ public class AttachmentSerializer {
         // start-info is a required parameter for XOP/MTOM, may be needed for
         // other WS cases but is redundant in simpler multipart/related cases
         if (writeOptionalTypeParameters || xop) {
-            ct.append("; ")
-                .append("start-info=\"")
+            ct.append("; start-info=\"")
                 .append(bodyCt)
                 .append("\"");
         }
@@ -159,7 +154,7 @@ public class AttachmentSerializer {
         StringBuilder mimeBodyCt = new StringBuilder();
         String bodyType = getHeaderValue("Content-Type", null);
         if (bodyType == null) {
-            mimeBodyCt.append((xop ? "application/xop+xml" : "text/xml") + "; charset=")
+            mimeBodyCt.append(xop ? "application/xop+xml; charset=" : "text/xml; charset=")
                 .append(encoding)
                 .append("; type=\"")
                 .append(bodyCt)
@@ -189,12 +184,9 @@ public class AttachmentSerializer {
     
     private static void writeHeaders(String contentType, String attachmentId, 
                                      Map<String, List<String>> headers, Writer
writer) throws IOException {
-        writer.write("\r\n");
-        writer.write("Content-Type: ");
+        writer.write("\r\nContent-Type: ");
         writer.write(contentType);
-        writer.write("\r\n");
-
-        writer.write("Content-Transfer-Encoding: binary\r\n");
+        writer.write("\r\nContent-Transfer-Encoding: binary\r\n");
 
         if (attachmentId != null) {
             attachmentId = checkAngleBrackets(attachmentId);
@@ -209,7 +201,8 @@ public class AttachmentSerializer {
                 || "Content-Transfer-Encoding".equalsIgnoreCase(name)) {
                 continue;
             }
-            writer.write(name + ": ");
+            writer.write(name);
+            writer.write(": ");
             List<String> values = entry.getValue();
             for (int i = 0; i < values.size(); i++) {
                 writer.write(values.get(i));
@@ -238,8 +231,7 @@ public class AttachmentSerializer {
         if (message.getAttachments() != null) {
             for (Attachment a : message.getAttachments()) {
                 StringWriter writer = new StringWriter();                
-                writer.write("\r\n");
-                writer.write("--");
+                writer.write("\r\n--");
                 writer.write(bodyBoundary);
                 
                 Map<String, List<String>> headers = null;
@@ -265,8 +257,7 @@ public class AttachmentSerializer {
             }
         }
         StringWriter writer = new StringWriter();                
-        writer.write("\r\n");
-        writer.write("--");
+        writer.write("\r\n--");
         writer.write(bodyBoundary);
         writer.write("--");
         out.write(writer.getBuffer().toString().getBytes(encoding));


Mime
View raw message