Skip to content

Package: AppendStream

AppendStream

nameinstructionbranchcomplexitylinemethod
AppendStream(WritableSharedFile)
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
close()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getInputStream()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
write(byte[])
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
write(byte[], int, int)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
write(int)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 2010, 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 org.eclipse.angus.mail.pop3;
18:
19: import java.io.IOException;
20: import java.io.InputStream;
21: import java.io.OutputStream;
22: import java.io.RandomAccessFile;
23:
24: /**
25: * A stream for writing to the temp file, and when done can return a stream for
26: * reading the data just written. NOTE: We assume that only one thread is
27: * writing to the file at a time.
28: */
29: class AppendStream extends OutputStream {
30:
31: private final WritableSharedFile tf;
32: private RandomAccessFile raf;
33: private final long start;
34: private long end;
35:
36: public AppendStream(WritableSharedFile tf) throws IOException {
37: this.tf = tf;
38: raf = tf.getWritableFile();
39: start = raf.length();
40: raf.seek(start);
41: }
42:
43: @Override
44: public void write(int b) throws IOException {
45: raf.write(b);
46: }
47:
48: @Override
49: public void write(byte[] b) throws IOException {
50: raf.write(b);
51: }
52:
53: @Override
54: public void write(byte[] b, int off, int len) throws IOException {
55: raf.write(b, off, len);
56: }
57:
58: @Override
59: public synchronized void close() throws IOException {
60: end = tf.updateLength();
61: raf = null; // no more writing allowed
62: }
63:
64: public synchronized InputStream getInputStream() throws IOException {
65: return tf.newStream(start, end);
66: }
67: }