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

📄 diskmanagerpieceimpl.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:   DiskManagerPieceImpl.java

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

import org.gudy.azureus2.core3.disk.DiskManager;
import org.gudy.azureus2.core3.disk.DiskManagerPiece;
import org.gudy.azureus2.core3.disk.impl.piecemapper.DMPieceList;
import org.gudy.azureus2.core3.disk.impl.piecemapper.DMPieceMapEntry;

// Referenced classes of package org.gudy.azureus2.core3.disk.impl:
//			DiskManagerFileInfoImpl, DiskManagerHelper

public class DiskManagerPieceImpl
	implements DiskManagerPiece
{

	private static final byte PIECE_STATUS_NEEDED = 1;
	private static final byte PIECE_STATUS_WRITTEN = 32;
	private static final byte PIECE_STATUS_CHECKING = 64;
	private static final byte PIECE_STATUS_MASK_DOWNLOADABLE = 97;
	private static final byte PIECE_STATUS_MASK_NEEDS_CHECK = 96;
	private final DiskManagerHelper diskManager;
	private final int pieceNumber;
	private final short nbBlocks;
	protected volatile boolean written[];
	private byte statusFlags;
	private short read_count;
	private boolean done;

	public DiskManagerPieceImpl(DiskManagerHelper _disk_manager, int pieceIndex, int length)
	{
		diskManager = _disk_manager;
		pieceNumber = pieceIndex;
		nbBlocks = (short)(((length + 16384) - 1) / 16384);
		statusFlags = 1;
	}

	public DiskManager getManager()
	{
		return diskManager;
	}

	public int getPieceNumber()
	{
		return pieceNumber;
	}

	public int getLength()
	{
		return diskManager.getPieceLength(pieceNumber);
	}

	public int getNbBlocks()
	{
		return nbBlocks;
	}

	public short getReadCount()
	{
		return read_count;
	}

	public void setReadCount(short c)
	{
		read_count = c;
	}

	public int getBlockSize(int blockNumber)
	{
		if (blockNumber == nbBlocks - 1)
		{
			int len = getLength() % 16384;
			if (len != 0)
				return len;
		}
		return 16384;
	}

	public boolean isSkipped()
	{
		DMPieceList pieceList = diskManager.getPieceList(pieceNumber);
		for (int i = 0; i < pieceList.size(); i++)
			if (!pieceList.get(i).getFile().isSkipped())
				return false;

		return true;
	}

	public boolean isNeeded()
	{
		return (statusFlags & 1) != 0;
	}

	public boolean calcNeeded()
	{
		boolean filesNeeded = false;
		DMPieceList pieceList = diskManager.getPieceList(pieceNumber);
		for (int i = 0; i < pieceList.size(); i++)
		{
			DiskManagerFileInfoImpl file = pieceList.get(i).getFile();
			long fileLength = file.getLength();
			filesNeeded |= fileLength > 0L && file.getDownloaded() < fileLength && !file.isSkipped();
		}

		if (filesNeeded)
		{
			statusFlags |= 1;
			return true;
		} else
		{
			statusFlags &= 0xfe;
			return false;
		}
	}

	public void clearNeeded()
	{
		statusFlags &= 0xfe;
	}

	public void setNeeded()
	{
		statusFlags |= 1;
	}

	public void setNeeded(boolean b)
	{
		if (b)
			statusFlags |= 1;
		else
			statusFlags &= 0xfe;
	}

	public boolean isWritten()
	{
		return (statusFlags & 0x20) != 0;
	}

	public boolean[] getWritten()
	{
		return written;
	}

	public boolean isWritten(int blockNumber)
	{
		if (done)
			return true;
		boolean writtenRef[] = written;
		if (writtenRef == null)
			return false;
		else
			return writtenRef[blockNumber];
	}

	public int getNbWritten()
	{
		if (done)
			return nbBlocks;
		boolean writtenRef[] = written;
		if (writtenRef == null)
			return 0;
		int res = 0;
		for (int i = 0; i < nbBlocks; i++)
			if (writtenRef[i])
				res++;

		return res;
	}

	public void setWritten(int blockNumber)
	{
		if (written == null)
			written = new boolean[nbBlocks];
		boolean written_ref[] = written;
		written_ref[blockNumber] = true;
		for (int i = 0; i < nbBlocks; i++)
			if (!written_ref[i])
				return;

		statusFlags |= 0x20;
	}

	public boolean isChecking()
	{
		return (statusFlags & 0x40) != 0;
	}

	public void setChecking()
	{
		statusFlags |= 0x40;
	}

	public boolean isNeedsCheck()
	{
		return !done && (statusFlags & 0x60) == 32;
	}

	public boolean calcDone()
	{
		return done;
	}

	public boolean isDone()
	{
		return done;
	}

	public void setDone(boolean b)
	{
		if (b != done)
			diskManager.setPieceDone(this, b);
	}

	public void setDoneSupport(boolean b)
	{
		done = b;
		if (done)
			written = null;
	}

	public void setDownloadable()
	{
		setDone(false);
		statusFlags &= 0x9e;
		calcNeeded();
	}

	public boolean isDownloadable()
	{
		return !done && (statusFlags & 0x61) == 1;
	}

	public boolean isInteresting()
	{
		return !done && (statusFlags & 1) != 0;
	}

	public void reset()
	{
		setDownloadable();
		written = null;
	}

	public void reDownloadBlock(int blockNumber)
	{
		boolean written_ref[] = written;
		if (written_ref != null)
		{
			written_ref[blockNumber] = false;
			setDownloadable();
		}
	}

	public String getString()
	{
		String text = "";
		text = (new StringBuilder()).append(text).append(isNeeded() ? "needed," : "").toString();
		text = (new StringBuilder()).append(text).append(isDone() ? "done," : "").toString();
		if (!isDone())
		{
			text = (new StringBuilder()).append(text).append(isDownloadable() ? "downable," : "").toString();
			text = (new StringBuilder()).append(text).append(isWritten() ? "written" : (new StringBuilder()).append("written ").append(getNbWritten()).toString()).append(",").toString();
			text = (new StringBuilder()).append(text).append(isChecking() ? "checking" : "").toString();
		}
		if (text.endsWith(","))
			text = text.substring(0, text.length() - 1);
		return text;
	}
}

⌨️ 快捷键说明

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