<commit_before>/*
 * jETeL/CloverETL - Java based ETL application framework.
 * Copyright (c) Javlin, a.s. (<EMAIL>)
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.jetel.data;

import java.io.UnsupportedEncodingException;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.charset.CharsetDecoder;
import java.util.Arrays;

import org.jetel.metadata.DataFieldMetadata;
import org.jetel.util.CloverPublicAPI;
import org.jetel.util.bytes.ByteBufferUtils;
import org.jetel.util.bytes.CloverBuffer;
import org.jetel.util.file.ZipUtils;
import org.jetel.util.string.Compare;

/**
 * Class implementing field which represents gzip-compressed array of bytes. 
 * @author <NAME> (<EMAIL>), Javlin Consulting (www.javlinconsulting.cz)
 * @since 12/01/06  
 */
@CloverPublicAPI
public class CompressedByteDataField extends ByteDataField {
	
	/** lenght of data represented by the field. */ 
	private int dataLen;

	public CompressedByteDataField(DataFieldMetadata _metadata) {
		super(_metadata);
		dataLen = 0;
	}

	public CompressedByteDataField(DataFieldMetadata _metadata, boolean plain) {
		super(_metadata, plain);
		dataLen = 0;
	}

	public CompressedByteDataField(DataFieldMetadata _metadata, byte[] value) {
		super(_metadata, value);
		// dataLen is set when the setValue(byte[]) is called in the constructor of the super class
	}
	
	@Override
	public DataField duplicate(){
		CompressedByteDataField compressedByteDataField = new CompressedByteDataField(metadata);
		compressedByteDataField.setValue(this);

		return compressedByteDataField;
	}

	/**
	 * @see org.jetel.data.DataField#copyField(org.jetel.data.DataField)
     * @deprecated use setValue(DataField) instead
	 */
	@Override
	public void copyFrom(DataField fromField){
	    if (fromField instanceof CompressedByteDataField){
	    	CompressedByteDataField compressedByteDataField = (CompressedByteDataField) fromField;
	        if (!compressedByteDataField.isNull){
	            int length = compressedByteDataField.value.length;
	            if (this.value == null || this.value.length != length){
	                this.value = new byte[length];
	            }
	            System.arraycopy(compressedByteDataField.value, 0, this.value, 0, length);
	        }
	        setNull(compressedByteDataField.isNull);
	        dataLen = compressedByteDataField.dataLen;
	    } else {
	        super.copyFrom(fromField);
        }
	}
	
	@Override
	public void setValue(byte[] value) {
		dataLen = value == null ? 0 : value.length;
		super.setValue(ZipUtils.compress(value));
	}
	
	@Override
	public void setValue(byte[] value, int fromOffset, int length) {<commit_msg>FINDBUGS: CLO-11945<commit_after>/*
 * jETeL/CloverETL - Java based ETL application framework.
 * Copyright (c) <NAME>. (<EMAIL>)
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package org.jetel.data;

import java.io.UnsupportedEncodingException;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.charset.CharsetDecoder;
import java.util.Arrays;

import org.jetel.metadata.DataFieldMetadata;
import org.jetel.util.CloverPublicAPI;
import org.jetel.util.bytes.ByteBufferUtils;
import org.jetel.util.bytes.CloverBuffer;
import org.jetel.util.file.ZipUtils;
import org.jetel.util.string.Compare;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

/**
 * Class implementing field which represents gzip-compressed array of bytes. 
 * @author <NAME> (<EMAIL>), Javlin Consulting (www.javlinconsulting.cz)
 * @since 12/01/06  
 */
@CloverPublicAPI
public class CompressedByteDataField extends ByteDataField {
	
	/** lenght of data represented by the field. */ 
	private int dataLen;

	public CompressedByteDataField(DataFieldMetadata _metadata) {
		super(_metadata);
		dataLen = 0;
	}

	public CompressedByteDataField(DataFieldMetadata _metadata, boolean plain) {
		super(_metadata, plain);
		dataLen = 0;
	}

	public CompressedByteDataField(DataFieldMetadata _metadata, byte[] value) {
		super(_metadata, value);
		// dataLen is set when the setValue(byte[]) is called in the constructor of the super class
	}
	
	@Override
	public DataField duplicate(){
		CompressedByteDataField compressedByteDataField = new CompressedByteDataField(metadata);
		compressedByteDataField.setValue(this);

		return compressedByteDataField;
	}

	/**
	 * @see org.jetel.data.DataField#copyField(org.jetel.data.DataField)
     * @deprecated use setValue(DataField) instead
	 */
	@Override
	public void copyFrom(DataField fromField){
	    if (fromField instanceof CompressedByteDataField){
	    	CompressedByteDataField compressedByteDataField = (CompressedByteDataField) fromField;
	        if (!compressedByteDataField.isNull){
	            int length = compressedByteDataField.value.length;
	            if (this.value == null || this.value.length != length){
	                this.value = new byte[length];
	            }
	            System.arraycopy(compressedByteDataField.value, 0, this.value, 0, length);
	        }
	        setNull(compressedByteDataField.isNull);
	        dataLen = compressedByteDataField.dataLen;
	    } else {
	        super.copyFrom(fromField);
        }
	}
	
	@SuppressFBWarnings("NP_NULL_PARAM_DEREF")
	@Override
	public void setValue(byte[] value) {
		dataLen = value == null ? 0 : value.length;
		super.setValue(ZipUtils.compress(value));
	}
	
	@Override
	public void setValue(byte[] value, int fromOffset, int length) {
{'fraction_non_alphanumeric': 0.09000439045807113, 'fraction_numerical': 0.008634567539879994, 'mean_word_length': 4.0213078618662745, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2891754', 'n_tokens_mistral': 2085, 'n_tokens_neox': 1939, 'n_words': 593}