< 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,22 +26,24 @@
/*
* @(#)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 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 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;
+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,11 +67,10 @@
*
* 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 {
@@ -142,17 +143,17 @@
* 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.
+ * @param ds DataSource, can be a MultipartDataSource.
+ * @throws MessagingException in case of error.
*/
public BMMimeMultipart(DataSource ds, ContentType ct)
throws MessagingException {
- super(ds,ct);
+ super(ds, ct);
boundary = ct.getParameter("boundary");
/*
if (ds instanceof MultipartDataSource) {
// ask super to do this for us.
setMultipartDataSource((MultipartDataSource)ds);
@@ -208,11 +209,11 @@
initStream();
SharedInputStream sin = null;
if (in instanceof SharedInputStream) {
- sin = (SharedInputStream)in;
+ sin = (SharedInputStream) in;
}
String bnd = "--" + boundary;
byte[] bndbytes = ASCIIUtility.getBytes(bnd);
try {
@@ -274,11 +275,11 @@
return mbp;
} else {
InternetHeaders headers = createInternetHeaders(stream);
ByteOutputStream baos = new ByteOutputStream();
- b = readBody(stream, pattern, null,baos, null);
+ 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,11 +306,11 @@
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) {
+ 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,22 +384,22 @@
if (sin != null) {
posVector[0] = pos;
}
break;
}
- buffer[i] = (byte)temp;
+ buffer[i] = (byte) temp;
}
- bufferLength=i;
+ 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;
+ int lx = l - 1;
BitSet eof = new BitSet(1);
long[] posVector = new long[1];
while (true) {
is.mark(l);
@@ -412,11 +413,11 @@
if (bufferLength < l) {
//is.reset();
return false;
}*/
- for(i = lx; i >= 0; i--) {
+ for (i = lx; i >= 0; i--) {
if (buffer[i] != pattern[i]) {
break;
}
}
@@ -437,11 +438,11 @@
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 lx = l - 1;
int bufferLength = 0;
int s = 0;
long endPos = -1;
byte[] tmp = null;
@@ -489,11 +490,11 @@
//return false;
b = -1;
return true;
}
- for(i = lx; i >= 0; i--) {
+ for (i = lx; i >= 0; i--) {
if (buffer[i] != pattern[i]) {
break;
}
}
@@ -505,11 +506,11 @@
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);
+ out.write(prevBuffer, 0, 1);
}
if (sin != null) {
posVector[0] = endPos;
}
@@ -517,30 +518,30 @@
throw new Exception(
"Boundary characters encountered in part Body " +
"without a preceeding CRLF");
}
- } else if (s==1) {
+ } else if (s == 1) {
if (prevBuffer[0] != '\n') {
throw new Exception(
"Boundary characters encountered in part Body " +
"without a preceeding CRLF");
- }else {
+ } else {
if (sin != null) {
posVector[0] = endPos;
}
}
}
} else if (s > 2) {
- if ((prevBuffer[s-2] == '\r') && (prevBuffer[s-1] == '\n')) {
+ 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') {
+ } 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,25 +560,25 @@
}
return true;
}
if ((s > 0) && (sin == null)) {
- if (prevBuffer[s-1] == (byte)13) {
+ if (prevBuffer[s - 1] == (byte) 13) {
// if buffer[0] == (byte)10
- 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]) {
+ 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);
+ out.write(prevBuffer, 0, s - 1);
} else {
- out.write(prevBuffer,0,s);
+ out.write(prevBuffer, 0, s);
}
} else {
out.write(prevBuffer, 0, s);
}
} else {
@@ -671,11 +672,12 @@
bcs[pattern[i]] = i + 1;
}
// Initialise Good Suffix Shift table
gss = new int[l];
- NEXT: for (i = l; i > 0; i--) {
+ 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,10 +756,11 @@
this.boundary = bnd;
if (this.contentType != null) {
this.contentType.setParameter("boundary", bnd);
}
}
+
public String getBoundary() {
return this.boundary;
}
public boolean isEndOfStream() {
< prev index next >