01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.core.io;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21:
22: /**
23: * Simple interface for objects that are sources for an {@link InputStream}.
24: *
25: * <p>This is the base interface for Spring's more extensive {@link Resource} interface.
26: *
27: * <p>For single-use streams, {@link InputStreamResource} can be used for any
28: * given <code>InputStream</code>. Spring's {@link ByteArrayResource} or any
29: * file-based <code>Resource</code> implementation can be used as a concrete
30: * instance, allowing one to read the underlying content stream multiple times.
31: * This makes this interface useful as an abstract content source for mail
32: * attachments, for example.
33: *
34: * @author Juergen Hoeller
35: * @since 20.01.2004
36: * @see java.io.InputStream
37: * @see Resource
38: * @see InputStreamResource
39: * @see ByteArrayResource
40: */
41: public interface InputStreamSource {
42:
43: /**
44: * Return an {@link InputStream}.
45: * <p>It is expected that each call creates a <i>fresh</i> stream.
46: * <p>This requirement is particularly important when you consider an API such
47: * as JavaMail, which needs to be able to read the stream multiple times when
48: * creating mail attachments. For such a use case, it is <i>required</i>
49: * that each <code>getInputStream()</code> call returns a fresh stream.
50: * @throws IOException if the stream could not be opened
51: * @see org.springframework.mail.javamail.MimeMessageHelper#addAttachment(String, InputStreamSource)
52: */
53: InputStream getInputStream() throws IOException;
54:
55: }
|