Java Code Examples for org.apache.lucene.store.Directory#copyFrom()
The following examples show how to use
org.apache.lucene.store.Directory#copyFrom() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetaDataStateFormat.java From crate with Apache License 2.0 | 6 votes |
private static void copyStateToExtraLocations(List<Tuple<Path, Directory>> stateDirs, String tmpFileName) throws WriteStateException { Directory srcStateDir = stateDirs.get(0).v2(); for (int i = 1; i < stateDirs.size(); i++) { Tuple<Path, Directory> extraStatePathAndDir = stateDirs.get(i); Path extraStateLocation = extraStatePathAndDir.v1(); Directory extraStateDir = extraStatePathAndDir.v2(); try { deleteFileIfExists(extraStateLocation, extraStateDir, tmpFileName); extraStateDir.copyFrom(srcStateDir, tmpFileName, tmpFileName, IOContext.DEFAULT); extraStateDir.sync(Collections.singleton(tmpFileName)); } catch (Exception e) { throw new WriteStateException(false, "failed to copy tmp state file to extra location " + extraStateLocation, e); } } }
Example 2
Source File: IndexReplicationHandler.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Copies the files from the source directory to the target one, if they are * not the same. */ public static void copyFiles(Directory source, Directory target, List<String> files) throws IOException { if (!source.equals(target)) { for (String file : files) { target.copyFrom(source, file, file, IOContext.READONCE); } } }
Example 3
Source File: TestUtil.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Returns a copy of the source directory, with file contents stored * in RAM. */ public static Directory ramCopyOf(Directory dir) throws IOException { Directory ram = new ByteBuffersDirectory(); for (String file : dir.listAll()) { if (file.startsWith(IndexFileNames.SEGMENTS) || IndexFileNames.CODEC_FILE_PATTERN.matcher(file).matches()) { ram.copyFrom(dir, file, file, IOContext.DEFAULT); } } return ram; }
Example 4
Source File: LuceneTestCase.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Returns a new Directory instance, using the specified random * with contents copied from the provided directory. See * {@link #newDirectory()} for more information. */ public static BaseDirectoryWrapper newDirectory(Random r, Directory d) throws IOException { Directory impl = newDirectoryImpl(r, TEST_DIRECTORY); for (String file : d.listAll()) { if (file.startsWith(IndexFileNames.SEGMENTS) || IndexFileNames.CODEC_FILE_PATTERN.matcher(file).matches()) { impl.copyFrom(d, file, file, newIOContext(r)); } } return wrapDirectory(r, impl, rarely(r), false); }
Example 5
Source File: TestBoolean2.java From lucene-solr with Apache License 2.0 | 5 votes |
private static Directory copyOf(Directory dir) throws IOException { Directory copy = newFSDirectory(createTempDir()); for(String name : dir.listAll()) { if (name.startsWith("extra")) { continue; } copy.copyFrom(dir, name, name, IOContext.DEFAULT); copy.sync(Collections.singleton(name)); } return copy; }
Example 6
Source File: HdfsBackupRepository.java From lucene-solr with Apache License 2.0 | 5 votes |
@Override public void copyFileTo(URI sourceRepo, String fileName, Directory dest) throws IOException { try (HdfsDirectory dir = new HdfsDirectory(new Path(sourceRepo), NoLockFactory.INSTANCE, hdfsConfig, copyBufferSize)) { dest.copyFrom(dir, fileName, fileName, DirectoryFactory.IOCONTEXT_NO_CACHE); } }
Example 7
Source File: LocalFileSystemRepository.java From lucene-solr with Apache License 2.0 | 4 votes |
@Override public void copyFileTo(URI sourceDir, String fileName, Directory dest) throws IOException { try (FSDirectory dir = new NIOFSDirectory(Paths.get(sourceDir), NoLockFactory.INSTANCE)) { dest.copyFrom(dir, fileName, fileName, DirectoryFactory.IOCONTEXT_NO_CACHE); } }
Example 8
Source File: DistributedDirectory.java From lumongo with Apache License 2.0 | 4 votes |
public void copyToDirectory(Directory directory) throws IOException { for (String file : this.listAll()) { directory.copyFrom(this, file, file, IOContext.DEFAULT); } }
Example 9
Source File: DirectoryFactory.java From lucene-solr with Apache License 2.0 | 2 votes |
/** * Override for more efficient moves. * * Intended for use with replication - use * carefully - some Directory wrappers will * cache files for example. * * @throws IOException If there is a low-level I/O error. */ public void move(Directory fromDir, Directory toDir, String fileName, IOContext ioContext) throws IOException { toDir.copyFrom(fromDir, fileName, fileName, ioContext); fromDir.deleteFile(fileName); }