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

📄 hexdumptest.java

📁 用免疫遗传算法解决TSP问题
💻 JAVA
字号:
/**
 * IgaLib -> String
 * Copyright (C) 2001  Tosiki IGA , IgaLib project member
 *   (http://homepage2.nifty.com/igat/igapyon/index.html)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package jp.ne.nifty.iga.tosiki.string;

import junit.framework.TestCase;
import java.io.*;

/**
 * 16恑妏曄姺僋儔僗孮傪僥僗僩偡傞僋儔僗偱偡丅
 * JUnit傪棙梡偟偰僥僗僩傪幚巤偡傞偨傔偵懚嵼偡傞僋儔僗偱偡丅<BR>
 * 偙偺僋儔僗帺恎傪壗偐偺梡搑偵棙梡偡傞偙偲偼柍偄偱偟傚偆丅
 *
 * @author Tosiki IGA
 */
public class HexDumpTest
	extends TestCase
{
	public HexDumpTest(String name)
	{
		super(name);
	}

	public static final void main(String[] args)
	{
		junit.textui.TestRunner.run(HexDumpTest.class);
	}

	public void testHexDumpWriter()
		throws IOException
	{
		{
			StringWriter writerBuf=new StringWriter();
			HexDumpWriter writer=new HexDumpWriter(writerBuf);
			writer.write("偁偄偆");
			writer.flush();
			writer.close();
			assertEquals(writerBuf.toString(),"3042  3044  3046");
		}

		{
			StringWriter writerBuf=new StringWriter();
			HexDumpWriter writer=new HexDumpWriter(writerBuf);
			writer.write("偁偄偆".getBytes("SJIS"));
			writer.flush();
			writer.close();
			assertEquals(writerBuf.toString(),"82 a0 82 a2 82 a4");
		}
	}

	public void testHexDumpUtil()
		throws IOException
	{
		assertEquals("3042  3044  3046",HexDumpUtil.toString("偁偄偆"));
		assertEquals("82 a0 82 a2 82 a4",HexDumpUtil.toString("偁偄偆".getBytes("SJIS")));

		assertEquals("672c  65e5  306f  6674  5929  306a  308a  3002  96a3  306e  5ba2  306f  826f  304f  67ff  98df  3046  5ba2  3060  3002",HexDumpUtil.toString("杮擔偼惏揤側傝丅椬偺媞偼椙偔奰怘偆媞偩丅"));

		assertEquals("0041  0042  0043  0044  0045  002d  0058  0059  005a",HexDumpUtil.toString("ABCDE-XYZ"));
	}

	public void testTinySaxWriter()
		throws IOException
	{
		TinySaxWriter writer=new TinySaxWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("./sample/test/TinySaxWriterTest.xml"))));
		writer.startDocument();
		writer.startElement("person_list",null);

		for(int index=0;index<10;index++)
		{
			java.util.ArrayList list=new java.util.ArrayList();
			list.add(new String[]{"id","code"+index});
			writer.startElement("person",list);

			{
				writer.startElement("name",null);

				writer.startElement("family",null);
				writer.characters("柤帤");
				writer.endElement("family");

				writer.startElement("given",null);
				writer.characters("柤慜");
				writer.endElement("given");

				writer.endElement("name");

				writer.startElement("email",null);
				writer.characters("mailto:儊乕儖傾僪儗僗"+index);
				writer.endElement("email");

				list=new java.util.ArrayList();
				list.add(new String[]{"subdir","dir"+index});
				writer.startElement("directory",list);
				writer.endElement("directory");
			}


			writer.endElement("person");
		}

		writer.endElement("person_list");
		writer.endDocument();
		writer.flush();
		writer.close();
	}
}


⌨️ 快捷键说明

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