pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / misc / src / java / org / apache / lucene / store / NativePosixUtil.java
1 package org.apache.lucene.store;
2
3 /**
4  * Licensed to the Apache Software Foundation (ASF) under one or more
5  * contributor license agreements.  See the NOTICE file distributed with
6  * this work for additional information regarding copyright ownership.
7  * The ASF licenses this file to You under the Apache License, Version 2.0
8  * (the "License"); you may not use this file except in compliance with
9  * the License.  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 import java.io.IOException;
21 import java.io.FileDescriptor;
22 import java.nio.ByteBuffer;
23
24 public final class NativePosixUtil {
25   public final static int NORMAL = 0;
26   public final static int SEQUENTIAL = 1;
27   public final static int RANDOM = 2;
28   public final static int WILLNEED = 3;
29   public final static int DONTNEED = 4;
30   public final static int NOREUSE = 5;
31
32   static {
33     System.loadLibrary("NativePosixUtil");
34   }
35
36   private static native int posix_fadvise(FileDescriptor fd, long offset, long len, int advise) throws IOException;
37   public static native int posix_madvise(ByteBuffer buf, int advise) throws IOException;
38   public static native int madvise(ByteBuffer buf, int advise) throws IOException;
39   public static native FileDescriptor open_direct(String filename, boolean read) throws IOException;
40   public static native long pread(FileDescriptor fd, long pos, ByteBuffer byteBuf) throws IOException;
41
42   public static void advise(FileDescriptor fd, long offset, long len, int advise) throws IOException {
43     final int code = posix_fadvise(fd, offset, len, advise);
44     if (code != 0) {
45       throw new RuntimeException("posix_fadvise failed code=" + code);
46     }
47   }
48 }
49