【初心者】Java質問・相談スレ23【大歓迎】
■ このスレッドは過去ログ倉庫に格納されています
04051/2: 改行多すぎ
NGNGBase64 版は見せれんが、こんなのどうだ? ASCII 16 進数で入出力する
フィルタストリーム。
public class HexOutputStream extends FilterOutputStream{
public HexOutputStream(OutputStream out){ super(out); }
public void write(int ch) throws IOException{
out.write(Character.forDigit((ch >> 4) & 0x0F, 16));
out.write(Character.forDigit((ch >> 0) & 0x0F, 16));
}
}
public class HexInputStream extends FilterInputStream{
public HexInputStream(InputStream in){ super(in); }
public int read() throws IOException{
int ch1 = in.read(); if(ch1 < 0) return ch1;
int ch2 = in.read(); if(ch2 < 0) return ch2;
return ((Character.digit((char)ch1, 16) & 0x0F) << 4)
|| ((Character.digit((char)ch2, 16) & 0x0F) << 0);
}
}
■ このスレッドは過去ログ倉庫に格納されています