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

📄 wbxmlwriter.java

📁 Mofire的JAR压缩包
💻 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:   WbxmlWriter.java

package org.kxml.wap;

import java.io.*;
import java.util.Hashtable;
import java.util.Vector;
import org.kxml.PrefixMap;
import org.kxml.io.AbstractXmlWriter;
import org.kxml.io.State;

public class WbxmlWriter extends AbstractXmlWriter
{

	Hashtable stringTable;
	OutputStream out;
	ByteArrayOutputStream buf;
	ByteArrayOutputStream stringTableBuf;
	String pending;
	Vector attributes;
	Hashtable attrStartTable;
	Hashtable attrValueTable;
	Hashtable tagTable;

	public WbxmlWriter(OutputStream out)
		throws IOException
	{
		stringTable = new Hashtable();
		buf = new ByteArrayOutputStream();
		stringTableBuf = new ByteArrayOutputStream();
		attributes = new Vector();
		attrStartTable = new Hashtable();
		attrValueTable = new Hashtable();
		tagTable = new Hashtable();
		this.out = out;
		buf = new ByteArrayOutputStream();
		stringTableBuf = new ByteArrayOutputStream();
		out.write(1);
		out.write(1);
		out.write(4);
	}

	public void flush()
	{
	}

	public void close()
		throws IOException
	{
		writeInt(out, stringTableBuf.size());
		out.write(stringTableBuf.toByteArray());
		out.write(buf.toByteArray());
		out.flush();
	}

	public void checkPending(boolean degenerated)
		throws IOException
	{
		if (pending == null)
			return;
		int len = attributes.size();
		Integer idx = (Integer)tagTable.get(pending);
		if (idx == null)
		{
			buf.write(len != 0 ? degenerated ? 132 : 196 : ((int) (degenerated ? 4 : 68)));
			writeStrT(pending);
		} else
		{
			buf.write(len != 0 ? degenerated ? idx.intValue() | 0x80 : idx.intValue() | 0xc0 : degenerated ? idx.intValue() : idx.intValue() | 0x40);
		}
		for (int i = 0; i < len; i++)
		{
			idx = (Integer)attrStartTable.get(attributes.elementAt(i));
			if (idx == null)
			{
				buf.write(4);
				writeStrT((String)attributes.elementAt(i));
			} else
			{
				buf.write(idx.intValue());
			}
			idx = (Integer)attrValueTable.get(attributes.elementAt(++i));
			if (idx == null)
			{
				buf.write(3);
				writeStrI(buf, (String)attributes.elementAt(i));
			} else
			{
				buf.write(idx.intValue());
			}
		}

		if (len > 0)
			buf.write(1);
		pending = null;
		attributes.removeAllElements();
	}

	public void startTag(PrefixMap prefixMap, String name)
		throws IOException
	{
		super.current = new State(super.current, prefixMap, name);
		checkPending(false);
		pending = name;
	}

	public void attribute(String name, String value)
	{
		attributes.addElement(name);
		attributes.addElement(value);
	}

	public void write(char chars[], int start, int len)
		throws IOException
	{
		checkPending(false);
		buf.write(3);
		writeStrI(buf, new String(chars, start, len));
	}

	public void endTag()
		throws IOException
	{
		super.current = super.current.prev;
		if (pending != null)
			checkPending(true);
		else
			buf.write(1);
	}

	public void writeLegacy(int i, String s)
	{
	}

	static void writeInt(OutputStream out, int i)
		throws IOException
	{
		byte buf[] = new byte[5];
		int idx = 0;
		do
		{
			buf[idx++] = (byte)(i & 0x7f);
			i >>= 7;
		} while (i != 0);
		while (idx > 1) 
			out.write(buf[--idx] | 0x80);
		out.write(buf[0]);
	}

	static void writeStrI(OutputStream out, String s)
		throws IOException
	{
		for (int i = 0; i < s.length(); i++)
			out.write((byte)s.charAt(i));

		out.write(0);
	}

	void writeStrT(String s)
		throws IOException
	{
		Integer idx = (Integer)stringTable.get(s);
		if (idx == null)
		{
			idx = new Integer(stringTableBuf.size());
			stringTable.put(s, idx);
			writeStrI(stringTableBuf, s);
			stringTableBuf.flush();
		}
		writeInt(buf, idx.intValue());
	}

	public void setTagTable(int page, String tagTable[])
	{
		for (int i = 0; i < tagTable.length; i++)
			if (tagTable[i] != null)
			{
				Integer idx = new Integer(i + 5);
				this.tagTable.put(tagTable[i], idx);
			}

		if (page != 0)
			throw new RuntimeException("code pages curr. not supp.");
		else
			return;
	}

	public void setAttrStartTable(int page, String attrStartTable[])
	{
		for (int i = 0; i < attrStartTable.length; i++)
			if (attrStartTable[i] != null)
			{
				Integer idx = new Integer(i + 5);
				this.attrStartTable.put(attrStartTable[i], idx);
			}

		if (page != 0)
			throw new RuntimeException("code pages curr. not supp.");
		else
			return;
	}

	public void setAttrValueTable(int page, String attrValueTable[])
	{
		for (int i = 0; i < attrValueTable.length; i++)
			if (attrValueTable[i] != null)
			{
				Integer idx = new Integer(i + 133);
				this.attrValueTable.put(attrValueTable[i], idx);
			}

		if (page != 0)
			throw new RuntimeException("code pages curr. not supp.");
		else
			return;
	}
}

⌨️ 快捷键说明

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