Skip to content

Package: StreamProvider$1

StreamProvider$1

nameinstructionbranchcomplexitylinemethod
run()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
{...}
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2021, 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.util;
18:
19: import java.io.InputStream;
20: import java.io.OutputStream;
21: import java.security.AccessController;
22: import java.security.PrivilegedAction;
23: import java.util.ServiceLoader;
24:
25: /**
26: * Service lookup is used to find implementations of this interface.
27: *
28: * It contains the methods to instance different encoders/decoders and
29: * other streams required by the API.
30: *
31: * @since JavaMail 2.1
32: */
33: public interface StreamProvider {
34:
35: /**
36: * Enumeration with the different encoder types supported by the Mail API.
37: *
38: * @since JavaMail 2.1
39: */
40: enum EncoderTypes {
41:
42: BASE_64("base64"),
43: B_ENCODER("b"),
44: Q_ENCODER("q"),
45: BINARY_ENCODER("binary"),
46: BIT7_ENCODER("7bit"),
47: BIT8_ENCODER("8bit"),
48: QUOTED_PRINTABLE_ENCODER("quoted-printable"),
49: UU_ENCODER("uuencode"),
50: X_UU_ENCODER("x-uuencode"),
51: X_UUE("x-uue");
52:
53: private final String encoder;
54:
55: EncoderTypes(String encoder) {
56: this.encoder = encoder;
57: }
58:
59: public String getEncoder() {
60: return encoder;
61: }
62: }
63:
64: /**
65: * Creates a 'base64' decoder from the InputStream.
66: *
67: * @param in the InputStream
68: * @return the decoder
69: */
70: InputStream inputBase64(InputStream in);
71:
72: /**
73: * Creates a 'base64' encoder from the OutputStream.
74: *
75: * @param out the OutputStream
76: * @return the encoder
77: */
78: OutputStream outputBase64(OutputStream out);
79:
80: /**
81: * Creates a 'binary', '7bit' and '8bit' decoder from the InputStream.
82: *
83: * @param in the InputStream
84: * @return the decoder
85: */
86: InputStream inputBinary(InputStream in);
87:
88: /**
89: * Creates a 'binary', '7bit' and '8bit' encoder from the OutputStream.
90: *
91: * @param out the OutputStream
92: * @return the encoder
93: */
94: OutputStream outputBinary(OutputStream out);
95:
96: /**
97: * Creates a 'b' encoder from the OutputStream.
98: *
99: * @param out the OutputStream
100: * @return the encoder
101: */
102: OutputStream outputB(OutputStream out);
103:
104: /**
105: * Creates a 'q' decoder from the InputStream.
106: *
107: * @param in the InputStream
108: * @return the decoder
109: */
110: InputStream inputQ(InputStream in);
111:
112: /**
113: * Creates a 'q' encoder.
114: *
115: * @param out the OutputStream
116: * @param encodingWord true if we are Q-encoding a word within a phrase.
117: * @return the encoder
118: */
119: OutputStream outputQ(OutputStream out, boolean encodingWord);
120:
121: /**
122: * Creates a new LineInputStream that supports reading CRLF terminated lines
123: * containing only US-ASCII characters from an input stream
124: *
125: * @param in the InputStream
126: * @param allowutf8 allow UTF-8 characters?
127: * @return the LineInputStream
128: */
129: LineInputStream inputLineStream(InputStream in, boolean allowutf8);
130:
131: /**
132: * Creates a new LineOutputStream that supports writing out Strings as a sequence of bytes terminated
133: * by a CRLF sequence. The String must contain only US-ASCII characters.
134: *
135: * @param out the OutputStream
136: * @param allowutf8 allow UTF-8 characters?
137: * @return the LineOutputStream
138: */
139: LineOutputStream outputLineStream(OutputStream out, boolean allowutf8);
140:
141: /**
142: * Creates a 'quoted-printable' decoder from the InputStream.
143: *
144: * @param in the InputStream
145: * @return the decoder
146: */
147: InputStream inputQP(InputStream in);
148:
149: /**
150: * Creates a 'quoted-printable' encoder from the OutputStream.
151: *
152: * @param out the OutputStream
153: * @return the encoder
154: */
155: OutputStream outputQP(OutputStream out);
156:
157: /**
158: * Creates a new InputStream from the underlying byte array to be shared
159: * between multiple readers.
160: *
161: * @param buff the byte array
162: * @return the InputStream
163: */
164: InputStream inputSharedByteArray(byte[] buff);
165:
166: /**
167: * Creates a 'uuencode', 'x-uuencode' and 'x-uue' decoder from the InputStream.
168: *
169: * @param in the InputStream
170: * @return the decoder
171: */
172: InputStream inputUU(InputStream in);
173:
174: /**
175: * Creates a 'uuencode', 'x-uuencode' and 'x-uue' encoder from the OutputStream.
176: *
177: * @param out the OutputStream
178: * @param filename Specifies a name for the encoded buffer. It can be null.
179: * @return the encoder
180: */
181: OutputStream outputUU(OutputStream out, String filename);
182:
183: /**
184: * Creates a stream provider object. The provider is loaded using the
185: * {@link ServiceLoader#load(Class)} method. If there are no available
186: * service providers, this method throws an IllegalStateException.
187: * Users are recommended to cache the result of this method.
188: *
189: * @return a stream provider
190: */
191: static StreamProvider provider() {
192: if (System.getSecurityManager() != null) {
193: return AccessController.doPrivileged(new PrivilegedAction<StreamProvider>() {
194: public StreamProvider run() {
195: return FactoryFinder.find(StreamProvider.class);
196: }
197: });
198: } else {
199: return FactoryFinder.find(StreamProvider.class);
200: }
201: }
202: }