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

📄 iprangeimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// 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:   IpRangeImpl.java

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

import java.net.UnknownHostException;
import org.gudy.azureus2.core3.ipfilter.*;
import org.gudy.azureus2.core3.tracker.protocol.PRHelpers;

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

public class IpRangeImpl
	implements IpRange
{

	private static final byte FLAG_SESSION_ONLY = 1;
	private static final byte FLAG_ADDED_TO_RANGE_LIST = 2;
	private static final byte FLAG_INVALID_START = 8;
	private static final byte FLAG_INVALID_END = 16;
	private static final byte FLAG_INVALID = 24;
	private int ipStart;
	private int ipEnd;
	private byte flags;
	private Object descRef;
	private static final byte FLAG_MERGED = 4;
	private int merged_end;
	private IpRange my_merged_entries[];

	public IpRangeImpl(String _description, String _startIp, String _endIp, boolean _sessionOnly)
	{
		descRef = null;
		if (_sessionOnly)
			flags = 1;
		if (_startIp == null || _endIp == null)
			throw new RuntimeException("Invalid start/end values - null not supported");
		try
		{
			ipStart = PRHelpers.addressToInt(_startIp);
		}
		catch (UnknownHostException e)
		{
			flags |= 8;
		}
		try
		{
			ipEnd = PRHelpers.addressToInt(_endIp);
		}
		catch (UnknownHostException e)
		{
			flags |= 0x10;
		}
		if (_description != "")
			setDescription(_description);
		checkValid();
	}

	public IpRangeImpl(String _description, int _startIp, int _endIp, boolean _sessionOnly)
	{
		descRef = null;
		if (_sessionOnly)
			flags = 1;
		ipStart = _startIp;
		ipEnd = _endIp;
		if (_description != "")
			setDescription(_description);
		checkValid();
	}

	public void checkValid()
	{
		((IpFilterImpl)IpFilterImpl.getInstance()).setValidOrNot(this, isValid());
	}

	public boolean isValid()
	{
		if ((flags & 0x18) > 0)
			return false;
		long start_address = ipStart;
		long end_address = ipEnd;
		if (start_address < 0L)
			start_address += 0x100000000L;
		if (end_address < 0L)
			end_address += 0x100000000L;
		return end_address >= start_address;
	}

	public boolean isInRange(String ipAddress)
	{
		if (!isValid())
			return false;
		long int_address;
		long start_address;
		long end_address;
		int_address = PRHelpers.addressToInt(ipAddress);
		if (int_address < 0L)
			int_address += 0x100000000L;
		start_address = ipStart;
		end_address = ipEnd;
		if (start_address < 0L)
			start_address += 0x100000000L;
		if (end_address < 0L)
			end_address += 0x100000000L;
		return int_address >= start_address && int_address <= end_address;
		UnknownHostException e;
		e;
		return false;
	}

	public String getDescription()
	{
		return new String(IpFilterManagerFactory.getSingleton().getDescription(descRef));
	}

	public void setDescription(String str)
	{
		descRef = IpFilterManagerFactory.getSingleton().addDescription(this, str.getBytes());
	}

	public String getStartIp()
	{
		return (flags & 8) <= 0 ? PRHelpers.intToAddress(ipStart) : "";
	}

	public long getStartIpLong()
	{
		if ((flags & 8) > 0)
			return -1L;
		long val = ipStart;
		if (val < 0L)
			val += 0x100000000L;
		return val;
	}

	public void setStartIp(String str)
	{
		if (str == null)
			throw new RuntimeException("Invalid start value - null not supported");
		if (str.equals(getStartIp()))
			return;
		flags &= 0xf7;
		try
		{
			ipStart = PRHelpers.addressToInt(str);
		}
		catch (UnknownHostException e)
		{
			flags |= 8;
		}
		if ((flags & 0x18) == 0)
			checkValid();
	}

	public String getEndIp()
	{
		return (flags & 0x10) <= 0 ? PRHelpers.intToAddress(ipEnd) : "";
	}

	public long getEndIpLong()
	{
		if ((flags & 0x10) > 0)
			return -1L;
		long val = ipEnd;
		if (val < 0L)
			val += 0x100000000L;
		return val;
	}

	public void setEndIp(String str)
	{
		if (str == null)
			throw new RuntimeException("Invalid end value - null not supported");
		if (str.equals(getEndIp()))
			return;
		flags &= 0xef;
		try
		{
			ipEnd = PRHelpers.addressToInt(str);
		}
		catch (UnknownHostException e)
		{
			flags |= 0x10;
		}
		if ((flags & 0x18) == 0)
			checkValid();
	}

	public String toString()
	{
		return (new StringBuilder()).append(getDescription()).append(" : ").append(getStartIp()).append(" - ").append(getEndIp()).toString();
	}

	public boolean isSessionOnly()
	{
		return (flags & 1) != 0;
	}

	public void setSessionOnly(boolean _sessionOnly)
	{
		if (_sessionOnly)
			flags |= 1;
		else
			flags &= 0xfe;
	}

	public int compareStartIpTo(IpRange other)
	{
		long l = getStartIpLong() - ((IpRangeImpl)other).getStartIpLong();
		if (l < 0L)
			return -1;
		return l <= 0L ? 0 : 1;
	}

	public int compareEndIpTo(IpRange other)
	{
		long l = getEndIpLong() - ((IpRangeImpl)other).getEndIpLong();
		if (l < 0L)
			return -1;
		return l <= 0L ? 0 : 1;
	}

	protected void setAddedToRangeList(boolean b)
	{
		if (b)
			flags |= 2;
		else
			flags &= 0xfd;
	}

	public boolean getAddedToRangeList()
	{
		return (flags & 2) != 0;
	}

	public int compareDescription(IpRange other)
	{
		return getDescription().compareTo(other.getDescription());
	}

	protected Object getDescRef()
	{
		return descRef;
	}

	protected void setDescRef(Object descRef)
	{
		this.descRef = descRef;
	}

	public long getMergedEndLong()
	{
		return merged_end >= 0 ? merged_end : (long)merged_end + 0x100000000L;
	}

	public IpRange[] getMergedEntries()
	{
		return my_merged_entries;
	}

	public void resetMergeInfo()
	{
		flags &= 0xfb;
		if ((flags & 0x10) == 0)
			merged_end = ipEnd;
	}

	public boolean getMerged()
	{
		return (flags & 4) != 0;
	}

	public void setMerged()
	{
		flags |= 4;
	}

	public void setMergedEnd(long endIpLong)
	{
		merged_end = (int)(endIpLong < 0x100000000L ? endIpLong : endIpLong - 0x100000000L);
	}

	public void addMergedEntry(IpRange e2)
	{
		if (my_merged_entries == null)
		{
			my_merged_entries = (new IpRange[] {
				e2
			});
		} else
		{
			IpRange x[] = new IpRange[my_merged_entries.length + 1];
			System.arraycopy(my_merged_entries, 0, x, 0, my_merged_entries.length);
			x[x.length - 1] = e2;
			my_merged_entries = x;
		}
	}
}

⌨️ 快捷键说明

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