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

📄 updatejarpatcher.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:   UpdateJarPatcher.java

package org.gudy.azureus2.update;

import java.io.*;
import java.util.*;
import java.util.jar.*;
import org.gudy.azureus2.plugins.logging.LoggerChannel;

public class UpdateJarPatcher
{

	private static String MANIFEST_NAME = "META-INF/MANIFEST.MF";
	protected Map patch_entries;

	protected UpdateJarPatcher(InputStream input_file, InputStream patch_file, OutputStream output_file, LoggerChannel log)
		throws IOException
	{
		patch_entries = new HashMap();
		readPatchEntries(patch_file);
		JarInputStream jis = new JarInputStream(input_file);
		JarOutputStream jos = new JarOutputStream(output_file);
		boolean manifest_found = false;
		do
		{
			JarEntry is_entry = jis.getNextJarEntry();
			if (is_entry == null)
				break;
			if (!is_entry.isDirectory())
			{
				String name = is_entry.getName();
				if (name.equalsIgnoreCase(MANIFEST_NAME))
					manifest_found = true;
				InputStream eis = getPatch(name);
				if (eis != null)
					log.log((new StringBuilder()).append("patch - replace: ").append(name).toString());
				else
					eis = jis;
				JarEntry os_entry = new JarEntry(name);
				writeEntry(jos, os_entry, eis);
			}
		} while (true);
		InputStream eis;
		JarEntry os_entry;
		for (Iterator it = patch_entries.keySet().iterator(); it.hasNext(); writeEntry(jos, os_entry, eis))
		{
			String name = (String)it.next();
			if (name.equalsIgnoreCase(MANIFEST_NAME))
				manifest_found = true;
			log.log((new StringBuilder()).append("patch - add: ").append(name).toString());
			eis = (InputStream)patch_entries.get(name);
			os_entry = new JarEntry(name);
		}

		if (!manifest_found)
		{
			JarEntry entry = new JarEntry(MANIFEST_NAME);
			ByteArrayInputStream bais = new ByteArrayInputStream("Manifest-Version: 1.0\r\n\r\n".getBytes());
			writeEntry(jos, entry, bais);
		}
		jos.finish();
	}

	private static void writeEntry(JarOutputStream jos, JarEntry entry, InputStream data)
		throws IOException
	{
		jos.putNextEntry(entry);
		byte newBytes[] = new byte[4096];
		for (int size = data.read(newBytes); size != -1; size = data.read(newBytes))
			jos.write(newBytes, 0, size);

	}

	protected void readPatchEntries(InputStream is)
		throws IOException
	{
		JarInputStream jis = new JarInputStream(is);
		do
		{
			JarEntry ent = jis.getNextJarEntry();
			if (ent == null)
				break;
			if (!ent.isDirectory())
			{
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				byte buffer[] = new byte[8192];
				do
				{
					int l = jis.read(buffer);
					if (l <= 0)
						break;
					baos.write(buffer, 0, l);
				} while (true);
				patch_entries.put(ent.getName(), new ByteArrayInputStream(baos.toByteArray()));
			}
		} while (true);
	}

	public InputStream getPatch(String name)
	{
		return (InputStream)patch_entries.remove(name);
	}

}

⌨️ 快捷键说明

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