Search in sources :

Example 26 with StreamCorruptedException

use of java.io.StreamCorruptedException in project Chronicle-Queue by OpenHFT.

the class SingleTableStore method acquireValueFor.

/**
 * {@inheritDoc}
 */
@Override
public synchronized LongValue acquireValueFor(CharSequence key) {
    // TODO Change to ThreadLocal values if performance is a problem.
    StringBuilder sb = Wires.acquireStringBuilder();
    mappedBytes.reserve();
    try {
        mappedBytes.readPosition(0);
        mappedBytes.readLimit(mappedBytes.realCapacity());
        while (mappedWire.readDataHeader()) {
            int header = mappedBytes.readInt();
            if (Wires.isNotComplete(header))
                break;
            long readPosition = mappedBytes.readPosition();
            int length = Wires.lengthOf(header);
            ValueIn valueIn = mappedWire.readEventName(sb);
            if (StringUtils.equalsCaseIgnore(key, sb)) {
                return valueIn.int64ForBinding(null);
            }
            mappedBytes.readPosition(readPosition + length);
        }
        // not found
        int safeLength = Maths.toUInt31(mappedBytes.realCapacity() - mappedBytes.readPosition());
        mappedBytes.writeLimit(mappedBytes.realCapacity());
        mappedBytes.writePosition(mappedBytes.readPosition());
        long pos = recovery.writeHeader(mappedWire, safeLength, timeoutMS, null, null);
        LongValue longValue = wireType.newLongReference().get();
        mappedWire.writeEventName(key).int64forBinding(Long.MIN_VALUE, longValue);
        mappedWire.updateHeader(pos, false);
        return longValue;
    } catch (StreamCorruptedException | EOFException e) {
        throw new IORuntimeException(e);
    } finally {
        mappedBytes.release();
    }
}
Also used : IORuntimeException(net.openhft.chronicle.core.io.IORuntimeException) LongValue(net.openhft.chronicle.core.values.LongValue) EOFException(java.io.EOFException) StreamCorruptedException(java.io.StreamCorruptedException)

Aggregations

StreamCorruptedException (java.io.StreamCorruptedException)26 IOException (java.io.IOException)18 ObjectInputStream (java.io.ObjectInputStream)15 ByteArrayInputStream (java.io.ByteArrayInputStream)11 OptionalDataException (java.io.OptionalDataException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 InvalidClassException (java.io.InvalidClassException)5 ObjectOutputStream (java.io.ObjectOutputStream)5 NotSerializableException (java.io.NotSerializableException)4 Serializable (java.io.Serializable)4 SSLException (javax.net.ssl.SSLException)4 EOFException (java.io.EOFException)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)3 SocketTimeoutException (java.net.SocketTimeoutException)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 DataOutputStream (java.io.DataOutputStream)2 File (java.io.File)2 Socket (java.net.Socket)2 UUID (java.util.UUID)2