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

📄 genericmessagedecoder.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:   GenericMessageDecoder.java

package org.gudy.azureus2.pluginsimpl.local.messaging;

import com.aelitis.azureus.core.networkmanager.Transport;
import com.aelitis.azureus.core.peermanager.messaging.Message;
import com.aelitis.azureus.core.peermanager.messaging.MessageStreamDecoder;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.core3.util.DirectByteBuffer;

// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.messaging:
//			GenericMessage

public class GenericMessageDecoder
	implements MessageStreamDecoder
{

	public static final int MAX_MESSAGE_LENGTH = 0x40000;
	private final ByteBuffer length_buffer = ByteBuffer.allocate(4);
	private final ByteBuffer buffers[];
	private final String msg_type;
	private final String msg_desc;
	private List messages;
	private int protocol_bytes_last_read;
	private int data_bytes_last_read;
	private volatile boolean destroyed;

	protected GenericMessageDecoder(String _msg_type, String _msg_desc)
	{
		buffers = (new ByteBuffer[] {
			length_buffer, null
		});
		messages = new ArrayList();
		protocol_bytes_last_read = 0;
		data_bytes_last_read = 0;
		msg_type = _msg_type;
		msg_desc = _msg_desc;
	}

	public int performStreamDecode(Transport transport, int max_bytes)
		throws IOException
	{
		protocol_bytes_last_read = 0;
		data_bytes_last_read = 0;
		long total_read;
		long bytes_read;
		for (total_read = 0L; total_read < (long)max_bytes; total_read += bytes_read)
		{
			int read_lim = (int)((long)max_bytes - total_read);
			ByteBuffer payload_buffer = buffers[1];
			int rem;
			int lim;
			if (payload_buffer == null)
			{
				rem = length_buffer.remaining();
				lim = length_buffer.limit();
				if (rem > read_lim)
					length_buffer.limit(length_buffer.position() + read_lim);
				bytes_read = transport.read(buffers, 0, 1);
				length_buffer.limit(lim);
				protocol_bytes_last_read += bytes_read;
				if (length_buffer.hasRemaining())
				{
					total_read += bytes_read;
					break;
				}
				length_buffer.flip();
				int size = length_buffer.getInt();
				if (size > 0x40000)
				{
					Debug.out("Message too large for generic payload");
					throw new IOException("message too large");
				}
				buffers[1] = ByteBuffer.allocate(size);
				length_buffer.flip();
				continue;
			}
			rem = payload_buffer.remaining();
			lim = payload_buffer.limit();
			if (rem > read_lim)
				payload_buffer.limit(payload_buffer.position() + read_lim);
			bytes_read = transport.read(buffers, 1, 1);
			payload_buffer.limit(lim);
			data_bytes_last_read += bytes_read;
			if (payload_buffer.hasRemaining())
			{
				total_read += bytes_read;
				break;
			}
			payload_buffer.flip();
			messages.add(new GenericMessage(msg_type, msg_desc, new DirectByteBuffer(payload_buffer), false));
			buffers[1] = null;
		}

		if (destroyed)
			throw new IOException("decoder has been destroyed");
		else
			return (int)total_read;
	}

	public Message[] removeDecodedMessages()
	{
		if (messages.isEmpty())
		{
			return null;
		} else
		{
			Message msgs[] = (Message[])(Message[])messages.toArray(new Message[messages.size()]);
			messages.clear();
			return msgs;
		}
	}

	public int getProtocolBytesDecoded()
	{
		return protocol_bytes_last_read;
	}

	public int getDataBytesDecoded()
	{
		return data_bytes_last_read;
	}

	public int getPercentDoneOfCurrentMessage()
	{
		return 0;
	}

	public void pauseDecoding()
	{
	}

	public void resumeDecoding()
	{
	}

	public ByteBuffer destroy()
	{
		destroyed = true;
		return null;
	}
}

⌨️ 快捷键说明

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