<commit_before>/*
 *
 *  *  Copyright 2010-2016 OrientDB LTD (http://orientdb.com)
 *  *
 *  *  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.
 *  *
 *  * For more information: http://orientdb.com
 *
 */

package com.orientechnologies.orient.core.serialization.serializer.record.binary;

import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.impl.OBlob;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ORecordFlat;
import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer;

import java.util.Base64;

public class ORecordSerializerBinary implements ORecordSerializer {

  public static final  String                  NAME                   = "ORecordSerializerBinary";
  public static final  ORecordSerializerBinary INSTANCE               = new ORecordSerializerBinary();
  private final byte                    CURRENT_RECORD_VERSION;

  private ODocumentSerializer[] serializerByVersion;

  private void init(){
    serializerByVersion = new ODocumentSerializer[2];
    serializerByVersion[0] = new ORecordSerializerBinaryV0();
    serializerByVersion[1] = new ORecordSerializerBinaryV1();
  }
  
  public ORecordSerializerBinary(byte serializerVersion){
    CURRENT_RECORD_VERSION = serializerVersion;
    init();
  }
  
  public ORecordSerializerBinary() {
    CURRENT_RECORD_VERSION = 0;
    init();
  }

  public int getNumberOfSupportedVersions(){
    return serializerByVersion.length;
  }
  
  @Override
  public int getCurrentVersion() {
    return CURRENT_RECORD_VERSION;
  }

  @Override
  public int getMinSupportedVersion() {
    return CURRENT_RECORD_VERSION;
  }

  public ODocumentSerializer getSerializer(final int iVersion) {
    return serializerByVersion[iVersion];
  }

  public ODocumentSerializer getCurrentSerializer() {
    return serializerByVersion[serializerByVersion.length - 1];
  }

  @Override
  public String toString() {
    return NAME;
  }

  @Override
  public ORecord fromStream(final byte[] iSource, ORecord iRecord, final String[] iFields) {
    if (iSource == null || iSource.length == 0)
      return iRecord;
    if (iRecord == null)
      iRecord = new ODocument();
    else if (iRecord instanceof OBlob) {
      iRecord.fromStream(iSource);
      return iRecord;<commit_msg>fixed inconsistency with choosing default serializer<commit_after>/*
 *
 *  *  Copyright 2010-2016 OrientDB LTD (http://orientdb.com)
 *  *
 *  *  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.
 *  *
 *  * For more information: http://orientdb.com
 *
 */

package com.orientechnologies.orient.core.serialization.serializer.record.binary;

import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.orient.core.record.ORecord;
import com.orientechnologies.orient.core.record.impl.OBlob;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.record.impl.ORecordFlat;
import com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializer;

import java.util.Base64;

public class ORecordSerializerBinary implements ORecordSerializer {

  public static final  String                  NAME                   = "ORecordSerializerBinary";
  public static final  ORecordSerializerBinary INSTANCE               = new ORecordSerializerBinary();
  private final byte                    CURRENT_RECORD_VERSION;

  private ODocumentSerializer[] serializerByVersion;

  private void init(){
    serializerByVersion = new ODocumentSerializer[2];
    serializerByVersion[0] = new ORecordSerializerBinaryV0();
    serializerByVersion[1] = new ORecordSerializerBinaryV1();
  }
  
  public ORecordSerializerBinary(byte serializerVersion){
    CURRENT_RECORD_VERSION = serializerVersion;
    init();
  }
  
  public ORecordSerializerBinary() {
    CURRENT_RECORD_VERSION = 0;
    init();
  }

  public int getNumberOfSupportedVersions(){
    return serializerByVersion.length;
  }
  
  @Override
  public int getCurrentVersion() {
    return CURRENT_RECORD_VERSION;
  }

  @Override
  public int getMinSupportedVersion() {
    return CURRENT_RECORD_VERSION;
  }

  public ODocumentSerializer getSerializer(final int iVersion) {
    return serializerByVersion[iVersion];
  }

  public ODocumentSerializer getCurrentSerializer() {
    return serializerByVersion[CURRENT_RECORD_VERSION];
  }

  @Override
  public String toString() {
    return NAME;
  }

  @Override
  public ORecord fromStream(final byte[] iSource, ORecord iRecord, final String[] iFields) {
    if (iSource == null || iSource.length == 0)
      return iRecord;
    if (iRecord == null)
      iRecord = new ODocument();
    else if (iRecord instanceof OBlob) {
      iRecord.fromStream(iSource);
      return iRecord;
{'fraction_non_alphanumeric': 0.08440797186400938, 'fraction_numerical': 0.007201473789984927, 'mean_word_length': 3.7023622047244094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '146742', 'n_tokens_mistral': 1748, 'n_tokens_neox': 1703, 'n_words': 443}