⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ipfilterautoloaderimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   IpFilterAutoLoaderImpl.java

package org.gudy.azureus2.core3.ipfilter.impl;

import com.aelitis.azureus.ui.UIFunctions;
import com.aelitis.azureus.ui.UIFunctionsManager;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.ipfilter.IpRange;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.utils.resourcedownloader.*;
import org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl;

// Referenced classes of package org.gudy.azureus2.core3.ipfilter.impl:
//			IpFilterImpl, IpRangeImpl

public class IpFilterAutoLoaderImpl
{

	private static final LogIDs LOGID;
	public static final String CFG_AUTOLOAD_LAST = "Ip Filter Autoload Last Date";
	public static final String CFG_AUTOLOAD_FILE = "Ip Filter Autoload File";
	private static AEMonitor class_mon = new AEMonitor("IpFilterAutoLoaderImpl:class");
	private Object timerEventFilterReload;
	private final IpFilterImpl ipFilter;

	public IpFilterAutoLoaderImpl(IpFilterImpl ipFilter)
	{
		this.ipFilter = ipFilter;
		COConfigurationManager.setLongDefault("Ip Filter Autoload Last Date", 0L);
		COConfigurationManager.setStringDefault("Ip Filter Autoload File", "");
	}

	private void loadDATFilters(InputStream fin)
	{
		List new_ipRanges;
		InputStreamReader streamReader;
		BufferedReader reader;
		class_mon.enter();
		new_ipRanges = new ArrayList(1024);
		streamReader = null;
		reader = null;
		Pattern pattern = Pattern.compile("^(.*):([0-9\\.]+)[^0-9]+([0-9\\.]+).*");
		int parseMode = -1;
		streamReader = new InputStreamReader(fin, "utf8");
		reader = new BufferedReader(streamReader);
		int numConsecutiveUnknowns = 0;
		do
		{
			if (numConsecutiveUnknowns >= 1000)
				break;
			String line = reader.readLine();
			if (line == null)
				break;
			line = line.trim();
			if (line.startsWith("#") || line.length() == 0)
				continue;
			String description = "";
			String startIp = null;
			String endIp = null;
			int level = 0;
			if (parseMode <= 0 || parseMode == 1)
			{
				Matcher matcher = pattern.matcher(line);
				if (matcher.find())
				{
					if (parseMode != 1)
						parseMode = 1;
					description = matcher.group(1);
					startIp = matcher.group(2);
					endIp = matcher.group(3);
				} else
				{
					Logger.log(new LogEvent(LOGID, 1, (new StringBuilder()).append("unrecognized line while reading ip filter: ").append(line).toString()));
				}
			}
			if (parseMode != 1)
			{
				if (parseMode != 2)
					parseMode = 2;
				String sections[] = line.split(" *[-,] *", 4);
				if (sections.length >= 2 && (sections[0].indexOf('.') < 0 || sections[1].indexOf('.') < 0 || sections[0].length() > 15 || sections[1].length() > 15 || sections[0].length() < 7 || sections[1].length() < 7))
				{
					numConsecutiveUnknowns++;
					continue;
				}
				if (sections.length >= 4)
				{
					startIp = sections[0];
					endIp = sections[1];
					description = sections[3];
					try
					{
						level = Integer.parseInt(sections[2]);
					}
					catch (NumberFormatException e)
					{
						description = (new StringBuilder()).append(sections[2]).append(" ").append(description).toString();
					}
					for (int i = 4; i < sections.length; i++)
						description = (new StringBuilder()).append(description).append(" ").append(sections[i]).toString();

					numConsecutiveUnknowns = 0;
				} else
				if (sections.length == 3)
				{
					startIp = sections[0];
					endIp = sections[1];
					description = sections[2];
					numConsecutiveUnknowns = 0;
				} else
				if (sections.length == 2)
				{
					startIp = sections[0];
					endIp = sections[1];
					numConsecutiveUnknowns = 0;
				} else
				{
					numConsecutiveUnknowns++;
					continue;
				}
				if (level >= 128)
					continue;
			}
			if (startIp != null && endIp != null)
			{
				IpRangeImpl ipRange = new IpRangeImpl(description, startIp, endIp, true);
				ipRange.setAddedToRangeList(true);
				new_ipRanges.add(ipRange);
			}
		} while (true);
		Throwable e;
		if (reader != null)
			try
			{
				reader.close();
			}
			// Misplaced declaration of an exception variable
			catch (Throwable e) { }
		if (streamReader != null)
			try
			{
				streamReader.close();
			}
			// Misplaced declaration of an exception variable
			catch (Throwable e) { }
		for (Iterator it = new_ipRanges.iterator(); it.hasNext(); ((IpRange)it.next()).checkValid());
		ipFilter.markAsUpToDate();
		break MISSING_BLOCK_LABEL_800;
		it;
		Debug.out(it);
		if (reader != null)
			try
			{
				reader.close();
			}
			// Misplaced declaration of an exception variable
			catch (Iterator it) { }
		if (streamReader != null)
			try
			{
				streamReader.close();
			}
			// Misplaced declaration of an exception variable
			catch (Iterator it) { }
		for (Iterator it = new_ipRanges.iterator(); it.hasNext(); ((IpRange)it.next()).checkValid());
		ipFilter.markAsUpToDate();
		break MISSING_BLOCK_LABEL_800;
		Exception exception;
		exception;
		if (reader != null)
			try
			{
				reader.close();
			}
			catch (Throwable e) { }
		if (streamReader != null)
			try
			{
				streamReader.close();
			}
			catch (Throwable e) { }
		for (Iterator it = new_ipRanges.iterator(); it.hasNext(); ((IpRange)it.next()).checkValid());
		ipFilter.markAsUpToDate();
		throw exception;
		class_mon.exit();
		break MISSING_BLOCK_LABEL_820;
		Exception exception1;
		exception1;
		class_mon.exit();
		throw exception1;
	}

