📄 xuxmlwriter.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: XUXmlWriter.java
package org.gudy.azureus2.core3.xml.util;
import java.io.*;
import java.util.*;
import org.gudy.azureus2.core3.util.ByteFormatter;
import org.gudy.azureus2.core3.util.Debug;
public class XUXmlWriter
{
private static final int INDENT_AMOUNT = 4;
private String current_indent_string;
private PrintWriter writer;
private boolean generic_simple;
protected XUXmlWriter()
{
resetIndent();
}
protected XUXmlWriter(OutputStream _output_stream)
{
setOutputStream(_output_stream);
resetIndent();
}
protected void setOutputStream(OutputStream _output_stream)
{
try
{
writer = new PrintWriter(new OutputStreamWriter(_output_stream, "UTF8"));
}
catch (UnsupportedEncodingException e)
{
Debug.printStackTrace(e);
writer = new PrintWriter(_output_stream);
}
}
protected void setOutputWriter(Writer _writer)
{
if (_writer instanceof PrintWriter)
writer = (PrintWriter)_writer;
else
writer = new PrintWriter(_writer);
}
protected void setGenericSimple(boolean simple)
{
generic_simple = simple;
}
protected void writeTag(String tag, String content)
{
writeLineRaw((new StringBuilder()).append("<").append(tag).append(">").append(escapeXML(content)).append("</").append(tag).append(">").toString());
}
protected void writeTag(String tag, long content)
{
writeLineRaw((new StringBuilder()).append("<").append(tag).append(">").append(content).append("</").append(tag).append(">").toString());
}
protected void writeTag(String tag, boolean content)
{
writeLineRaw((new StringBuilder()).append("<").append(tag).append(">").append(content ? "YES" : "NO").append("</").append(tag).append(">").toString());
}
protected void writeLineRaw(String str)
{
writer.println((new StringBuilder()).append(current_indent_string).append(str).toString());
}
protected void writeLineEscaped(String str)
{
writer.println((new StringBuilder()).append(current_indent_string).append(escapeXML(str)).toString());
}
protected void resetIndent()
{
current_indent_string = "";
}
protected void indent()
{
int i = 0;
_L2:
if (i >= 4)
break; /* Loop/switch isn't completed */
new StringBuilder();
this;
JVM INSTR dup_x1 ;
current_indent_string;
append();
" ";
append();
toString();
current_indent_string;
i++;
if (true) goto _L2; else goto _L1
_L1:
}
protected void exdent()
{
if (current_indent_string.length() >= 4)
current_indent_string = current_indent_string.substring(0, current_indent_string.length() - 4);
else
current_indent_string = "";
}
public static String escapeXML(String str)
{
if (str == null)
{
return "";
} else
{
str = str.replaceAll("&", "&");
str = str.replaceAll(">", ">");
str = str.replaceAll("<", "<");
str = str.replaceAll("\"", """);
str = str.replaceAll("'", "'");
str = str.replaceAll("--", "--");
return str;
}
}
public static String unescapeXML(String str)
{
if (str == null)
{
return "";
} else
{
str = str.replaceAll(">", ">");
str = str.replaceAll("<", "<");
str = str.replaceAll(""", "\"");
str = str.replaceAll("'", "'");
str = str.replaceAll("--", "--");
str = str.replaceAll("&", "&");
return str;
}
}
protected void flushOutputStream()
{
if (writer != null)
writer.flush();
}
protected void closeOutputStream()
{
if (writer != null)
{
writer.flush();
writer.close();
writer = null;
}
}
protected void writeGenericMapEntry(String name, Object value)
{
if (!generic_simple)
break MISSING_BLOCK_LABEL_101;
name = name.replace(' ', '_').toUpperCase();
writeLineRaw((new StringBuilder()).append("<").append(name).append(">").toString());
indent();
writeGeneric(value);
exdent();
break MISSING_BLOCK_LABEL_70;
Exception exception;
exception;
exdent();
throw exception;
writeLineRaw((new StringBuilder()).append("</").append(name).append(">").toString());
break MISSING_BLOCK_LABEL_163;
writeLineRaw((new StringBuilder()).append("<KEY name=\"").append(escapeXML(name)).append("\">").toString());
indent();
writeGeneric(value);
exdent();
break MISSING_BLOCK_LABEL_157;
Exception exception1;
exception1;
exdent();
throw exception1;
writeLineRaw("</KEY>");
}
protected void writeGeneric(Object obj)
{
if (obj instanceof Map)
writeGeneric((Map)obj);
else
if (obj instanceof List)
writeGeneric((List)obj);
else
if (obj instanceof byte[])
writeGeneric((byte[])(byte[])obj);
else
writeGeneric((Long)obj);
}
protected void writeGeneric(Map map)
{
writeLineRaw("<MAP>");
indent();
String key;
for (Iterator it = map.keySet().iterator(); it.hasNext(); writeGenericMapEntry(key, map.get(key)))
key = (String)it.next();
exdent();
break MISSING_BLOCK_LABEL_72;
Exception exception;
exception;
exdent();
throw exception;
writeLineRaw("</MAP>");
return;
}
protected void writeGeneric(List list)
{
writeLineRaw("<LIST>");
indent();
for (int i = 0; i < list.size(); i++)
writeGeneric(list.get(i));
exdent();
break MISSING_BLOCK_LABEL_53;
Exception exception;
exception;
exdent();
throw exception;
writeLineRaw("</LIST>");
return;
}
protected void writeGeneric(byte bytes[])
{
if (generic_simple)
try
{
writeLineRaw(escapeXML(new String(bytes, "UTF-8")));
}
catch (Throwable e)
{
e.printStackTrace();
}
else
writeTag("BYTES", encodeBytes(bytes));
}
protected void writeGeneric(Long l)
{
if (generic_simple)
writeLineRaw(l.toString());
else
writeTag("LONG", (new StringBuilder()).append("").append(l).toString());
}
protected void writeTag(String tag, byte content[])
{
writeLineRaw((new StringBuilder()).append("<").append(tag).append(">").append(encodeBytes(content)).append("</").append(tag).append(">").toString());
}
protected void writeLocalisableTag(String tag, byte content[])
{
boolean use_bytes = true;
String utf_string = null;
try
{
utf_string = new String(content, "UTF8");
if (Arrays.equals(content, utf_string.getBytes("UTF8")))
use_bytes = false;
}
catch (UnsupportedEncodingException e) { }
writeLineRaw((new StringBuilder()).append("<").append(tag).append(" encoding=\"").append(use_bytes ? "bytes" : "utf8").append("\">").append(use_bytes ? encodeBytes(content) : escapeXML(utf_string)).append("</").append(tag).append(">").toString());
}
protected String encodeBytes(byte bytes[])
{
String data = ByteFormatter.nicePrint(bytes, true);
return data;
}
protected String getUTF(byte bytes[])
{
return new String(bytes, "UTF8");
UnsupportedEncodingException e;
e;
Debug.printStackTrace(e);
return "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -