📄 hexdumpwriter.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 java.io.*;
/**
* 16恑僟儞僾傪峴偆Writer僋儔僗<BR>
* 奐敪傪峴偭偰偄傞偲 晄堄偵偁傞僨乕僞傪16恑僟儞僾偟偨偔側傝傑偡丅
* 偙偺僋儔僗偼 偦偺傛偆側16恑僟儞僾傪峴偆僋儔僗偱偡丅
* 側偍 僟儞僾弌椡偦偺傕偺偼 亀柍憰忺亁 偱峴偄傑偡丅
*
* @author Tosiki IGA , Eiichirou Takahashi
*/
public class HexDumpWriter
extends Writer
{
protected static final boolean IS_DEBUG=false;
protected Writer writer=null;
protected int iSeparatorSpace=0;
/**
* 16恑僟儞僾傪峴偆僋儔僗偺僐儞僗僩儔僋僞
*
* @param Writer writer 楢寢偡傞尦偺Writer
*/
public HexDumpWriter(Writer writer)
{
this.writer=writer;
}
/**
* 1暥帤Writer偵彂偒崬傒傑偡丅
*
* @param int cWrite 彂偒崬傓暥帤
* @throws IOException 壗偐偟傜偺I/O椺奜
*/
public void write(int cWrite)
throws IOException
{
fillSeparatorSpace();
String str4th=Integer.toHexString((int)((cWrite>>12) & 0x0F));
String str3th=Integer.toHexString((int)(cWrite>>8) & 0x0F);
String str2th=Integer.toHexString((int)(cWrite>>4) & 0x0F);
String str1th=Integer.toHexString((int)cWrite & 0x0F);
writer.write(str4th+str3th+str2th+str1th);
iSeparatorSpace+=2;
if(IS_DEBUG)System.out.println("偆偘["+str4th+str3th+str2th+str1th+"]");
}
/**
* 壜帇壔僗儁乕僗傪杽傔傑偡丅
*
* @param int cWrite 彂偒崬傓暥帤
* @throws IOException 壗偐偟傜偺I/O椺奜
*/
protected final void fillSeparatorSpace()
throws IOException
{
for(;iSeparatorSpace>0;iSeparatorSpace--)
{
writer.write(' ');
}
}
/**
* 暥帤攝楍傪Writer傊彂偒崬傒傑偡丅<BR>
* 偨偩偟彂偒崬傑傟傞偺偼 梌偊傜傟偨暥帤楍偺16恑壔僟儞僾暥帤楍偱偡
*
* @param char cbuf[] 彂偒崬傒僶僢僼傽
* @param int off 彂偒崬傒僶僢僼傽偺僆僼僙僢僩
* @param int len 彂偒崬傒挿偝
* @throws IOException 壗偐偟傜偺I/O椺奜
*/
public final void write(char cbuf[], int off, int len)
throws IOException
{
int iTill=off+len;
for(int index=off;index<iTill;index++)
{
write(cbuf[index]);
}
}
/**
* 僶僀僩攝楍傪Writer傊彂偒崬傒傑偡丅<BR>
* 偙偺儊僜僢僪偼 Writer偲偄偆娤揰偐傜偼 偐側傝亀晛捠亁偱偼偁傝傑偣傫丅
*
* @param char cbuf[] 彂偒崬傒僶僢僼傽
* @param int off 彂偒崬傒僶僢僼傽偺僆僼僙僢僩
* @param int len 彂偒崬傒挿偝
* @throws IOException 壗偐偟傜偺I/O椺奜
*/
public final void write(byte buf[])
throws IOException
{
for(int index=0;index<buf.length;index++)
{
fillSeparatorSpace();
int iVal=buf[index];
if(iVal<0)
{
iVal+=256;
}
writer.write(Integer.toHexString(iVal));
iSeparatorSpace+=1;
}
}
/**
* Writer傪僼儔僢僔儏偟傑偡
*
* @throws IOException 壗偐偟傜偺I/O椺奜偺敪惗
*/
public final void flush()
throws IOException
{
if(writer!=null)
{
writer.flush();
}
}
/**
* Writer傪僋儘乕僘偟傑偡
*
* @throws IOException 壗偐偟傜偺I/O椺奜偺敪惗
*/
public final void close()
throws IOException
{
if(writer!=null)
{
writer.close();
writer=null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -