Skip navigation links
net.openhft.chronicle.bytes

Class NativeBytes<U>

    • Field Detail

      • capacity

        protected long capacity
    • Constructor Detail

      • NativeBytes

        public NativeBytes(@NotNull
                           @NotNull BytesStore store,
                           long capacity)
                    throws IllegalArgumentException,
                           net.openhft.chronicle.core.io.ClosedIllegalStateException
        Constructs a new instance of NativeBytes with the specified BytesStore and capacity.
        Parameters:
        store - the BytesStore to be used for the newly constructed instance
        capacity - the capacity to be used for the newly constructed instance
        Throws:
        net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.
        net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe way
        IllegalArgumentException
      • NativeBytes

        public NativeBytes(@NotNull
                           @NotNull BytesStore store)
                    throws IllegalArgumentException,
                           net.openhft.chronicle.core.io.ClosedIllegalStateException
        Constructs a new instance of NativeBytes with the specified BytesStore and the store's capacity.
        Parameters:
        store - the BytesStore to be used for the newly constructed instance
        Throws:
        net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.
        net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe way
        IllegalArgumentException
    • Method Detail

      • areNewGuarded

        public static boolean areNewGuarded()
        Checks if new NativeBytes instances will be guarded or not.
        Returns:
        true if new NativeBytes instances will be guarded, false otherwise
      • setNewGuarded

        public static boolean setNewGuarded(boolean guarded)
        Sets the guarded state for new NativeBytes instances.
        Parameters:
        guarded - true to turn on guarding for new NativeBytes instances, false to turn it off
        Returns:
        true if the operation is successful, false otherwise
      • resetNewGuarded

        public static void resetNewGuarded()
        Resets the guarded state for new NativeBytes instances to its default value.
      • nativeBytes

        @NotNull
        public static @NotNull NativeBytes<Void> nativeBytes()
        Creates a new instance of NativeBytes with an empty BytesStore and maximum capacity.
        Returns:
        A new instance of NativeBytes.
        Throws:
        AssertionError - If there's an error during the wrapping process.
      • nativeBytes

        @NotNull
        public static @NotNull NativeBytes<Void> nativeBytes(long initialCapacity)
                                                               throws IllegalArgumentException
        Creates a new instance of NativeBytes with a specific initial capacity.
        Parameters:
        initialCapacity - The initial capacity of the NativeBytes instance.
        Returns:
        A new instance of NativeBytes.
        Throws:
        IllegalArgumentException - If the initial capacity is not valid.
        AssertionError - If there's an error during the wrapping process.
      • copyOf

        @Deprecated
        public static BytesStore<Bytes<Void>,Void> copyOf(@NotNull
                                                                      @NotNull Bytes<?> bytes)
                                                               throws net.openhft.chronicle.core.io.ClosedIllegalStateException
        Deprecated. This method is to be removed in version x.26.
        Creates a new copy of the provided Bytes. This method is deprecated and will be removed in version x.26.
        Parameters:
        bytes - The Bytes to copy.
        Returns:
        A new instance of BytesStore with the copied Bytes.
        Throws:
        net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.
        net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe way
      • wrapWithNativeBytes

        @NotNull
        public static <T> @NotNull NativeBytes<T> wrapWithNativeBytes(@NotNull
                                                                               @NotNull BytesStore<?,T> bs,
                                                                               long capacity)
                                                                        throws net.openhft.chronicle.core.io.ClosedIllegalStateException,
                                                                               IllegalArgumentException
        Wraps the provided BytesStore with a new instance of NativeBytes with the specified capacity.
        Parameters:
        bs - The BytesStore to wrap.
        capacity - The capacity of the new NativeBytes instance.
        Returns:
        A new instance of NativeBytes.
        Throws:
        IllegalArgumentException - If the provided capacity is not valid.
        net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.
        net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe way
      • maxCapacityFor

        protected static <T> long maxCapacityFor(@NotNull
                                                 @NotNull BytesStore<?,T> bs)
      • capacity

        public long capacity()
        Description copied from interface: BytesStore
        Provides the maximum limit that can be set for the ByteStore.
        Specified by:
        capacity in interface BytesStore<Bytes<U>,U>
        Overrides:
        capacity in class AbstractBytes<U>
        Returns:
        the maximum capacity of the ByteStore
      • writeCheckOffset

        protected void writeCheckOffset(long offset,
                                        long adding)
                                 throws BufferOverflowException,
                                        net.openhft.chronicle.core.io.ClosedIllegalStateException,
                                        net.openhft.chronicle.core.io.ThreadingIllegalStateException
        Overrides:
        writeCheckOffset in class AbstractBytes<U>
        Throws:
        BufferOverflowException
        net.openhft.chronicle.core.io.ClosedIllegalStateException
        net.openhft.chronicle.core.io.ThreadingIllegalStateException
      • ensureCapacity

        public void ensureCapacity(long desiredCapacity)
                            throws IllegalArgumentException,
                                   net.openhft.chronicle.core.io.ClosedIllegalStateException,
                                   net.openhft.chronicle.core.io.ThreadingIllegalStateException
        Description copied from interface: Bytes
        Ensures that this Bytes object has the capacity to accommodate the specified amount of data.

        If this Bytes object is elastic and doesn't have enough capacity, it will be resized. If it is not elastic and doesn't have enough capacity, a DecoratedBufferOverflowException will be thrown.

        Parameters:
        desiredCapacity - The minimum capacity, in bytes, that is required.
        Throws:
        net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.
        net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe way
        IllegalArgumentException
      • isElastic

        public boolean isElastic()
        Description copied from interface: Bytes
        Checks if this Bytes object is elastic, meaning it can dynamically resize when more data is written than its current Bytes.realCapacity().

        Elastic Bytes objects can automatically grow to accommodate additional data, whereas non-elastic ones have a fixed capacity.

        Specified by:
        isElastic in interface Bytes<U>
        Overrides:
        isElastic in class VanillaBytes<U>
        Returns:
        true if this Bytes object is elastic; false otherwise.
      • isEqual

        public boolean isEqual(long start,
                               long length,
                               String s)
        Description copied from interface: BytesStore
        Returns if a specified portion of this BytesStore is equal to a specified String. The portion is specified with its offset and length.
        Parameters:
        start - the portion offset
        length - the number of bytes from this BytesStore that should be compared to s
        s - the String to compare to
        Returns:
        true if the specified portion of this BytesStore is equal to s
      • bytesStore

        public void bytesStore(@NotNull
                               @NotNull BytesStore<Bytes<U>,U> byteStore,
                               long offset,
                               long length)
                        throws IllegalStateException,
                               IllegalArgumentException,
                               BufferUnderflowException,
                               net.openhft.chronicle.core.io.ClosedIllegalStateException
        Description copied from interface: Byteable
        Sets the reference to a data type that points to the underlying ByteStore.
        Specified by:
        bytesStore in interface Byteable<Bytes<U>,U>
        Overrides:
        bytesStore in class VanillaBytes<U>
        Parameters:
        byteStore - the fixed-point ByteStore
        offset - the offset within the ByteStore, indicating the starting point of the memory section
        length - the length of the memory section within the ByteStore
        Throws:
        net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.
        net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe way
        IllegalArgumentException - If the provided arguments are invalid
        BufferUnderflowException - If the new memory section starts before the start of the ByteStore
        IllegalStateException
      • writeSome

        @NotNull
        public @NotNull NativeBytes writeSome(@NotNull
                                                       @NotNull Bytes<?> bytes)
                                                throws net.openhft.chronicle.core.io.ClosedIllegalStateException,
                                                       net.openhft.chronicle.core.io.ThreadingIllegalStateException
        Description copied from interface: StreamingDataOutput
        Writes data from the specified Bytes object into the output stream. The amount of data written is the minimum of the remaining data in the Bytes object and the remaining space in the output stream. The position of this output stream is updated accordingly, but the read position of the input data is not changed.
        Parameters:
        bytes - the Bytes object from which data is read.
        Returns:
        The current StreamingDataOutput instance.
        Throws:
        net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.
        net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe way
      • writeOffsetPositionMoved

        protected long writeOffsetPositionMoved(long adding,
                                                long advance)
                                         throws BufferOverflowException,
                                                net.openhft.chronicle.core.io.ClosedIllegalStateException,
                                                net.openhft.chronicle.core.io.ThreadingIllegalStateException
        Overrides:
        writeOffsetPositionMoved in class AbstractBytes<U>
        Throws:
        BufferOverflowException
        net.openhft.chronicle.core.io.ClosedIllegalStateException
        net.openhft.chronicle.core.io.ThreadingIllegalStateException
      • writeByte

        @NotNull
        public @NotNull Bytes<U> writeByte(byte i8)
                                             throws BufferOverflowException,
                                                    IllegalStateException,
                                                    net.openhft.chronicle.core.io.ClosedIllegalStateException,
                                                    net.openhft.chronicle.core.io.ThreadingIllegalStateException
        Description copied from interface: StreamingDataOutput
        Writes a byte to the data stream.
        Specified by:
        writeByte in interface StreamingDataOutput<Bytes<U>>
        Overrides:
        writeByte in class AbstractBytes<U>
        Parameters:
        i8 - The byte to be written.
        Returns:
        The current StreamingDataOutput instance.
        Throws:
        BufferOverflowException - If there is insufficient space in the buffer.
        net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.
        net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe way
        IllegalStateException
      • writeLong

        @NotNull
        public @NotNull Bytes<U> writeLong(long i64)
                                             throws BufferOverflowException,
                                                    IllegalStateException,
                                                    net.openhft.chronicle.core.io.ClosedIllegalStateException,
                                                    net.openhft.chronicle.core.io.ThreadingIllegalStateException
        Description copied from interface: StreamingDataOutput
        Writes a long integer to the data stream.
        Specified by:
        writeLong in interface StreamingDataOutput<Bytes<U>>
        Overrides:
        writeLong in class AbstractBytes<U>
        Parameters:
        i64 - The long integer to be written.
        Returns:
        The current StreamingDataOutput instance.
        Throws:
        BufferOverflowException - If there is insufficient space in the buffer.
        net.openhft.chronicle.core.io.ClosedIllegalStateException - If the resource has been released or closed.
        net.openhft.chronicle.core.io.ThreadingIllegalStateException - If this resource was accessed by multiple threads in an unsafe way
        IllegalStateException
      • readRemaining

        public long readRemaining()
        Calculates the number of bytes remaining that can be read from the current read position.

        If the resource is closed, the returned value is unspecified.

        Returns:
        The number of bytes that can still be read.

Copyright © 2023. All rights reserved.