You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by "Bernhard Roider (JIRA)" <ji...@apache.org> on 2006/12/11 09:09:23 UTC

[jira] Updated: (WSCOMMONS-123) Improvements for OMTextImpl Methods getText(..) and getTextAsQName(..)

     [ http://issues.apache.org/jira/browse/WSCOMMONS-123?page=all ]

Bernhard Roider updated WSCOMMONS-123:
--------------------------------------

    Attachment: OMTextImpl.java
                Base64.java

Hi Eran,

enclosed you can find the desired patches. 

kind regards 
Bernhard



> Improvements for OMTextImpl Methods getText(..) and getTextAsQName(..)
> ----------------------------------------------------------------------
>
>                 Key: WSCOMMONS-123
>                 URL: http://issues.apache.org/jira/browse/WSCOMMONS-123
>             Project: WS-Commons
>          Issue Type: Improvement
>          Components: AXIOM
>         Environment: all
>            Reporter: Bernhard Roider
>            Priority: Minor
>         Attachments: Base64.java, OMTextImpl.java
>
>
> The following impovements should result in less memory usage and more speed.
> //File OMTextImpl
> // create a new private Methode
> private String getTextFromInputStream() throws Exception {
>       InputStream inStream = this.getInputStream();
> 	  
>       if (inStream.available() <= 0) {
>          return EMPTY_STRING;
>       }
> 	  
>       StringBuffer text = new StringBuffer();
>       byte[] data = new byte[1023];
> 	  
>       do {
>           int len;
>           while ((len = inStream.read(data)) > 0) {
>              Base64.encode(data, 0, len, text);
>           }
>       } while (inStream.available() > 0);
>       return text.toString();	
> }
> // modify methods getText(..) and getTextAsQName(..)
> // modified method
> public QName getTextAsQName() throws OMException {
>         if (textNS != null) {
>             String prefix = textNS.getPrefix();
>             String name = textNS.getNamespaceURI();
>             if (prefix == null || "".equals(prefix)) {
>                 return new QName(name, getTextFromProperPlace());
>             } else {
>                 return new QName(textNS.getNamespaceURI(), getTextFromProperPlace(), prefix);
>             }
>         } else if (this.value != null || charArray != null) {
>             return new QName(getTextFromProperPlace());
>         } else {
>             try {
>                 return new QName(getTextFromInputStream());
>             } catch (Exception e) {
>                 throw new OMException(e);
>             }
>         }
>     }
> // modified method
> public String getText() throws OMException {
>         if (textNS != null) {
>             return getTextString();
>         } else if (charArray != null || this.value != null) {
>             return getTextFromProperPlace();
>         } else {
>             try {
>               return getTextFromInputStream();
>             } catch (Exception e) {
>               throw new OMException(e);
>             }
>         }
> }
> // create new static method in org.apache.axiom.om.util.Base64
> public static void encode(byte[] data, int off, int len, StringBuffer buffer) {
>         if (len <= 0) {
>           return;
>         }
> 		
>         char[] out = new char[4];
>         int rindex = off;
>         int rest = len - off;
>         while (rest >= 3) {
>             int i = ((data[rindex] & 0xff) << 16)
>                     + ((data[rindex + 1] & 0xff) << 8)
>                     + (data[rindex + 2] & 0xff);
>             out[0] = S_BASE64CHAR[i >> 18];
>             out[1] = S_BASE64CHAR[(i >> 12) & 0x3f];
>             out[2] = S_BASE64CHAR[(i >> 6) & 0x3f];
>             out[3] = S_BASE64CHAR[i & 0x3f];
> 			buffer.append(out);
>             rindex += 3;
>             rest -= 3;
>         }
>         if (rest == 1) {
>             int i = data[rindex] & 0xff;
>             out[0] = S_BASE64CHAR[i >> 2];
>             out[1] = S_BASE64CHAR[(i << 4) & 0x3f];
>             out[2] = S_BASE64PAD;
>             out[3] = S_BASE64PAD;
>             buffer.append(out);			
>         } else if (rest == 2) {
>             int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
>             out[0] = S_BASE64CHAR[i >> 10];
>             out[1] = S_BASE64CHAR[(i >> 4) & 0x3f];
>             out[2] = S_BASE64CHAR[(i << 2) & 0x3f];
>             out[3] = S_BASE64PAD;
>             buffer.append(out);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org