Class CodeAreaUtils


  • @ParametersAreNonnullByDefault
    public class CodeAreaUtils
    extends java.lang.Object
    Binary editor component utilities.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static char[] byteToHexChars​(byte value)
      Converts byte value to sequence of hexadecimal characters.
      static void byteToHexChars​(char[] target, byte value)
      Converts byte value to sequence of two hexadecimal characters.
      static void byteToCharsCode​(byte dataByte, CodeType codeType, char[] targetData, int targetPosition, CodeCharactersCase charCase)
      Converts byte value to sequence of characters of given code type.
      static java.lang.IllegalStateException getInvalidTypeException​(java.lang.Enum<?> enumObject)  
      static byte[] characterToBytes​(char value, java.nio.charset.Charset charset)
      Converts provided character into byte array for given charset.
      static void insertHexStringIntoData​(java.lang.String insertedString, org.exbin.auxiliary.paged_data.EditableBinaryData data, CodeType codeType)
      Inserts text encoded data of given code type into given binary data.
      static boolean isValidCodeKeyValue​(char keyValue, int codeOffset, CodeType codeType)
      Return true if provided character is valid for given code type and position.
      static int longToBaseCode​(char[] target, int targetOffset, long value, int base, int lengthLimit, boolean fillZeros, CodeCharactersCase characterCase)
      Converts long value to code of given base and length limit.
      static void longToHexChars​(char[] target, long value, int length)
      Converts long value to sequence of hexadecimal character.
      static char[] longToHexChars​(long value, int length)
      Converts long value to sequence of hexadecimal character.
      static void requireNonNull​(java.lang.Object... objects)  
      static <T> T requireNonNull​(T object)  
      static <T> T requireNonNull​(T object, java.lang.String message)  
      static <T> T requireNonNullContentData​(T object)  
      static byte setCodeValue​(byte byteValue, int value, int codeOffset, CodeType codeType)
      Returns modified byte value after single code value is applied.
      static byte stringCodeToByte​(java.lang.String code, CodeType codeType)
      Converts string of characters to byte value.
      static void throwInvalidTypeException​(java.lang.Enum<?> enumObject)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • UPPER_HEX_CODES

        public static final char[] UPPER_HEX_CODES
      • LOWER_HEX_CODES

        public static final char[] LOWER_HEX_CODES
      • MIME_CLIPBOARD_BINARY

        public static final java.lang.String MIME_CLIPBOARD_BINARY
        See Also:
        Constant Field Values
      • CONTENT_DATA_ERROR

        public static final java.lang.String CONTENT_DATA_ERROR
        See Also:
        Constant Field Values
    • Method Detail

      • byteToHexChars

        @Nonnull
        public static char[] byteToHexChars​(byte value)
        Converts byte value to sequence of hexadecimal characters.
        Parameters:
        value - byte value
        Returns:
        sequence of two hexadecimal chars with upper case
      • byteToHexChars

        public static void byteToHexChars​(char[] target,
                                          byte value)
        Converts byte value to sequence of two hexadecimal characters.
        Parameters:
        target - target char array (output parameter)
        value - byte value
      • longToHexChars

        @Nonnull
        public static char[] longToHexChars​(long value,
                                            int length)
        Converts long value to sequence of hexadecimal character. No range checking.
        Parameters:
        value - long value
        length - length of the target sequence
        Returns:
        hexadecimal characters
      • longToHexChars

        public static void longToHexChars​(char[] target,
                                          long value,
                                          int length)
        Converts long value to sequence of hexadecimal character. No range checking.
        Parameters:
        target - target char array (output parameter)
        value - long value
        length - length of the target sequence
      • byteToCharsCode

        public static void byteToCharsCode​(byte dataByte,
                                           CodeType codeType,
                                           char[] targetData,
                                           int targetPosition,
                                           CodeCharactersCase charCase)
        Converts byte value to sequence of characters of given code type.
        Parameters:
        dataByte - byte value
        codeType - code type
        targetData - target array of characters (output parameter)
        targetPosition - target position in array of characters
        charCase - case type for alphabetical characters
      • stringCodeToByte

        public static byte stringCodeToByte​(java.lang.String code,
                                            CodeType codeType)
        Converts string of characters to byte value.
        Parameters:
        code - source text string
        codeType - code type
        Returns:
        byte value
        Throws:
        java.lang.IllegalArgumentException - if code is invalid
      • longToBaseCode

        public static int longToBaseCode​(char[] target,
                                         int targetOffset,
                                         long value,
                                         int base,
                                         int lengthLimit,
                                         boolean fillZeros,
                                         CodeCharactersCase characterCase)
        Converts long value to code of given base and length limit. Optionally fills rest of the value with zeros.
        Parameters:
        target - target characters array (output parameter)
        targetOffset - offset position in target array
        value - value value
        base - target numerical base, supported values are 1 to 16
        lengthLimit - length limit
        fillZeros - flag if rest of the value should be filled with zeros
        characterCase - upper case for values greater than 9
        Returns:
        offset of characters position
      • characterToBytes

        @Nonnull
        public static byte[] characterToBytes​(char value,
                                              java.nio.charset.Charset charset)
        Converts provided character into byte array for given charset.
        Parameters:
        value - character value
        charset - charset
        Returns:
        byte array
      • insertHexStringIntoData

        public static void insertHexStringIntoData​(java.lang.String insertedString,
                                                   org.exbin.auxiliary.paged_data.EditableBinaryData data,
                                                   CodeType codeType)
        Inserts text encoded data of given code type into given binary data.
        Parameters:
        insertedString - inserted text in format of code type
        data - data output (output parameter)
        codeType - type of code to use
      • isValidCodeKeyValue

        public static boolean isValidCodeKeyValue​(char keyValue,
                                                  int codeOffset,
                                                  CodeType codeType)
        Return true if provided character is valid for given code type and position.
        Parameters:
        keyValue - keyboard key value
        codeOffset - current code offset
        codeType - current code type
        Returns:
        true if key value value is valid
      • setCodeValue

        public static byte setCodeValue​(byte byteValue,
                                        int value,
                                        int codeOffset,
                                        CodeType codeType)
        Returns modified byte value after single code value is applied.
        Parameters:
        byteValue - original byte value
        value - code value
        codeOffset - code offset
        codeType - code type
        Returns:
        modified byte value
      • requireNonNull

        @Nonnull
        public static <T> T requireNonNull​(@Nullable
                                           T object)
      • requireNonNull

        @Nonnull
        public static <T> T requireNonNull​(@Nullable
                                           T object,
                                           java.lang.String message)
      • requireNonNull

        public static void requireNonNull​(java.lang.Object... objects)
      • requireNonNullContentData

        @Nonnull
        public static <T> T requireNonNullContentData​(@Nullable
                                                      T object)
      • throwInvalidTypeException

        public static void throwInvalidTypeException​(java.lang.Enum<?> enumObject)
      • getInvalidTypeException

        @Nonnull
        public static java.lang.IllegalStateException getInvalidTypeException​(java.lang.Enum<?> enumObject)