Skip to content

Package: SharedInputStream

SharedInputStream

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package jakarta.mail.internet;
18:
19: import java.io.InputStream;
20:
21: /**
22: * An InputStream that is backed by data that can be shared by multiple
23: * readers may implement this interface. This allows users of such an
24: * InputStream to determine the current position in the InputStream, and
25: * to create new InputStreams representing a subset of the data in the
26: * original InputStream. The new InputStream will access the same
27: * underlying data as the original, without copying the data. <p>
28: *
29: * Note that implementations of this interface must ensure that the
30: * <code>close</code> method does not close any underlying stream
31: * that might be shared by multiple instances of <code>SharedInputStream</code>
32: * until all shared instances have been closed.
33: *
34: * @author Bill Shannon
35: * @since JavaMail 1.2
36: */
37:
38: public interface SharedInputStream {
39: /**
40: * Return the current position in the InputStream, as an
41: * offset from the beginning of the InputStream.
42: *
43: * @return the current position
44: */
45: long getPosition();
46:
47: /**
48: * Return a new InputStream representing a subset of the data
49: * from this InputStream, starting at <code>start</code> (inclusive)
50: * up to <code>end</code> (exclusive). <code>start</code> must be
51: * non-negative. If <code>end</code> is -1, the new stream ends
52: * at the same place as this stream. The returned InputStream
53: * will also implement the SharedInputStream interface.
54: *
55: * @param start the starting position
56: * @param end the ending position + 1
57: * @return the new stream
58: */
59: InputStream newStream(long start, long end);
60: }