Skip navigation links
net.openhft.chronicle.bytes

Class NativeBytes<U>

    • 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 IllegalStateException
        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:
        IllegalStateException - If the Bytes cannot be copied.
      • wrapWithNativeBytes

        @NotNull
        public static <T> @NotNull NativeBytes<T> wrapWithNativeBytes(@NotNull
                                                                               @NotNull BytesStore<?,T> bs,
                                                                               long capacity)
                                                                        throws IllegalStateException,
                                                                               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:
        IllegalStateException - If the BytesStore cannot be wrapped.
        IllegalArgumentException - If the provided capacity is not valid.
      • 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
      • ensureCapacity

        public void ensureCapacity(long desiredCapacity)
                            throws IllegalArgumentException,
                                   IllegalStateException
        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:
        IllegalStateException - If the Bytes object is closed and needs to be resized.
        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
      • writeSome

        @NotNull
        public @NotNull NativeBytes writeSome(@NotNull
                                                       @NotNull Bytes<?> bytes)
                                                throws IllegalStateException
        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:
        IllegalStateException - if released
      • 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.