Example usage for org.apache.lucene.store IndexOutput copyBytes

List of usage examples for org.apache.lucene.store IndexOutput copyBytes

Introduction

In this page you can find the example usage for org.apache.lucene.store IndexOutput copyBytes.

Prototype

public void copyBytes(DataInput input, long numBytes) throws IOException 

Source Link

Document

Copy numBytes bytes from input to ourself.

Usage

From source file:org.apache.blur.command.TableCopyCommand.java

License:Apache License

private long copy(String file, Directory srcDirectory, HdfsDirectory destDirectory) throws IOException {
    long fileLength = srcDirectory.fileLength(file);
    IOContext context = IOContext.DEFAULT;
    IndexOutput os = null;
    IndexInput is = null;//  w  w w. jav  a2s  . co  m
    IOException priorException = null;
    try {
        os = destDirectory.createOutput(file, context);
        is = srcDirectory.openInput(file, context);
        os.copyBytes(is, is.length());
    } catch (IOException ioe) {
        priorException = ioe;
    } finally {
        boolean success = false;
        try {
            IOUtils.closeWhileHandlingException(priorException, os, is);
            success = true;
        } finally {
            if (!success) {
                try {
                    destDirectory.deleteFile(file);
                } catch (Throwable t) {
                }
            }
        }
    }
    return fileLength;
}

From source file:org.apache.blur.mapreduce.lib.GenericRecordReader.java

License:Apache License

private static Directory copyFilesLocally(Configuration configuration, Directory dir, String table,
        Path shardDir, Path localCachePath, Collection<String> files) throws IOException {
    LOG.info("Copying files need to local cache for faster reads [{0}].", shardDir);
    Path localShardPath = new Path(new Path(localCachePath, table), shardDir.getName());
    HdfsDirectory localDir = new HdfsDirectory(configuration, localShardPath, null, files);
    for (String name : files) {
        if (!isValidFileToCache(name)) {
            continue;
        }//w ww .j  ava 2  s  . c o m
        LOG.info("Valid file for local copy [{0}].", name);
        if (!isValid(localDir, dir, name)) {
            LastModified lastModified = (LastModified) dir;
            long fileModified = lastModified.getFileModified(name);

            IndexInput input = dir.openInput(name, IOContext.READONCE);
            IndexOutput output = localDir.createOutput(name, IOContext.READONCE);
            output.copyBytes(input, input.length());
            output.close();
            IndexOutput lastMod = localDir.createOutput(name + LASTMOD, IOContext.DEFAULT);
            lastMod.writeLong(fileModified);
            lastMod.close();
        }
    }
    return localDir;
}

From source file:org.apache.jackrabbit.oak.plugins.index.lucene.OakDirectoryTest.java

License:Apache License

private static void writeFile(Directory directory, String fileName, long size) throws Exception {
    IndexOutput o = directory.createOutput(fileName, IOContext.DEFAULT);
    o.copyBytes(new InputStreamDataInput(new NullInputStream(size)), size);
    o.close();/*from w ww.  j ava 2s .c o m*/
}