download.java

来自「这是一个用jsp+Oracle开发的联系人客户关系管理系统!」· Java 代码 · 共 78 行

JAVA
78
字号
import java.io.*;
import net.jxta.pipe.*;
import net.jxta.share.*;
import net.jxta.share.client.*;

public class Download
{
	private PeerGroup netPeerGroup = null;
	private ListContentRequest request = null;
	private String searchString = null;

	public Download(String subStr)
	{
		searchString = subStr;
	}

	public void run()
	{
		try
		{
			netPeerGroup = PeerGroupFactory.newNetPeetGroup();
			request = new MyListRequest(netPeerGroup,searchString);
			request.activateRequest();
		}catch(Exception e)
		{
			System.out.println(e.getMessage());
			System.exit(-1);
		}
	}

	public static void main(String args[])
	{
		Download myShare = new Download("java");
		myShare.run();
	}


	class MyContentRequest extends GetContentRequest
	{
		public MyContentRequest(PeerGroup group,String subString)
		{
			super(group,subString);
		}

		public void notifyDone()
		{
			System.out.println(getFile()+"downloaded");
		}

		public void notifyFailure()
		{
			System.out.println(getFile()+"download failed");
		}

		public void notifyUpdate(int percent)
		{
			System.out.println(getFile()+"downloaded "+percent+"%");
		}
	};

	class MyListRequest extends ListContentRequest
	{
		PeerGroup pggroup = null;
		public MyListRequest(PeerGroup group,String subString)
		{
			super(group,subString);
			pggroup = group;
		}

		public void notifyMoreResults()
		{
			ContentAdvertisement[] res = getResults();
			for(int i=0;i<res.length;i++)
				System.out.println(res[i].getName());
			new MyContentRequest(pggroup,res[0],new File("download.txt"));
		}
	};
}

⌨️ 快捷键说明

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