Skip to content

Package: UNIXFile

UNIXFile

nameinstructionbranchcomplexitylinemethod
UNIXFile(String)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
lastAccessed()
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%
lastAccessed(File)
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%
lock(FileDescriptor, String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
lock(FileDescriptor, String, boolean)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 106 C: 0
0%
M: 16 C: 0
0%
M: 9 C: 0
0%
M: 40 C: 0
0%
M: 1 C: 0
0%

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 org.eclipse.angus.mail.mbox;
18:
19: import java.io.File;
20: import java.io.FileDescriptor;
21: import java.util.StringTokenizer;
22:
23: public class UNIXFile extends File {
24: protected static final boolean loaded;
25: protected static final int lockType;
26:
27: private static final long serialVersionUID = -7972156315284146651L;
28:
29: public UNIXFile(String name) {
30:         super(name);
31: }
32:
33: // lock type enum
34: protected static final int NONE = 0;
35: protected static final int NATIVE = 1;
36: protected static final int JAVA = 2;
37:
38: static {
39:         String lt = System.getProperty("mail.mbox.locktype", "native");
40:         int type = NATIVE;
41:•        if (lt.equalsIgnoreCase("none"))
42:          type = NONE;
43:•        else if (lt.equalsIgnoreCase("java"))
44:          type = JAVA;
45:         lockType = type;
46:
47:         boolean lloaded = false;
48:•        if (lockType == NATIVE) {
49:          try {
50:                 System.loadLibrary("mbox");
51:                 lloaded = true;
52:          } catch (UnsatisfiedLinkError e) {
53:                 String classpath = System.getProperty("java.class.path");
54:                 String sep = System.getProperty("path.separator");
55:                 String arch = System.getProperty("os.arch");
56:                 StringTokenizer st = new StringTokenizer(classpath, sep);
57:•                while (st.hasMoreTokens()) {
58:                  String path = st.nextToken();
59:•                 if (path.endsWith("/classes") ||
60:•                         path.endsWith("/mail.jar") ||
61:•                         path.endsWith("/jakarta.mail.jar")) {
62:                         int i = path.lastIndexOf('/');
63:                         String libdir = path.substring(0, i + 1) + "lib/";
64:                         String lib = libdir + arch + "/libmbox.so";
65:                         try {
66:                          System.load(lib);
67:                          lloaded = true;
68:                          break;
69:                         } catch (UnsatisfiedLinkError e2) {
70:                          lib = libdir + "libmbox.so";
71:                          try {
72:                                 System.load(lib);
73:                                 lloaded = true;
74:                                 break;
75:                          } catch (UnsatisfiedLinkError e3) {
76:                                 continue;
77:                          }
78:                         }
79:                  }
80:                 }
81:          }
82:         }
83:         loaded = lloaded;
84:•        if (loaded)
85:          initIDs(FileDescriptor.class, FileDescriptor.in);
86: }
87:
88: /**
89: * Return the access time of the file.
90: */
91: public static long lastAccessed(File file) {
92:         return lastAccessed0(file.getPath());
93: }
94:
95: public long lastAccessed() {
96:         return lastAccessed0(getPath());
97: }
98:
99: private static native void initIDs(Class<FileDescriptor> fdClass,
100:                                         FileDescriptor stdin);
101:
102: /**
103: * Lock the file referred to by fd. The string mode is "r"
104: * for a read lock or "rw" for a write lock. Don't block
105: * if lock can't be acquired.
106: */
107: public static boolean lock(FileDescriptor fd, String mode) {
108:         return lock(fd, mode, false);
109: }
110:
111: /**
112: * Lock the file referred to by fd. The string mode is "r"
113: * for a read lock or "rw" for a write lock. If block is set,
114: * block waiting for the lock if necessary.
115: */
116: private static boolean lock(FileDescriptor fd, String mode, boolean block) {
117:         //return loaded && lock0(fd, mode);
118:•        if (loaded) {
119:          boolean ret;
120:          //System.out.println("UNIXFile.lock(" + fd + ", " + mode + ")");
121:          ret = lock0(fd, mode, block);
122:          //System.out.println("UNIXFile.lock returns " + ret);
123:          return ret;
124:         }
125:         return false;
126: }
127:
128: private static native boolean lock0(FileDescriptor fd, String mode,
129:                                                                 boolean block);
130:
131: public static native long lastAccessed0(String name);
132: }