當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。