X-Git-Url: https://git.mdrn.pl/pylucene.git/blobdiff_plain/a2e61f0c04805cfcb8706176758d1283c7e3a55c..aaeed5504b982cf3545252ab528713250aa33eed:/lucene-java-3.4.0/lucene/src/java/org/apache/lucene/store/FSDirectory.java diff --git a/lucene-java-3.4.0/lucene/src/java/org/apache/lucene/store/FSDirectory.java b/lucene-java-3.4.0/lucene/src/java/org/apache/lucene/store/FSDirectory.java deleted file mode 100644 index 7d247ba..0000000 --- a/lucene-java-3.4.0/lucene/src/java/org/apache/lucene/store/FSDirectory.java +++ /dev/null @@ -1,525 +0,0 @@ -package org.apache.lucene.store; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FilenameFilter; -import java.io.IOException; -import java.io.RandomAccessFile; - -import java.util.Collection; -import static java.util.Collections.synchronizedSet; - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.Future; - -import org.apache.lucene.util.ThreadInterruptedException; -import org.apache.lucene.util.Constants; - -/** - * - * Base class for Directory implementations that store index - * files in the file system. There are currently three core - * subclasses: - * - *
The locking implementation is by default {@link
- * NativeFSLockFactory}, but can be changed by
- * passing in a custom {@link LockFactory} instance.
- *
- * @see Directory
- */
-public abstract class FSDirectory extends Directory {
-
- /**
- * Default read chunk size. This is a conditional default: on 32bit JVMs, it defaults to 100 MB. On 64bit JVMs, it's
- * Currently this returns {@link MMapDirectory} for most Solaris
- * and Windows 64-bit JREs, {@link NIOFSDirectory} for other
- * non-Windows JREs, and {@link SimpleFSDirectory} for other
- * JREs on Windows. It is highly recommended that you consult the
- * implementation's documentation for your platform before
- * using this method.
- *
- * NOTE: this method may suddenly change which
- * implementation is returned from release to release, in
- * the event that higher performance defaults become
- * possible; if the precise implementation is important to
- * your application, please instantiate it directly,
- * instead. For optimal performance you should consider using
- * {@link MMapDirectory} on 64 bit JVMs.
- *
- * See above */
- public static FSDirectory open(File path) throws IOException {
- return open(path, null);
- }
-
- /** Just like {@link #open(File)}, but allows you to
- * also specify a custom {@link LockFactory}. */
- public static FSDirectory open(File path, LockFactory lockFactory) throws IOException {
- if ((Constants.WINDOWS || Constants.SUN_OS || Constants.LINUX)
- && Constants.JRE_IS_64BIT && MMapDirectory.UNMAP_SUPPORTED) {
- return new MMapDirectory(path, lockFactory);
- } else if (Constants.WINDOWS) {
- return new SimpleFSDirectory(path, lockFactory);
- } else {
- return new NIOFSDirectory(path, lockFactory);
- }
- }
-
- @Override
- public void setLockFactory(LockFactory lockFactory) throws IOException {
- super.setLockFactory(lockFactory);
-
- // for filesystem based LockFactory, delete the lockPrefix, if the locks are placed
- // in index dir. If no index dir is given, set ourselves
- if (lockFactory instanceof FSLockFactory) {
- final FSLockFactory lf = (FSLockFactory) lockFactory;
- final File dir = lf.getLockDir();
- // if the lock factory has no lockDir set, use the this directory as lockDir
- if (dir == null) {
- lf.setLockDir(directory);
- lf.setLockPrefix(null);
- } else if (dir.getCanonicalPath().equals(directory.getCanonicalPath())) {
- lf.setLockPrefix(null);
- }
- }
-
- }
-
- /** Lists all files (not subdirectories) in the
- * directory. This method never returns null (throws
- * {@link IOException} instead).
- *
- * @throws NoSuchDirectoryException if the directory
- * does not exist, or does exist but is not a
- * directory.
- * @throws IOException if list() returns null */
- public static String[] listAll(File dir) throws IOException {
- if (!dir.exists())
- throw new NoSuchDirectoryException("directory '" + dir + "' does not exist");
- else if (!dir.isDirectory())
- throw new NoSuchDirectoryException("file '" + dir + "' exists but is not a directory");
-
- // Exclude subdirs
- String[] result = dir.list(new FilenameFilter() {
- public boolean accept(File dir, String file) {
- return !new File(dir, file).isDirectory();
- }
- });
-
- if (result == null)
- throw new IOException("directory '" + dir + "' exists and is a directory, but cannot be listed: list() returned null");
-
- return result;
- }
-
- /** Lists all files (not subdirectories) in the
- * directory.
- * @see #listAll(File) */
- @Override
- public String[] listAll() throws IOException {
- ensureOpen();
- return listAll(directory);
- }
-
- /** Returns true iff a file with the given name exists. */
- @Override
- public boolean fileExists(String name) {
- ensureOpen();
- File file = new File(directory, name);
- return file.exists();
- }
-
- /** Returns the time the named file was last modified. */
- @Override
- public long fileModified(String name) {
- ensureOpen();
- File file = new File(directory, name);
- return file.lastModified();
- }
-
- /** Returns the time the named file was last modified. */
- public static long fileModified(File directory, String name) {
- File file = new File(directory, name);
- return file.lastModified();
- }
-
- /** Set the modified time of an existing file to now.
- * @deprecated Lucene never uses this API; it will be
- * removed in 4.0. */
- @Override
- @Deprecated
- public void touchFile(String name) {
- ensureOpen();
- File file = new File(directory, name);
- file.setLastModified(System.currentTimeMillis());
- }
-
- /** Returns the length in bytes of a file in the directory. */
- @Override
- public long fileLength(String name) throws IOException {
- ensureOpen();
- File file = new File(directory, name);
- final long len = file.length();
- if (len == 0 && !file.exists()) {
- throw new FileNotFoundException(name);
- } else {
- return len;
- }
- }
-
- /** Removes an existing file in the directory. */
- @Override
- public void deleteFile(String name) throws IOException {
- ensureOpen();
- File file = new File(directory, name);
- if (!file.delete())
- throw new IOException("Cannot delete " + file);
- staleFiles.remove(name);
- }
-
- /** Creates an IndexOutput for the file with the given name. */
- @Override
- public IndexOutput createOutput(String name) throws IOException {
- ensureOpen();
-
- ensureCanWrite(name);
- return new FSIndexOutput(this, name);
- }
-
- protected void ensureCanWrite(String name) throws IOException {
- if (!directory.exists())
- if (!directory.mkdirs())
- throw new IOException("Cannot create directory: " + directory);
-
- File file = new File(directory, name);
- if (file.exists() && !file.delete()) // delete existing, if any
- throw new IOException("Cannot overwrite: " + file);
- }
-
- protected void onIndexOutputClosed(FSIndexOutput io) {
- staleFiles.add(io.name);
- }
-
- @Deprecated
- @Override
- public void sync(String name) throws IOException {
- sync(Collections.singleton(name));
- }
-
- @Override
- public void sync(Collection Changes to this value will not impact any
- * already-opened {@link IndexInput}s. You should call
- * this before attempting to open an index on the
- * directory. NOTE: This value should be as large as
- * possible to reduce any possible performance impact. If
- * you still encounter an incorrect OutOfMemoryError,
- * trying lowering the chunk size.Integer.MAX_VALUE
.
- *
- * @see #setReadChunkSize
- */
- public static final int DEFAULT_READ_CHUNK_SIZE = Constants.JRE_IS_64BIT ? Integer.MAX_VALUE : 100 * 1024 * 1024;
-
- protected final File directory; // The underlying filesystem directory
- protected final Set