<commit_before>package org.apache.spark.ml.dsl.utils

import java.security.Key

import javax.xml.bind.DatatypeConverter
import com.tribbloids.spookystuff.utils.IDMixin
import javax.crypto.spec.SecretKeySpec

/**
  * Created by peng on 31/10/16.
  */
class ByteEncoded(
    blob: Array[Byte]
) extends IDMixin {

  def asBytes: Array[Byte] = blob

  lazy val _id = blob.toList

  lazy val toBase64Str = DatatypeConverter.printBase64Binary(blob)
  lazy val toBase16Str = DatatypeConverter.printHexBinary(blob)
  lazy val toUTF8Str = new String(blob, "UTF-8")

  override def toString: String = toBase64Str

  def toKeySpec(algorithm: String, lengthOpt: Option[Int] = None) = {
    val _blob = lengthOpt match {
      case Some(v) => blob.slice(0, v)
      case None    => blob
    }
    new SecretKeySpec(_blob, 0, blob.length, algorithm)
  }

  def toAESKey(lengthOpt: Option[Int] = Some(16)) = toKeySpec("AES", lengthOpt)<commit_msg>add an implicit conversion import<commit_after>package org.apache.spark.ml.dsl.utils

import java.security.Key

import javax.xml.bind.DatatypeConverter
import com.tribbloids.spookystuff.utils.IDMixin
import javax.crypto.spec.SecretKeySpec

import scala.language.implicitConversions

/**
  * Created by peng on 31/10/16.
  */
class ByteEncoded(
    blob: Array[Byte]
) extends IDMixin {

  def asBytes: Array[Byte] = blob

  lazy val _id = blob.toList

  lazy val toBase64Str = DatatypeConverter.printBase64Binary(blob)
  lazy val toBase16Str = DatatypeConverter.printHexBinary(blob)
  lazy val toUTF8Str = new String(blob, "UTF-8")

  override def toString: String = toBase64Str

  def toKeySpec(algorithm: String, lengthOpt: Option[Int] = None) = {
    val _blob = lengthOpt match {
      case Some(v) => blob.slice(0, v)
      case None    => blob
    }
    new SecretKeySpec(_blob, 0, blob.length, algorithm)
  }

  def toAESKey(lengthOpt: Option[Int] = Some(16)) = toKeySpec("AES", lengthOpt)
{'fraction_non_alphanumeric': 0.10679108346293416, 'fraction_numerical': 0.020736132711249352, 'mean_word_length': 4.026041666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3110110', 'n_tokens_mistral': 681, 'n_tokens_neox': 649, 'n_words': 157}