<commit_before>package braingames.binary.store

import java.io.{ FileNotFoundException, InputStream, FileInputStream, File }
import akka.routing.Broadcast
import akka.agent.Agent
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits._
import braingames.binary.LoadBlock
import net.liftweb.common.Box
import net.liftweb.common.Failure

/**
 * A data store implementation which uses the hdd as data storage
 */
class FileDataStore extends DataStore {
  import DataStore._
  /**
   * Loads the due to x,y and z defined block into the cache array and
   * returns it.
   */
  def load(dataInfo: LoadBlock): Future[Box[Array[Byte]]] = {
    Future {
      try {
        val binaryStream =
          new FileInputStream(createFilename(dataInfo))
        Some(inputStreamToByteArray(binaryStream, dataInfo))
      } catch {
        case e: FileNotFoundException =>
          Failure("Couldn't find file: " + e)
      }
    }
  }

  /**
   *  Read file contents to a byteArray
   */
  def inputStreamToByteArray(is: InputStream, dataInfo: LoadBlock) = {
    val byteArray = new Array[Byte](dataInfo.dataSet.blockSize * dataInfo.dataLayer.bytesPerElement)
    is.read(byteArray, 0, dataInfo.dataSet.blockSize * dataInfo.dataLayer.bytesPerElement)
    //assert(is.skip(1) == 0, "INPUT STREAM NOT EMPTY")
    byteArray
  }
}<commit_msg>added error message if filedata store can't find file<commit_after>package braingames.binary.store

import java.io.{ FileNotFoundException, InputStream, FileInputStream, File }
import akka.routing.Broadcast
import akka.agent.Agent
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits._
import braingames.binary.LoadBlock
import net.liftweb.common.Box
import net.liftweb.common.Failure

/**
 * A data store implementation which uses the hdd as data storage
 */
class FileDataStore extends DataStore {
  import DataStore._
  /**
   * Loads the due to x,y and z defined block into the cache array and
   * returns it.
   */
  def load(dataInfo: LoadBlock): Future[Box[Array[Byte]]] = {
    Future {
      try {
        val binaryStream =
          new FileInputStream(createFilename(dataInfo))
        Some(inputStreamToByteArray(binaryStream, dataInfo))
      } catch {
        case e: FileNotFoundException =>
          System.err.println("File datastore couldn't find file: " + createFilename(dataInfo))
          Failure("Couldn't find file: " + e)
      }
    }
  }

  /**
   *  Read file contents to a byteArray
   */
  def inputStreamToByteArray(is: InputStream, dataInfo: LoadBlock) = {
    val byteArray = new Array[Byte](dataInfo.dataSet.blockSize * dataInfo.dataLayer.bytesPerElement)
    is.read(byteArray, 0, dataInfo.dataSet.blockSize * dataInfo.dataLayer.bytesPerElement)
    //assert(is.skip(1) == 0, "INPUT STREAM NOT EMPTY")
    byteArray
  }
}
{'fraction_non_alphanumeric': 0.09785286870820134, 'fraction_numerical': 0.0021119324181626186, 'mean_word_length': 3.561797752808989, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1093194', 'n_tokens_mistral': 856, 'n_tokens_neox': 842, 'n_words': 218}