<commit_before>/**
 * 
 */
package cn.strong.leke.core.ip;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;

/**
 * IPv4Locator 工厂 Bean
 * 
 * @author liulongbiao
 *
 */
public class IPv4LocatorFactoryBean implements FactoryBean<IPv4Locator> {
	private static final int IP_RECORD_LENGTH = 7; // 索引记录长度，4 字节起始IP，3字节位置偏移
	private static final byte REDIRECT_MODE_1 = 0x01;
	private static final byte REDIRECT_MODE_2 = 0x02;
	public static final Charset GBK = Charset.forName("GBK");

	private byte[] b4 = new byte[4];
	private byte[] buf = new byte[32];

	private Resource datFile;
	private MappedByteBuffer mbb;
	private ArrayList<IPv4Entry> entries;
	private IPv4Locator locator;

	public void setDatFile(Resource datFile) {
		this.datFile = datFile;
	}

	public void afterPropertiesSet() throws Exception {
		Assert.notNull(datFile, "ip dat file is null!");
		File file = datFile.getFile();<commit_msg>实现 InitializingBean<commit_after>/**
 * 
 */
package cn.strong.leke.core.ip;

import java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteOrder;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;

/**
 * IPv4Locator 工厂 Bean
 * 
 * @author liulongbiao
 *
 */
public class IPv4LocatorFactoryBean implements FactoryBean<IPv4Locator>, InitializingBean {
	private static final int IP_RECORD_LENGTH = 7; // 索引记录长度，4 字节起始IP，3字节位置偏移
	private static final byte REDIRECT_MODE_1 = 0x01;
	private static final byte REDIRECT_MODE_2 = 0x02;
	public static final Charset GBK = Charset.forName("GBK");

	private byte[] b4 = new byte[4];
	private byte[] buf = new byte[32];

	private Resource datFile;
	private MappedByteBuffer mbb;
	private ArrayList<IPv4Entry> entries;
	private IPv4Locator locator;

	public void setDatFile(Resource datFile) {
		this.datFile = datFile;
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		Assert.notNull(datFile, "ip dat file is null!");
		File file = datFile.getFile();
{'fraction_non_alphanumeric': 0.10067873303167421, 'fraction_numerical': 0.015082956259426848, 'mean_word_length': 5.24235294117647, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6271800', 'n_tokens_mistral': 920, 'n_tokens_neox': 899, 'n_words': 214}