2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.util;
21 import java.io.FilterWriter;
22 import java.io.IOException;
23 import java.io.Writer;
26 /* ================================================================ */
27 /** Handle a multipart MIME response.
32 public class MultiPartWriter extends FilterWriter
34 /* ------------------------------------------------------------ */
35 private final static String __CRLF="\015\012";
36 private final static String __DASHDASH="--";
38 public static final String MULTIPART_MIXED=MultiPartOutputStream.MULTIPART_MIXED;
39 public static final String MULTIPART_X_MIXED_REPLACE=MultiPartOutputStream.MULTIPART_X_MIXED_REPLACE;
41 /* ------------------------------------------------------------ */
42 private String boundary;
44 /* ------------------------------------------------------------ */
45 private boolean inPart=false;
47 /* ------------------------------------------------------------ */
48 public MultiPartWriter(Writer out)
52 boundary = "jetty"+System.identityHashCode(this)+
53 Long.toString(System.currentTimeMillis(),36);
58 /* ------------------------------------------------------------ */
59 /** End the current part.
60 * @exception IOException IOException
70 out.write(__DASHDASH);
72 out.write(__DASHDASH);
82 /* ------------------------------------------------------------ */
83 public String getBoundary()
88 /* ------------------------------------------------------------ */
89 /** Start creation of the next Content.
91 public void startPart(String contentType)
96 out.write(__DASHDASH);
99 out.write("Content-Type: ");
100 out.write(contentType);
106 /* ------------------------------------------------------------ */
107 /** end creation of the next Content.
109 public void endPart()
117 /* ------------------------------------------------------------ */
118 /** Start creation of the next Content.
120 public void startPart(String contentType, String[] headers)
125 out.write(__DASHDASH);
128 out.write("Content-Type: ");
129 out.write(contentType);
131 for (int i=0;headers!=null && i<headers.length;i++)
133 out.write(headers[i]);