Scott,
agree, please find a patch
Pavel
> -----Original Message-----
> From: Scott Nichol [mailto:snicholnews@;scottnichol.com]
> Sent: Tuesday, November 05, 2002 10:17 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Question: MimeType usage
>
>
> From your description, I guess you have traced into
> MimeType#match(String) to see that it instantiates a MimeType
> so it can
> call MimeType#match(MimeType), right? If that is the case,
> it seems to
> me that something that will speed execution without worrying about the
> actual logic in the call is to create class variables for the types we
> always compare against:
>
> private static final MimeType MT_APPLICATION_OCTET_STREAM = new
> MimeType("application/octet-stream");
>
> if (ctype.match(MT_APPLICATION_OCTET_STREAM) ...
>
> Scott Nichol
>
> ----- Original Message -----
> From: "Pavel Ausianik" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, November 05, 2002 10:55 AM
> Subject: Question: MimeType usage
>
>
> > Hi,
> >
> >
> > Need an advice of expert on MymeTypes. We have a code in the lib,
> which
> > could save around 2% of time in class
> org.apache.soap.rpc.SOAPContext
> method
> > addBodyPart.
> >
> > MimeType ctype = new MimeType(dh.getContentType());
> > part.setHeader(Constants.HEADER_CONTENT_TYPE,
> > ctype.toString());
> > ....
> >
> > if (ctype.match("application/octet-stream") ||
> > ctype.match("image/*") ||
> > ctype.match("audio/*") ||
> > ctype.match("video/*"))
> >
> >
> > Unfortunately match method requres create additional MimeType
> instances and
> > scan over String
> >
> > Will be this code fragment safe to rewrite as follows:
> >
> > String ctype = dh.getContentType())
> > part.setHeader(Constants.HEADER_CONTENT_TYPE,
> > ctype);
> > ....
> >
> > if (ctype.equals("application/octet-stream") ||
> > ctype.equals("image/*") || // or maybe
> > ctype.startsWith("image/"
> > ctype.equals("audio/*") ||
> > ctype.equals("video/*"))
> >
> > Best regards,
> > Pavel
> >
> > --
> > To unsubscribe, e-mail:
> <mailto:soap-dev-unsubscribe@;xml.apache.org>
> > For additional commands, e-mail:
> <mailto:soap-dev-help@;xml.apache.org>
> >
> >
>
>
> --
> To unsubscribe, e-mail: <mailto:soap-dev-unsubscribe@;xml.apache.org>
> For additional commands, e-mail: <mailto:soap-dev-help@;xml.apache.org>
>
Index: SOAPContext.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/rpc/SOAPContext.java,v
retrieving revision 1.12
diff -u -r1.12 SOAPContext.java
--- SOAPContext.java 11 Oct 2002 19:21:41 -0000 1.12
+++ SOAPContext.java 6 Nov 2002 16:18:02 -0000
@@ -90,6 +90,12 @@
protected Boolean gzip = null;
protected Boolean acceptGzip = null;
+ // Constants for checking type for base64 encoding
+ private static MimeType MIME_STREAM;
+ private static MimeType MIME_IMAGE;
+ private static MimeType MIME_AUDIO;
+ private static MimeType MIME_VIDEO;
+
/**
* This flag indicates if setRootPart() was called, so we can distinguish
* default root part resolution from deliberate root part indication.
@@ -121,6 +127,20 @@
*/
public SOAPContext() {
parts = null;
+ // Initialize mime types
+ if (MIME_STREAM == null) {
+ synchronized (SOAPContext.class) {
+ if (MIME_STREAM == null) {
+ try {
+ MIME_STREAM = new MimeType("application", "octet-stream");
+ MIME_IMAGE = new MimeType("image", "*");
+ MIME_AUDIO = new MimeType("audio", "*");
+ MIME_VIDEO = new MimeType("video", "*");
+ }
+ catch (MimeTypeParseException e) {}
+ }
+ }
+ }
}
/**
@@ -361,10 +381,10 @@
* exception for text/*, which should be UTF-8 encoded.
* To do: find a way to do the latter...
*/
- if (ctype.match("application/octet-stream") ||
- ctype.match("image/*") ||
- ctype.match("audio/*") ||
- ctype.match("video/*"))
+ if (ctype.match(MIME_STREAM) ||
+ ctype.match(MIME_IMAGE) ||
+ ctype.match(MIME_AUDIO) ||
+ ctype.match(MIME_VIDEO))
part.setHeader("Content-Transfer-Encoding", "8bit");
} catch(MessagingException me) {
throw new IllegalArgumentException(
--
To unsubscribe, e-mail: <mailto:soap-dev-unsubscribe@;xml.apache.org>
For additional commands, e-mail: <mailto:soap-dev-help@;xml.apache.org>