Skip to content

Package: WritableSharedFile

WritableSharedFile

nameinstructionbranchcomplexitylinemethod
WritableSharedFile(File)
M: 15 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: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
getAppendStream()
M: 17 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getWritableFile()
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%
updateLength()
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 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.File;
20: import java.io.IOException;
21: import java.io.RandomAccessFile;
22:
23: import jakarta.mail.util.SharedFileInputStream;
24:
25:
26: /**
27: * A subclass of SharedFileInputStream that also allows writing.
28: */
29: class WritableSharedFile extends SharedFileInputStream {
30:
31: private RandomAccessFile raf;
32: private AppendStream af;
33:
34: public WritableSharedFile(File file) throws IOException {
35:         super(file);
36:         try {
37:          raf = new RandomAccessFile(file, "rw");
38:         } catch (IOException ex) {
39:          // if anything goes wrong opening the writable file,
40:          // close the readable file too
41:          super.close();
42:         }
43: }
44:
45: /**
46: * Return the writable version of this file.
47: */
48: public RandomAccessFile getWritableFile() {
49:         return raf;
50: }
51:
52: /**
53: * Close the readable and writable files.
54: */
55: @Override
56: public void close() throws IOException {
57:         try {
58:          super.close();
59:         } finally {
60:          raf.close();
61:         }
62: }
63:
64: /**
65: * Update the size of the readable file after writing to the file. Updates
66: * the length to be the current size of the file.
67: */
68: synchronized long updateLength() throws IOException {
69:         datalen = in.length();
70:         af = null;
71:         return datalen;
72: }
73:
74: /**
75: * Return a new AppendStream, but only if one isn't in active use.
76: */
77: public synchronized AppendStream getAppendStream() throws IOException {
78:•        if (af != null) {
79:          throw new IOException(
80:                  "POP3 file cache only supports single threaded access");
81:         }
82:         af = new AppendStream(this);
83:         return af;
84: }
85: }