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

📄 loadproxies.java

📁 基于java的电子邮件群发系统,基于java的电子邮件群发系统
💻 JAVA
字号:
package com.cwq.batchmail.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.util.HashSet;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;

public class LoadProxies {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
	private int totalProxiesCount = 0;
	
	public Vector<Proxy> load(File f) throws IOException {
		
		Set<Proxy> proxies = new HashSet<Proxy>();
		
		BufferedReader in = new BufferedReader(new java.io.FileReader(f));
		String line = null;
		
		StringTokenizer tokener = null;
		while ((line = in.readLine()) != null) {
			line = line.trim();
			if(line.length() > 0) {
				try {
					tokener = new StringTokenizer(line, ":;, ", false);
					proxies.add(new Proxy(
							Proxy.Type.SOCKS,
							new java.net.InetSocketAddress(
									tokener.nextToken(),
									Integer.parseInt(tokener.nextToken())
							)
							) {
						public String toString() {
							return this.address().toString();
						}
					});
					totalProxiesCount ++;
				} catch(NoSuchElementException ex) {
				} catch(NumberFormatException ex) {
				} catch(Exception ex) {
				}
			}
		}
		
		try { in.close(); } catch(Exception ex) {}
		
		return new Vector<Proxy>(proxies);
	}
	
	public Vector<Proxy> clean(File f) throws IOException {
		Vector<Proxy> vs = load(f);
		save(f, vs);
		return vs;
	}
	
	static void save(File f, Vector<Proxy> emails) throws IOException {
		//System.out.println(emails.size());
		BufferedWriter writer = new BufferedWriter(new FileWriter(f));
		final int BUFFER_SIZE = 100;
		int count = 0;
		for(Iterator<Proxy> it = emails.iterator(); it.hasNext(); ) {
			InetSocketAddress p = (InetSocketAddress) (it.next().address());
			//System.out.println(p.toString());
			writer.write(p.toString().replaceFirst("/", "").concat("\r\n"));
			//writer.write(p.getHostName().concat(" " + p.getPort()).concat("\r\n"));
			if(count ++ > BUFFER_SIZE)
				writer.flush();
		}
		writer.flush();
		try { writer.close(); } catch(Exception ex) {}
	}

	public int getTotalProxiesCount() {
		return totalProxiesCount;
	}

}

⌨️ 快捷键说明

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