Return the size of the content of this message in bytes. Returns -1 if the size cannot be determined. Note that this number may not be an exact measure of the content size and may or may not account for any transfer encoding of the content. @return size of content in bytes @except
()
| 86 | * @exception MessagingException for failures |
| 87 | */ |
| 88 | @Override |
| 89 | public int getSize() throws MessagingException { |
| 90 | try { |
| 91 | synchronized (this) { |
| 92 | // if we already have the size, return it |
| 93 | if (msgSize > 0) |
| 94 | return msgSize; |
| 95 | } |
| 96 | |
| 97 | /* |
| 98 | * Use LIST to determine the entire message |
| 99 | * size and subtract out the header size |
| 100 | * (which may involve loading the headers, |
| 101 | * which may load the content as a side effect). |
| 102 | * If the content is loaded as a side effect of |
| 103 | * loading the headers, it will set the size. |
| 104 | * |
| 105 | * Make sure to call loadHeaders() outside of the |
| 106 | * synchronization block. There's a potential race |
| 107 | * condition here but synchronization will occur in |
| 108 | * loadHeaders() to make sure the headers are only |
| 109 | * loaded once, and again in the following block to |
| 110 | * only compute msgSize once. |
| 111 | */ |
| 112 | if (headers == null) |
| 113 | loadHeaders(); |
| 114 | |
| 115 | synchronized (this) { |
| 116 | if (msgSize < 0) |
| 117 | msgSize = folder.getProtocol().list(msgnum) - hdrSize; |
| 118 | return msgSize; |
| 119 | } |
| 120 | } catch (EOFException eex) { |
| 121 | folder.close(false); |
| 122 | throw new FolderClosedException(folder, eex.toString()); |
| 123 | } catch (IOException ex) { |
| 124 | throw new MessagingException("error getting size", ex); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Produce the raw bytes of the message. The data is fetched using |
no test coverage detected