<commit_before>/*
 * Copyright 2012-2013 <NAME> (@sgodbillon) and Zenexity
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package reactivemongo.api.gridfs

import java.io._
import java.util.Arrays
import play.api.libs.iteratee._
import reactivemongo.api._
import reactivemongo.bson._
import reactivemongo.core.commands.LastError
import reactivemongo.utils._
import scala.concurrent.{ ExecutionContext, Future }
import reactivemongo.core.netty.ChannelBufferWritableBuffer
import reactivemongo.api.collections.GenericCollectionProducer
import reactivemongo.api.collections.GenericCollection

object `package` {
  private[gridfs] val logger = LazyLogger("reactivemongo.api.gridfs")
}

object Implicits {
  /** A default `BSONReader` for `ReadFile`. */
  implicit object DefaultReadFileReader extends BSONDocumentReader[DefaultReadFile] {
    import DefaultBSONHandlers._
    def read(doc: BSONDocument) = {
      val metadata = doc.elements.filterNot { element =>
        element._1 == "contentType" || element._1 == "filename" || element._1 == "uploadDate" ||
          element._1 == "chunkSize" || element._1 == "length" || element._1 == "md5" || element._1 == "_id"
      }.toSeq
      DefaultReadFile(
        doc.getAs[BSONValue]("_id").get,
        doc.getAs[BSONString]("contentType").map(_.value),
        doc.getAs[BSONString]("filename").map(_.value).get,
        doc.getAs[BSONNumberLike]("uploadDate").map(_.toLong),
        doc.getAs[BSONNumberLike]("chunkSize").map(_.toInt).get,
        doc.getAs[BSONNumberLike]("length").map(_.toInt).get,
        doc.getAs[BSONString]("md5").map(_.value),
        BSONDocument(metadata.toStream))
    }
  }
}

/** Metadata that cannot be customized. */
trait ComputedMetadata {<commit_msg>DefaultReadFileReader extends BSONDocumentReader[ReadFile[BSONValue]] instead of BSONDocumentReader[DefaultReadFile]<commit_after>/*
 * Copyright 2012-2013 <NAME> (@sgodbillon) and Zenexity
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package reactivemongo.api.gridfs

import java.io._
import java.util.Arrays
import play.api.libs.iteratee._
import reactivemongo.api._
import reactivemongo.bson._
import reactivemongo.core.commands.LastError
import reactivemongo.utils._
import scala.concurrent.{ ExecutionContext, Future }
import reactivemongo.core.netty.ChannelBufferWritableBuffer
import reactivemongo.api.collections.GenericCollectionProducer
import reactivemongo.api.collections.GenericCollection

object `package` {
  private[gridfs] val logger = LazyLogger("reactivemongo.api.gridfs")
}

object Implicits {
  /** A default `BSONReader` for `ReadFile`. */
  implicit object DefaultReadFileReader extends BSONDocumentReader[ReadFile[BSONValue]] {
    import DefaultBSONHandlers._
    def read(doc: BSONDocument) = {
      val metadata = doc.elements.filterNot { element =>
        element._1 == "contentType" || element._1 == "filename" || element._1 == "uploadDate" ||
          element._1 == "chunkSize" || element._1 == "length" || element._1 == "md5" || element._1 == "_id"
      }.toSeq
      DefaultReadFile(
        doc.getAs[BSONValue]("_id").get,
        doc.getAs[BSONString]("contentType").map(_.value),
        doc.getAs[BSONString]("filename").map(_.value).get,
        doc.getAs[BSONNumberLike]("uploadDate").map(_.toLong),
        doc.getAs[BSONNumberLike]("chunkSize").map(_.toInt).get,
        doc.getAs[BSONNumberLike]("length").map(_.toInt).get,
        doc.getAs[BSONString]("md5").map(_.value),
        BSONDocument(metadata.toStream))
    }
  }
}

/** Metadata that cannot be customized. */
trait ComputedMetadata {
{'fraction_non_alphanumeric': 0.11894942478836554, 'fraction_numerical': 0.009116561753852833, 'mean_word_length': 4.17752808988764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6598190', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1347, 'n_words': 345}