You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@ws.apache.org by Pavel Ausianik <Pa...@epam.com> on 2002/11/05 16:55:47 UTC

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

Re: Question: MimeType usage

Posted by Scott Nichol <sn...@scottnichol.com>.
>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" <Pa...@epam.com>
To: <so...@xml.apache.org>
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:   <ma...@xml.apache.org>
> For additional commands, e-mail: <ma...@xml.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@xml.apache.org>
For additional commands, e-mail: <ma...@xml.apache.org>