< prev index next >

jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/messaging/saaj/packaging/mime/internet/BMMimeMultipart.java

Print this page

        

*** 26,47 **** /* * @(#)MimeMultipart.java 1.31 03/01/29 */ - package com.sun.xml.internal.messaging.saaj.packaging.mime.internet; ! import java.io.*; ! import java.util.BitSet; import javax.activation.DataSource; ! ! import com.sun.xml.internal.messaging.saaj.packaging.mime.*; ! import com.sun.xml.internal.messaging.saaj.packaging.mime.util.*; ! ! import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; /** * The MimeMultipart class is an implementation of the abstract Multipart * class that uses MIME conventions for the multipart data. <p> * --- 26,49 ---- /* * @(#)MimeMultipart.java 1.31 03/01/29 */ package com.sun.xml.internal.messaging.saaj.packaging.mime.internet; ! import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException; ! import com.sun.xml.internal.messaging.saaj.packaging.mime.util.ASCIIUtility; ! import com.sun.xml.internal.messaging.saaj.packaging.mime.util.OutputUtil; ! import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; import javax.activation.DataSource; ! import java.io.BufferedInputStream; ! import java.io.ByteArrayInputStream; ! import java.io.IOException; ! import java.io.InputStream; ! import java.io.OutputStream; ! import java.util.BitSet; /** * The MimeMultipart class is an implementation of the abstract Multipart * class that uses MIME conventions for the multipart data. <p> *
*** 65,75 **** * * An application can directly construct a MIME multipart object of any * subtype by using the <code>MimeMultipart(String subtype)</code> * constructor. For example, to create a "multipart/alternative" object, * use <code>new MimeMultipart("alternative")</code>. - * */ //TODO: cleanup the SharedInputStream handling public class BMMimeMultipart extends MimeMultipart { --- 67,76 ----
*** 142,158 **** * the data for the body parts are needed, the parser extracts the * "boundary" parameter from the content type of this DataSource, * skips the 'preamble' and reads bytes till the terminating * boundary and creates MimeBodyParts for each part of the stream. * - * @param ds DataSource, can be a MultipartDataSource. * @param ct content type. ! * @exception MessagingException in case of error. */ public BMMimeMultipart(DataSource ds, ContentType ct) throws MessagingException { ! super(ds,ct); boundary = ct.getParameter("boundary"); /* if (ds instanceof MultipartDataSource) { // ask super to do this for us. setMultipartDataSource((MultipartDataSource)ds); --- 143,159 ---- * the data for the body parts are needed, the parser extracts the * "boundary" parameter from the content type of this DataSource, * skips the 'preamble' and reads bytes till the terminating * boundary and creates MimeBodyParts for each part of the stream. * * @param ct content type. ! * @param ds DataSource, can be a MultipartDataSource. ! * @throws MessagingException in case of error. */ public BMMimeMultipart(DataSource ds, ContentType ct) throws MessagingException { ! super(ds, ct); boundary = ct.getParameter("boundary"); /* if (ds instanceof MultipartDataSource) { // ask super to do this for us. setMultipartDataSource((MultipartDataSource)ds);
*** 208,218 **** initStream(); SharedInputStream sin = null; if (in instanceof SharedInputStream) { ! sin = (SharedInputStream)in; } String bnd = "--" + boundary; byte[] bndbytes = ASCIIUtility.getBytes(bnd); try { --- 209,219 ---- initStream(); SharedInputStream sin = null; if (in instanceof SharedInputStream) { ! sin = (SharedInputStream) in; } String bnd = "--" + boundary; byte[] bndbytes = ASCIIUtility.getBytes(bnd); try {
*** 274,284 **** return mbp; } else { InternetHeaders headers = createInternetHeaders(stream); ByteOutputStream baos = new ByteOutputStream(); ! b = readBody(stream, pattern, null,baos, null); // looks like this check has to be disabled // in the old impl it is allowed to have Mime Package // without closing boundary if (!ignoreMissingEndBoundary) { if ((b == -1) && !lastBodyPartFound()) { --- 275,285 ---- return mbp; } else { InternetHeaders headers = createInternetHeaders(stream); ByteOutputStream baos = new ByteOutputStream(); ! b = readBody(stream, pattern, null, baos, null); // looks like this check has to be disabled // in the old impl it is allowed to have Mime Package // without closing boundary if (!ignoreMissingEndBoundary) { if ((b == -1) && !lastBodyPartFound()) {
*** 305,315 **** private int readHeaders(InputStream is) throws Exception { // if the headers are to end properly then there has to be CRLF // actually we just need to mark the start and end positions int b = is.read(); ! while(b != -1) { // when it is a shared input stream no need to copy if (b == '\r') { b = is.read(); if (b == '\n') { b = is.read(); --- 306,316 ---- private int readHeaders(InputStream is) throws Exception { // if the headers are to end properly then there has to be CRLF // actually we just need to mark the start and end positions int b = is.read(); ! while (b != -1) { // when it is a shared input stream no need to copy if (b == '\r') { b = is.read(); if (b == '\n') { b = is.read();
*** 383,404 **** if (sin != null) { posVector[0] = pos; } break; } ! buffer[i] = (byte)temp; } ! bufferLength=i; } return bufferLength; } public boolean find(InputStream is, byte[] pattern, SharedInputStream sin) throws Exception { int i; int l = pattern.length; ! int lx = l -1; BitSet eof = new BitSet(1); long[] posVector = new long[1]; while (true) { is.mark(l); --- 384,405 ---- if (sin != null) { posVector[0] = pos; } break; } ! buffer[i] = (byte) temp; } ! bufferLength = i; } return bufferLength; } public boolean find(InputStream is, byte[] pattern, SharedInputStream sin) throws Exception { int i; int l = pattern.length; ! int lx = l - 1; BitSet eof = new BitSet(1); long[] posVector = new long[1]; while (true) { is.mark(l);
*** 412,422 **** if (bufferLength < l) { //is.reset(); return false; }*/ ! for(i = lx; i >= 0; i--) { if (buffer[i] != pattern[i]) { break; } } --- 413,423 ---- if (bufferLength < l) { //is.reset(); return false; }*/ ! for (i = lx; i >= 0; i--) { if (buffer[i] != pattern[i]) { break; } }
*** 437,447 **** public boolean find( InputStream is, byte[] pattern, long[] posVector, ByteOutputStream out, SharedInputStream sin) throws Exception { int i; int l = pattern.length; ! int lx = l -1; int bufferLength = 0; int s = 0; long endPos = -1; byte[] tmp = null; --- 438,448 ---- public boolean find( InputStream is, byte[] pattern, long[] posVector, ByteOutputStream out, SharedInputStream sin) throws Exception { int i; int l = pattern.length; ! int lx = l - 1; int bufferLength = 0; int s = 0; long endPos = -1; byte[] tmp = null;
*** 489,499 **** //return false; b = -1; return true; } ! for(i = lx; i >= 0; i--) { if (buffer[i] != pattern[i]) { break; } } --- 490,500 ---- //return false; b = -1; return true; } ! for (i = lx; i >= 0; i--) { if (buffer[i] != pattern[i]) { break; } }
*** 505,515 **** if (s <= 2) { //it could be "some-char\n" so write some-char if (s == 2) { if (prevBuffer[1] == '\n') { if (prevBuffer[0] != '\r' && prevBuffer[0] != '\n') { ! out.write(prevBuffer,0,1); } if (sin != null) { posVector[0] = endPos; } --- 506,516 ---- if (s <= 2) { //it could be "some-char\n" so write some-char if (s == 2) { if (prevBuffer[1] == '\n') { if (prevBuffer[0] != '\r' && prevBuffer[0] != '\n') { ! out.write(prevBuffer, 0, 1); } if (sin != null) { posVector[0] = endPos; }
*** 517,546 **** throw new Exception( "Boundary characters encountered in part Body " + "without a preceeding CRLF"); } ! } else if (s==1) { if (prevBuffer[0] != '\n') { throw new Exception( "Boundary characters encountered in part Body " + "without a preceeding CRLF"); ! }else { if (sin != null) { posVector[0] = endPos; } } } } else if (s > 2) { ! if ((prevBuffer[s-2] == '\r') && (prevBuffer[s-1] == '\n')) { if (sin != null) { posVector[0] = endPos - 2; } else { out.write(prevBuffer, 0, s - 2); } ! } else if (prevBuffer[s-1] == '\n') { //old impl allowed just a \n if (sin != null) { posVector[0] = endPos - 1; } else { out.write(prevBuffer, 0, s - 1); --- 518,547 ---- throw new Exception( "Boundary characters encountered in part Body " + "without a preceeding CRLF"); } ! } else if (s == 1) { if (prevBuffer[0] != '\n') { throw new Exception( "Boundary characters encountered in part Body " + "without a preceeding CRLF"); ! } else { if (sin != null) { posVector[0] = endPos; } } } } else if (s > 2) { ! if ((prevBuffer[s - 2] == '\r') && (prevBuffer[s - 1] == '\n')) { if (sin != null) { posVector[0] = endPos - 2; } else { out.write(prevBuffer, 0, s - 2); } ! } else if (prevBuffer[s - 1] == '\n') { //old impl allowed just a \n if (sin != null) { posVector[0] = endPos - 1; } else { out.write(prevBuffer, 0, s - 1);
*** 559,583 **** } return true; } if ((s > 0) && (sin == null)) { ! if (prevBuffer[s-1] == (byte)13) { // if buffer[0] == (byte)10 ! if (buffer[0] == (byte)10) { int j; ! for(j = lx-1; j > 0; j--) { ! if (buffer[j+1] != pattern[j]) { break; } } if (j == 0) { // matched the pattern excluding the last char of the pattern // so dont write the CR into stream ! out.write(prevBuffer,0,s-1); } else { ! out.write(prevBuffer,0,s); } } else { out.write(prevBuffer, 0, s); } } else { --- 560,584 ---- } return true; } if ((s > 0) && (sin == null)) { ! if (prevBuffer[s - 1] == (byte) 13) { // if buffer[0] == (byte)10 ! if (buffer[0] == (byte) 10) { int j; ! for (j = lx - 1; j > 0; j--) { ! if (buffer[j + 1] != pattern[j]) { break; } } if (j == 0) { // matched the pattern excluding the last char of the pattern // so dont write the CR into stream ! out.write(prevBuffer, 0, s - 1); } else { ! out.write(prevBuffer, 0, s); } } else { out.write(prevBuffer, 0, s); } } else {
*** 671,681 **** bcs[pattern[i]] = i + 1; } // Initialise Good Suffix Shift table gss = new int[l]; ! NEXT: for (i = l; i > 0; i--) { // j is the beginning index of suffix being considered for (j = l - 1; j >= i; j--) { // Testing for good suffix if (pattern[j] == pattern[j - i]) { // pattern[j..len] is a good suffix --- 672,683 ---- bcs[pattern[i]] = i + 1; } // Initialise Good Suffix Shift table gss = new int[l]; ! NEXT: ! for (i = l; i > 0; i--) { // j is the beginning index of suffix being considered for (j = l - 1; j >= i; j--) { // Testing for good suffix if (pattern[j] == pattern[j - i]) { // pattern[j..len] is a good suffix
*** 754,763 **** --- 756,766 ---- this.boundary = bnd; if (this.contentType != null) { this.contentType.setParameter("boundary", bnd); } } + public String getBoundary() { return this.boundary; } public boolean isEndOfStream() {
< prev index next >