View Javadoc
1 /* 2 * Copyright (C) The Apache Software Foundation. All rights reserved. 3 * 4 * This software is published under the terms of the Apache Software License 5 * version 1.1, a copy of which has been included with this distribution in 6 * the LICENSE file. 7 */ 8 package org.apache.james.core; 9 10 import java.io.IOException; 11 import java.io.InputStream; 12 13 /*** 14 * This defines a reusable datasource that can supply an input stream with 15 * MimeMessage data. This allows a MimeMessageWrapper or other classes to 16 * grab the underlying data. 17 * 18 * @see MimeMessageWrapper 19 */ 20 public abstract class MimeMessageSource { 21 /*** 22 * Returns a unique String ID that represents the location from where 23 * this file is loaded. This will be used to identify where the data 24 * is, primarily to avoid situations where this data would get overwritten. 25 * 26 * @return the String ID 27 */ 28 public abstract String getSourceId(); 29 30 /*** 31 * Get an input stream to retrieve the data stored in the datasource 32 * 33 * @return a <code>InputStream</code> containing the data 34 * 35 * @throws IOException if an error occurs while generating the 36 * InputStream 37 */ 38 public abstract InputStream getInputStream() throws IOException; 39 40 /*** 41 * Return the size of all the data. 42 * Default implementation... others can override to do this much faster 43 * 44 * @return the size of the data represented by this source 45 * @throws IOException if an error is encountered while computing the message size 46 */ 47 public long getMessageSize() throws IOException { 48 int size = 0; 49 InputStream in = null; 50 try { 51 in = getInputStream(); 52 int read = 0; 53 byte[] data = new byte[1024]; 54 while ((read = in.read(data)) > 0) { 55 size += read; 56 } 57 } finally { 58 try { 59 if (in != null) { 60 in.close(); 61 } 62 } catch (IOException ioe) { 63 // Exception ignored because logging is 64 // unavailable 65 } 66 } 67 return size; 68 } 69 70 }

This page was automatically generated by Maven