]>
git.argeo.org Git - gpl/argeo-slc.git/blob - ext/javax.mail.mbox/src/com/sun/mail/mbox/UNIXFile.java
2 * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
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.
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.
14 * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
17 package com
.sun
.mail
.mbox
;
20 import java
.io
.FileDescriptor
;
21 import java
.util
.StringTokenizer
;
23 public class UNIXFile
extends File
{
24 protected static final boolean loaded
;
25 protected static final int lockType
;
27 private static final long serialVersionUID
= -7972156315284146651L;
29 public UNIXFile(String name
) {
34 protected static final int NONE
= 0;
35 protected static final int NATIVE
= 1;
36 protected static final int JAVA
= 2;
39 String lt
= System
.getProperty("mail.mbox.locktype", "native");
41 if (lt
.equalsIgnoreCase("none"))
43 else if (lt
.equalsIgnoreCase("java"))
47 boolean lloaded
= false;
48 if (lockType
== NATIVE
) {
50 System
.loadLibrary("mbox");
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("/javax.mail.jar")) {
62 int i
= path
.lastIndexOf('/');
63 String libdir
= path
.substring(0, i
+ 1) + "lib/";
64 String lib
= libdir
+ arch
+ "/libmbox.so";
69 } catch (UnsatisfiedLinkError e2
) {
70 lib
= libdir
+ "libmbox.so";
75 } catch (UnsatisfiedLinkError e3
) {
85 initIDs(FileDescriptor
.class, FileDescriptor
.in
);
89 * Return the access time of the file.
91 public static long lastAccessed(File file
) {
92 return lastAccessed0(file
.getPath());
95 public long lastAccessed() {
96 return lastAccessed0(getPath());
99 private static native void initIDs(Class
<FileDescriptor
> fdClass
,
100 FileDescriptor stdin
);
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.
107 public static boolean lock(FileDescriptor fd
, String mode
) {
108 return lock(fd
, mode
, false);
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.
116 private static boolean lock(FileDescriptor fd
, String mode
, boolean block
) {
117 //return loaded && lock0(fd, mode);
120 //System.out.println("UNIXFile.lock(" + fd + ", " + mode + ")");
121 ret
= lock0(fd
, mode
, block
);
122 //System.out.println("UNIXFile.lock returns " + ret);
128 private static native boolean lock0(FileDescriptor fd
, String mode
,
131 public static native long lastAccessed0(String name
);