	private int getP2BFileVersion(InputStream is)
	{
		int i = 0;
_L1:
		int byteRead;
		if (i >= 4)
			break MISSING_BLOCK_LABEL_27;
		byteRead = is.read();
		if (byteRead != 255)
			return -1;
		i++;
		  goto _L1
		byte MAGIC[];
		int i;
		MAGIC = (new byte[] {
			80, 50, 66
		});
		i = 0;
_L2:
		byte b;
		if (i >= MAGIC.length)
			break MISSING_BLOCK_LABEL_76;
		b = MAGIC[i];
		if (b != is.read())
			return -1;
		i++;
		  goto _L2
		int p2bVersion;
		p2bVersion = is.read();
		Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("Log Filter: loading p2b version ").append(p2bVersion).toString()));
		return p2bVersion;
		IOException e;
		e;
		Debug.out(e);
		return -1;
	}

	protected void loadOtherFilters(boolean allowAsyncDownloading, boolean loadOldWhileAsyncDownloading)
	{
		int p2bVersion = -1;
		List new_ipRanges;
		InputStream fin;
		BufferedInputStream bin;
		boolean isURL;
		class_mon.enter();
		new_ipRanges = new ArrayList(1024);
		fin = null;
		bin = null;
		isURL = false;
		String file;
		File filtersFile;
		file = COConfigurationManager.getStringParameter("Ip Filter Autoload File");
		Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("IP Filter file: ").append(file).toString()));
		filtersFile = new File(file);
		if (filtersFile.exists())
		{
			isURL = false;
			break MISSING_BLOCK_LABEL_527;
		}
		if (UrlUtils.isURL(file))
			break MISSING_BLOCK_LABEL_192;
		if (bin != null)
			try
			{
				bin.close();
			}
			catch (Throwable e) { }
		if (fin != null)
			try
			{
				fin.close();
			}
			catch (Throwable e) { }
		for (Iterator it = new_ipRanges.iterator(); it.hasNext(); ((IpRange)it.next()).checkValid());
		ipFilter.markAsUpToDate();
		if (!isURL)
			setFileReloadTimer();
		class_mon.exit();
		return;
		isURL = true;
		filtersFile = FileUtil.getUserFile("ipfilter.dl");
		if (!filtersFile.exists())
			break MISSING_BLOCK_LABEL_359;
		if (!allowAsyncDownloading)
			break MISSING_BLOCK_LABEL_527;
		Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("Downloading ").append(file).append("  async").toString()));
		downloadFiltersAsync(new URL(file));
		if (loadOldWhileAsyncDownloading)
			break MISSING_BLOCK_LABEL_527;
		if (bin != null)
			try
			{
				bin.close();
			}
			catch (Throwable e) { }
		if (fin != null)
			try
			{
				fin.close();
			}
			catch (Throwable e) { }
		for (Iterator it = new_ipRanges.iterator(); it.hasNext(); ((IpRange)it.next()).checkValid());
		ipFilter.markAsUpToDate();
		if (!isURL)
			setFileReloadTimer();
		class_mon.exit();
		return;
		Logger.log(new LogEvent(LOGID, (new StringBuilder()).append("sync Downloading ").append(file).toString()));
		try
		{
			ResourceDownloader rd = ResourceDownloaderFactoryImpl.getSingleton().create(new URL(file));
			fin = rd.download();
			FileUtil.copyFile(fin, filtersFile);
			setNextAutoDownload(true);
			break MISSING_BLOCK_LABEL_527;
		}
		catch (ResourceDownloaderException e)
		{
			if (bin != null)
				try
				{
					bin.close();
				}
				catch (Throwable e) { }
			if (fin != null)
				try
				{
					fin.close();
				}
				catch (Throwable e) { }
			for (Iterator it = new_ipRanges.iterator(); it.hasNext(); ((IpRange)it.next()).checkValid());
			ipFilter.markAsUpToDate();
			if (!isURL)
				setFileReloadTimer();
		}
		class_mon.exit();
		return;
		ZipInputStream zip;
		fin = new FileInputStream(filtersFile);
		bin = new BufferedInputStream(fin, 16384);
		byte headerBytes[] = new byte[2];
		bin.mark(3);
		bin.read(headerBytes, 0, 2);
		bin.reset();
		if (headerBytes[1] == -117 && headerBytes[0] == 31)
		{
			GZIPInputStream gzip = new GZIPInputStream(bin);
			filtersFile = FileUtil.getUserFile("ipfilter.ext");
			FileUtil.copyFile(gzip, filtersFile);
			fin = new FileInputStream(filtersFile);
			bin = new BufferedInputStream(fin, 16384);
			break MISSING_BLOCK_LABEL_846;
		}
		if (headerBytes[0] != 80 || headerBytes[1] != 75)
			break MISSING_BLOCK_LABEL_846;
		zip = new ZipInputStream(bin);
		ZipEntry zipEntry;
		for (zipEntry = zip.getNextEntry(); zipEntry != null && zipEntry.getSize() < 0x100000L; zipEntry = zip.getNextEntry());
		if (zipEntry != null)
			break MISSING_BLOCK_LABEL_807;
		if (bin != null)
			try
			{
				bin.close();
			}
			catch (Throwable e) { }
		if (fin != null)
			try
			{
				fin.close();
			}
			catch (Throwable e) { }
		for (Iterator it = new_ipRanges.iterator(); it.hasNext(); ((IpRange)it.next()).checkValid());
		ipFilter.markAsUpToDate();
		if (!isURL)
			setFileReloadTimer();
		class_mon.exit();
		return;
		filtersFile = FileUtil.getUserFile("ipfilter.ext");
		FileUtil.copyFile(zip, filtersFile);
		fin = new FileInputStream(filtersFile);
		bin = new BufferedInputStream(fin, 16384);
		bin.mark(8);
		p2bVersion = getP2BFileVersion(bin);
		if (p2bVersion >= 1 && p2bVersion <= 3)
			break MISSING_BLOCK_LABEL_971;
		bin.reset();
		loadDATFilters(bin);
		if (bin != null)
			try
			{
				bin.close();
			}
			catch (Throwable e) { }
		if (fin != null)
			try
			{
				fin.close();
			}
			catch (Throwable e) { }
		for (Iterator it = new_ipRanges.iterator(); it.hasNext(); ((IpRange)it.next()).checkValid());
		ipFilter.markAsUpToDate();
		if (!isURL)
			setFileReloadTimer();
		class_mon.exit();
		return;
		byte descBytes[];
		byte ipBytes[];
		String encoding;
		int read;
		descBytes = new byte[255];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -