当前位置: 首页>>代码示例>>Java>>正文


Java IOUtils.close方法代码示例

本文整理汇总了Java中org.apache.lucene.util.IOUtils.close方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.close方法的具体用法?Java IOUtils.close怎么用?Java IOUtils.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.lucene.util.IOUtils的用法示例。


在下文中一共展示了IOUtils.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testPendingDelete

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/**
 * Tests that closing views after the translog is fine and we can reopen the translog
 */
public void testPendingDelete() throws IOException {
    translog.add(new Translog.Index("test", "1", new byte[]{1}));
    translog.prepareCommit();
    Translog.TranslogGeneration generation = translog.getGeneration();
    TranslogConfig config = translog.getConfig();
    translog.close();
    translog = new Translog(config, generation, () -> SequenceNumbersService.UNASSIGNED_SEQ_NO);
    translog.add(new Translog.Index("test", "2", new byte[]{2}));
    translog.prepareCommit();
    Translog.View view = translog.newView();
    translog.add(new Translog.Index("test", "3", new byte[]{3}));
    translog.close();
    IOUtils.close(view);
    translog = new Translog(config, generation, () -> SequenceNumbersService.UNASSIGNED_SEQ_NO);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:TranslogTests.java

示例2: copyFileEntry

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/**
 * Copy the contents of the file with specified extension into the provided
 * output stream.
 */
private final long copyFileEntry(IndexOutput dataOut, FileEntry fileEntry)
    throws IOException {
  final IndexInput is = fileEntry.dir.openInput(fileEntry.file, IOContext.READONCE);
  boolean success = false;
  try {
    final long startPtr = dataOut.getFilePointer();
    final long length = fileEntry.length;
    dataOut.copyBytes(is, length);
    // Verify that the output length diff is equal to original file
    long endPtr = dataOut.getFilePointer();
    long diff = endPtr - startPtr;
    if (diff != length)
      throw new IOException("Difference in the output file offsets " + diff
          + " does not match the original file length " + length);
    fileEntry.offset = startPtr;
    success = true;
    return length;
  } finally {
    if (success) {
      IOUtils.close(is);
      // copy successful - delete file
      // if we can't we rely on IFD to pick up and retry
      IOUtils.deleteFilesIgnoringExceptions(fileEntry.dir, fileEntry.file);
    } else {
      IOUtils.closeWhileHandlingException(is);
    }
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:33,代码来源:CompoundFileWriter.java

示例3: testUserDataRead

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
public void testUserDataRead() throws IOException {
    final ShardId shardId = new ShardId("index", "_na_", 1);
    DirectoryService directoryService = new LuceneManagedDirectoryService(random());
    Store store = new Store(shardId, INDEX_SETTINGS, directoryService, new DummyShardLock(shardId));
    IndexWriterConfig config = newIndexWriterConfig(random(), new MockAnalyzer(random())).setCodec(TestUtil.getDefaultCodec());
    SnapshotDeletionPolicy deletionPolicy = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
    config.setIndexDeletionPolicy(deletionPolicy);
    IndexWriter writer = new IndexWriter(store.directory(), config);
    Document doc = new Document();
    doc.add(new TextField("id", "1", Field.Store.NO));
    writer.addDocument(doc);
    Map<String, String> commitData = new HashMap<>(2);
    String syncId = "a sync id";
    String translogId = "a translog id";
    commitData.put(Engine.SYNC_COMMIT_ID, syncId);
    commitData.put(Translog.TRANSLOG_GENERATION_KEY, translogId);
    writer.setCommitData(commitData);
    writer.commit();
    writer.close();
    Store.MetadataSnapshot metadata;
    metadata = store.getMetadata(randomBoolean() ? null : deletionPolicy.snapshot());
    assertFalse(metadata.asMap().isEmpty());
    // do not check for correct files, we have enough tests for that above
    assertThat(metadata.getCommitUserData().get(Engine.SYNC_COMMIT_ID), equalTo(syncId));
    assertThat(metadata.getCommitUserData().get(Translog.TRANSLOG_GENERATION_KEY), equalTo(translogId));
    TestUtil.checkIndex(store.directory());
    assertDeleteContent(store, directoryService);
    IOUtils.close(store);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:30,代码来源:StoreTests.java

示例4: clearClusters

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
private static void clearClusters() throws IOException {
    if (!clusters.isEmpty()) {
        IOUtils.close(clusters.values());
        clusters.clear();
    }
    if (restClient != null) {
        restClient.close();
        restClient = null;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:11,代码来源:ESIntegTestCase.java

示例5: close

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
    try {
        prebuiltAnalysis.close();
    } finally {
        IOUtils.close(cachedAnalyzer.values());
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:9,代码来源:AnalysisRegistry.java

示例6: closeStreams

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/**
 * Closes streams, interrupts the download, may delete the
 * output file.
 */
void closeStreams() throws IOException {
    interrupt();
    if (success) {
        IOUtils.close(is, os);
    } else {
        IOUtils.closeWhileHandlingException(is, os);
        if (dest != null && Files.exists(dest)) {
            IOUtils.deleteFilesIgnoringExceptions(dest);
        }
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:16,代码来源:HttpDownloadHelper.java

示例7: loadStopwordSet

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
/**
 * @deprecated Use {@link #loadStopwordSet(File)}
 */
@Deprecated
protected static CharArraySet loadStopwordSet(File stopwords,
    Version matchVersion) throws IOException {
  Reader reader = null;
  try {
    reader = IOUtils.getDecodingReader(stopwords, StandardCharsets.UTF_8);
    return WordlistLoader.getWordSet(reader, matchVersion);
  } finally {
    IOUtils.close(reader);
  }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:StopwordAnalyzerBase.java

示例8: closeNoLock

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
protected void closeNoLock(String reason) {
    if (isClosed.compareAndSet(false, true)) {
        try {
            logger.debug("shadow replica close searcher manager refCount: {}", store.refCount());
            IOUtils.close(searcherManager);
        } catch (Exception e) {
            logger.warn("shadow replica failed to close searcher manager", e);
        } finally {
            store.decRef();
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:14,代码来源:ShadowEngine.java

示例9: closeTribes

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@AfterClass
public static void closeTribes() throws IOException {
    IOUtils.close(tribe1, tribe2);
    tribe1 = null;
    tribe2 = null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:TribeUnitTests.java

示例10: close

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
    IOUtils.close(commands);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:PluginCli.java

示例11: close

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
    IOUtils.close(remoteClusters.values());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:5,代码来源:RemoteClusterService.java

示例12: testTimeoutPerConnection

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
public void testTimeoutPerConnection() throws IOException {
    assumeTrue("Works only on BSD network stacks and apparently windows",
        Constants.MAC_OS_X || Constants.FREE_BSD || Constants.WINDOWS);
    try (ServerSocket socket = new MockServerSocket()) {
        // note - this test uses backlog=1 which is implementation specific ie. it might not work on some TCP/IP stacks
        // on linux (at least newer ones) the listen(addr, backlog=1) should just ignore new connections if the queue is full which
        // means that once we received an ACK from the client we just drop the packet on the floor (which is what we want) and we run
        // into a connection timeout quickly. Yet other implementations can for instance can terminate the connection within the 3 way
        // handshake which I haven't tested yet.
        socket.bind(new InetSocketAddress(InetAddress.getLocalHost(), 0), 1);
        socket.setReuseAddress(true);
        DiscoveryNode first = new DiscoveryNode("TEST", new TransportAddress(socket.getInetAddress(),
            socket.getLocalPort()), emptyMap(),
            emptySet(), version0);
        DiscoveryNode second = new DiscoveryNode("TEST", new TransportAddress(socket.getInetAddress(),
            socket.getLocalPort()), emptyMap(),
            emptySet(), version0);
        ConnectionProfile.Builder builder = new ConnectionProfile.Builder();
        builder.addConnections(1,
            TransportRequestOptions.Type.BULK,
            TransportRequestOptions.Type.PING,
            TransportRequestOptions.Type.RECOVERY,
            TransportRequestOptions.Type.REG,
            TransportRequestOptions.Type.STATE);
        // connection with one connection and a large timeout -- should consume the one spot in the backlog queue
        try (TransportService service = buildService("TS_TPC", Version.CURRENT, null,
            Settings.EMPTY, true, false)) {
            IOUtils.close(service.openConnection(first, builder.build()));
            builder.setConnectTimeout(TimeValue.timeValueMillis(1));
            final ConnectionProfile profile = builder.build();
            // now with the 1ms timeout we got and test that is it's applied
            long startTime = System.nanoTime();
            ConnectTransportException ex = expectThrows(ConnectTransportException.class, () -> service.openConnection(second, profile));
            final long now = System.nanoTime();
            final long timeTaken = TimeValue.nsecToMSec(now - startTime);
            assertTrue("test didn't timeout quick enough, time taken: [" + timeTaken + "]",
                timeTaken < TimeValue.timeValueSeconds(5).millis());
            assertEquals(ex.getMessage(), "[][" + second.getAddress() + "] connect_timeout[1ms]");
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:42,代码来源:AbstractSimpleTransportTestCase.java

示例13: close

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
public final void close() throws IOException {
    IOUtils.close(currentStream);
    initialized = true;
    currentStream = null;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:SlicedInputStream.java

示例14: close

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
    IOUtils.close(scriptEngines);
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:5,代码来源:ScriptService.java

示例15: close

import org.apache.lucene.util.IOUtils; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
   IOUtils.close(() -> Stream.concat(analyzers.values().stream(), normalizers.values().stream())
       .filter(a -> a.scope() == AnalyzerScope.INDEX)
       .iterator());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:7,代码来源:IndexAnalyzers.java


注:本文中的org.apache.lucene.util.IOUtils.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。