當前位置: 首頁>>代碼示例>>Java>>正文


Java TextWire類代碼示例

本文整理匯總了Java中net.openhft.chronicle.wire.TextWire的典型用法代碼示例。如果您正苦於以下問題:Java TextWire類的具體用法?Java TextWire怎麽用?Java TextWire使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TextWire類屬於net.openhft.chronicle.wire包,在下文中一共展示了TextWire類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeHeader

import net.openhft.chronicle.wire.TextWire; //導入依賴的package包/類
/**
 * @return ByteBuffer, with self bootstrapping header in [position, limit) range
 */
private static <K, V> ByteBuffer writeHeader(
        FileChannel fileChannel, VanillaChronicleMap<K, V, ?> map) throws IOException {
    ByteBuffer headerBuffer = ByteBuffer.allocate(
            SELF_BOOTSTRAPPING_HEADER_OFFSET + MAX_BOOTSTRAPPING_HEADER_SIZE);
    headerBuffer.order(LITTLE_ENDIAN);

    Bytes<ByteBuffer> headerBytes = Bytes.wrapForWrite(headerBuffer);
    headerBytes.writePosition(SELF_BOOTSTRAPPING_HEADER_OFFSET);
    Wire wire = new TextWire(headerBytes);
    wire.getValueOut().typedMarshallable(map);

    int headerLimit = (int) headerBytes.writePosition();
    int headerSize = headerLimit - SELF_BOOTSTRAPPING_HEADER_OFFSET;
    // First set readiness bit to READY, to compute checksum correctly
    //noinspection PointlessBitwiseExpression
    headerBuffer.putInt(SIZE_WORD_OFFSET, READY | DATA | headerSize);

    long checksum = headerChecksum(headerBuffer, headerSize);
    headerBuffer.putLong(HEADER_OFFSET, checksum);

    // Set readiness bit to NOT_COMPLETE, because the Chronicle Map instance is not actually
    // ready yet
    //noinspection PointlessBitwiseExpression
    headerBuffer.putInt(SIZE_WORD_OFFSET, NOT_COMPLETE | DATA | headerSize);

    // Write the size-prefixed blob to the file
    headerBuffer.position(0).limit(headerLimit);
    writeFully(fileChannel, 0, headerBuffer);

    headerBuffer.position(SELF_BOOTSTRAPPING_HEADER_OFFSET);
    return headerBuffer;
}
 
開發者ID:OpenHFT,項目名稱:Chronicle-Map,代碼行數:36,代碼來源:ChronicleMapBuilder.java

示例2: openWithExistingFile

import net.openhft.chronicle.wire.TextWire; //導入依賴的package包/類
private VanillaChronicleMap<K, V, ?> openWithExistingFile(
        File file, RandomAccessFile raf, ChronicleHashResources resources,
        boolean recover, boolean overrideBuilderConfig,
        ChronicleHashCorruption.Listener corruptionListener)
        throws IOException {
    ChronicleHashCorruptionImpl corruption = recover ? new ChronicleHashCorruptionImpl() : null;
    try {
        int headerSize = waitUntilReady(raf, file, recover);
        FileChannel fileChannel = raf.getChannel();
        ByteBuffer headerBuffer = readSelfBootstrappingHeader(
                file, raf, headerSize, recover, corruptionListener, corruption);
        if (headerSize != headerBuffer.remaining())
            throw new AssertionError();
        boolean headerCorrect = checkSumSelfBootstrappingHeader(headerBuffer, headerSize);
        boolean headerWritten = false;
        if (!headerCorrect) {
            if (overrideBuilderConfig) {
                VanillaChronicleMap<K, V, ?> mapObjectForHeaderOverwrite = newMap();
                headerBuffer = writeHeader(fileChannel, mapObjectForHeaderOverwrite);
                headerSize = headerBuffer.remaining();
                headerWritten = true;
            } else {
                throw throwRecoveryOrReturnIOException(file,
                        "Self Bootstrapping Header checksum doesn't match the stored checksum",
                        recover);
            }
        }
        Bytes<ByteBuffer> headerBytes = Bytes.wrapForRead(headerBuffer);
        headerBytes.readPosition(headerBuffer.position());
        headerBytes.readLimit(headerBuffer.limit());
        Wire wire = new TextWire(headerBytes);
        VanillaChronicleMap<K, V, ?> map = wire.getValueIn().typedMarshallable();
        map.initBeforeMapping(file, raf, headerBuffer.limit(), recover);
        long dataStoreSize = map.globalMutableState().getDataStoreSize();
        if (!recover && dataStoreSize > file.length()) {
            throw new IOException("The file " + file + " the map is serialized from " +
                    "has unexpected length " + file.length() + ", probably corrupted. " +
                    "Data store size is " + dataStoreSize);
        }
        map.initTransientsFromBuilder(this);
        if (!recover) {
            map.createMappedStoreAndSegments(resources);
        } else {
            if (!headerWritten)
                writeNotComplete(fileChannel, headerBuffer, headerSize);
            map.recover(resources, corruptionListener, corruption);
            commitChronicleMapReady(map, raf, headerBuffer, headerSize);
        }
        return map;
    } catch (Throwable t) {
        if (recover && !(t instanceof IOException) &&
                !(t instanceof ChronicleHashRecoveryFailedException)) {
            throw new ChronicleHashRecoveryFailedException(t);
        }
        throw Throwables.propagateNotWrapping(t, IOException.class);
    }
}
 
開發者ID:OpenHFT,項目名稱:Chronicle-Map,代碼行數:58,代碼來源:ChronicleMapBuilder.java


注:本文中的net.openhft.chronicle.wire.TextWire類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。