Repository: cxf Updated Branches: refs/heads/3.0.x-fixes 2cfdd8e18 -> c26c0f711
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/1c8cbd98 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/1c8cbd98 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/1c8cbd98 Branch: refs/heads/3.0.x-fixes Commit: 1c8cbd98259ac6a6d45e2ba58945d100bffa8d83 Parents: b46d037 Author: Alessio Soldano <[email protected]> Authored: Thu Apr 9 18:23:50 2015 +0200 Committer: Alessio Soldano <[email protected]> Committed: Thu Apr 9 18:27:24 2015 +0200 ---------------------------------------------------------------------- .../cxf/attachment/AttachmentSerializer.java | 33 +++++++------------- 1 file changed, 12 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/1c8cbd98/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));
