Java Code Examples for net.openhft.chronicle.bytes.Bytes#readSkip()

The following examples show how to use net.openhft.chronicle.bytes.Bytes#readSkip() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplicatedInput.java    From Chronicle-Map with Apache License 2.0 6 votes vote down vote up
public void processReplicatedEvent(byte remoteNodeIdentifier, Bytes replicatedInputBytes) {
    long timestamp = replicatedInputBytes.readStopBit();
    byte identifier = replicatedInputBytes.readByte();
    ru.initReplicationUpdate(identifier, timestamp, remoteNodeIdentifier);

    boolean isDeleted = replicatedInputBytes.readBoolean();
    long keySize = mh.m().keySizeMarshaller.readSize(replicatedInputBytes);
    long keyOffset = replicatedInputBytes.readPosition();

    q.initInputKey(q.getInputKeyBytesAsData(replicatedInputBytes, keyOffset, keySize));
    replicatedInputBytes.readSkip(keySize);
    if (isDeleted) {
        s.innerUpdateLock.lock();
        mh.m().remoteOperations.remove(this);
    } else {
        long valueSize = mh.m().valueSizeMarshaller.readSize(replicatedInputBytes);
        long valueOffset = replicatedInputBytes.readPosition();
        Data<V> value = q.wrapValueBytesAsData(replicatedInputBytes, valueOffset, valueSize);
        replicatedInputBytes.readSkip(valueSize);
        s.innerWriteLock.lock();
        mh.m().remoteOperations.put(this, value);
    }
}
 
Example 2
Source File: RollEOFTest.java    From Chronicle-Queue with Apache License 2.0 6 votes vote down vote up
private void removeEOF(Path path) throws IOException {
    long blockSize = 64 << 10;
    long chunkSize = OS.pageAlign(blockSize);
    long overlapSize = OS.pageAlign(blockSize / 4);
    final MappedBytes mappedBytes = MappedBytes.mappedBytes(path.toFile(), chunkSize, overlapSize, false);
    mappedBytes.reserve(test);
    try {
        final Wire wire = WireType.BINARY_LIGHT.apply(mappedBytes);
        final Bytes<?> bytes = wire.bytes();
        bytes.readLimitToCapacity();
        bytes.readSkip(4);
        // move past header
        try (final SingleChronicleQueueStore qs = loadStore(wire)) {
            assertNotNull(qs);
            long l = qs.writePosition();
            long len = Wires.lengthOf(bytes.readVolatileInt(l));
            long eofOffset = l + len + 4L;
            bytes.writePosition(eofOffset);
            bytes.writeInt(0);
        }
    } finally {
        mappedBytes.release(test);
    }
}
 
Example 3
Source File: EchoHandler.java    From Chronicle-Network with Apache License 2.0 5 votes vote down vote up
@Override
    public void process(@NotNull final Bytes in, @NotNull final Bytes out, T nc) {
//        System.out.println(in.readRemaining());
        if (in.readRemaining() == 0)
            return;
//        System.out.println("P start " + in.toDebugString());
        long toWrite = Math.min(in.readRemaining(), out.writeRemaining());
        out.write(in, in.readPosition(), toWrite);
        in.readSkip(toWrite);
//        System.out.println("... P End " + in.toDebugString());
    }
 
Example 4
Source File: TimedEchoHandler.java    From Chronicle-Network with Apache License 2.0 5 votes vote down vote up
@Override
public void process(@NotNull final Bytes in, @NotNull final Bytes out, T nc) {
    if (in.readRemaining() == 0)
        return;
    long toWrite = Math.min(in.readRemaining(), out.writeRemaining());
    out.write(in, in.readPosition(), toWrite);
    out.writeLong(System.nanoTime());
    in.readSkip(toWrite);
}
 
Example 5
Source File: VanillaChronicleMap.java    From Chronicle-Map with Apache License 2.0 5 votes vote down vote up
public void alignReadPosition(Bytes entry) {
       throwExceptionIfClosed();

long positionAddr = entry.addressForRead(entry.readPosition());
       long skip = alignAddr(positionAddr, alignment) - positionAddr;
       if (skip > 0)
           entry.readSkip(skip);
   }
 
Example 6
Source File: Lexer.java    From SAXophone with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void unreadChar(Bytes txt) {
    txt.readSkip(-1);
}
 
Example 7
Source File: SCQIndexing.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@NotNull
private ScanResult linearScan0(@NotNull final Wire wire,
                               final long toIndex,
                               long fromKnownIndex,
                               long knownAddress) {
    this.linearScanCount++;
    @NotNull final Bytes<?> bytes = wire.bytes();

    // optimized if the `toIndex` is the last sequence
    long lastAddress = writePosition.getVolatileValue();
    long lastIndex = this.sequence.getSequence(lastAddress);
    if (toIndex == lastIndex) {
        assert (lastAddress >= knownAddress && lastIndex >= fromKnownIndex);
        knownAddress = lastAddress;
        fromKnownIndex = lastIndex;
    }

    bytes.readPositionUnlimited(knownAddress);

    for (long i = fromKnownIndex; ; i++) {
        try {
            if (wire.readDataHeader()) {
                if (i == toIndex) {
                    return ScanResult.FOUND;
                }
                int header = bytes.readVolatileInt();
                if (Wires.isNotComplete(header)) { // or isEndOfFile
                    return ScanResult.NOT_REACHED;
                }
                bytes.readSkip(Wires.lengthOf(header));
                continue;
            }
        } catch (EOFException fallback) {
            // reached the end of the file.
            if (i == toIndex) {
                return ScanResult.END_OF_FILE;
            }
        }
        return i == toIndex ? ScanResult.NOT_FOUND : ScanResult.NOT_REACHED;
    }
}
 
Example 8
Source File: RawAccessJava.java    From Chronicle-Queue with Apache License 2.0 4 votes vote down vote up
@Test
public void Tailer() {
    if (!assert_from_cpp())
        return;

    String tmp = "/dev/shm/RawAccessCtoJ";
    System.out.println(tmp); // so C++ knows this ran rather than skipped

    try (ChronicleQueue cq = SingleChronicleQueueBuilder.binary(tmp).build()) {

        ExcerptTailer tailer = cq.createTailer();

        for (int i = 0; i < COUNT; ++i) {
            try (DocumentContext dc = tailer.readingDocument()) {

                Bytes bytes = dc.wire().bytes();

                bytes.readSkip(-QUEUE_HEADER_SIZE);
                int header = bytes.readInt();

                // document length, inc 4-byte length
                int length = Wires.lengthOf(header);

                // actual length of data
                int data_length = bytes.readInt();

                assertEquals(bytes.readByte(), (byte) 0xab);
                assertEquals(bytes.readShort(), (short) 12);
                assertEquals(bytes.readInt(), 123);
                assertEquals(bytes.readLong(), 123456789L);
                assertEquals(bytes.readFloat(), 1.234f, 1.0e-7);
                assertEquals(bytes.readDouble(), 123.456, 1.0e-7);
                assertEquals(bytes.readChar(), 'a');

                StringBuilder sb = new StringBuilder();
                bytes.read8bit(sb);
                assertEquals(sb.toString(), "Hello World");
            }
        }
    }
}