本文整理汇总了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;
}
示例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);
}
}