Class Base64Converter

java.lang.Object
io.github.jspinak.brobot.util.string.Base64Converter

@Component public class Base64Converter extends Object
Utility for Base64 encoding of files and byte arrays in the Brobot framework.

Base64Converter provides convenient methods for converting binary data to Base64-encoded strings, which is essential for data serialization, transmission, and storage in text-based formats. This utility is particularly important for handling image data and other binary content within the framework's JSON-based configuration and communication systems.

Key features:

  • File Encoding: Converts files directly to Base64 strings by path
  • Byte Array Encoding: Encodes raw byte arrays for in-memory data
  • Error Handling: Gracefully handles file reading errors
  • Static Methods: Utility methods accessible without instantiation

Common use cases:

  • Encoding images for storage in JSON configurations
  • Preparing binary data for network transmission
  • Converting screenshots for inclusion in reports
  • Serializing binary patterns for mock data
  • Embedding resources in text-based formats

Implementation notes:

  • Uses standard Java Base64 encoder for compatibility
  • Reads entire file into memory - suitable for typical image sizes
  • Returns null on error rather than throwing exceptions
  • Thread-safe due to stateless design

In the model-based approach, Base64Converter enables the framework to work seamlessly with binary data in text-oriented environments. This is crucial for features like configuration-based test scenarios, where image patterns need to be embedded in JSON files, and for transmitting visual data through text-based protocols.

Since:
1.0
See Also:
  • Constructor Details

    • Base64Converter

      public Base64Converter()
  • Method Details

    • convert

      public static String convert(String filePath)
    • convert

      public static String convert(byte[] byteArray)