<commit_before>require 'java'
require "java_to_base64/version"
require 'i_can_has_java_class'

unless ::ICanHasJavaClass.java_class_defined?("org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString")
  require 'java_to_base64/jars/commons-codec-1.9.jar'
end

module JavaToBase64
  def self.included(klass)
    unless klass.java_kind_of?(::Java::JavaIo::Serializable)
      warn <<-SERIALIZABLE
        To include JavaToBase64 in a Java class you must implement java.io.Serializable
      SERIALIZABLE
    end

    klass.class_eval do 
      include ::JavaToBase64::InstanceMethods
      extend ::JavaToBase64::ClassMethods
    end
  end

  module InstanceMethods
    def to_base64
      byte_array_output_stream = java.io.ByteArrayOutputStream.new
      object_output_stream = java.io.ObjectOutputStream.new(byte_array_output_stream)
      object_output_stream.write_object(self)
      bytes = byte_array_output_stream.to_byte_array<commit_msg>check included_modules when checking if an interface is implemented<commit_after>require 'java'
require "java_to_base64/version"
require 'i_can_has_java_class'

unless ::ICanHasJavaClass.java_class_defined?("org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString")
  require 'java_to_base64/jars/commons-codec-1.9.jar'
end

module JavaToBase64
  def self.included(klass)
    unless java_instance_of?(klass, ::Java::JavaIo::Serializable)
      warn <<-SERIALIZABLE
        To include JavaToBase64 in a Java class you must implement java.io.Serializable
      SERIALIZABLE
    end

    klass.class_eval do 
      include ::JavaToBase64::InstanceMethods
      extend ::JavaToBase64::ClassMethods
    end
  end

  def self.java_instance_of?(klass, klass_or_module)
    return klass.java_kind_of?(klass_or_module) || klass.included_modules.include?(klass_or_module)
  end

  module InstanceMethods
    def to_base64
      byte_array_output_stream = java.io.ByteArrayOutputStream.new
      object_output_stream = java.io.ObjectOutputStream.new(byte_array_output_stream)
      object_output_stream.write_object(self)
      bytes = byte_array_output_stream.to_byte_array
{'fraction_non_alphanumeric': 0.07717647058823529, 'fraction_numerical': 0.018823529411764704, 'mean_word_length': 4.745945945945946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2843098', 'n_tokens_mistral': 691, 'n_tokens_neox': 681, 'n_words': 117}