java - Transforming FileInputStream into a stream that returns hex -
I need to supply data from a binary file as a hen string. I load this whole file into memory Converts it to hex string and fields the hex string as a byte array in the second component.
Now the problem is facing that this file is sometimes very large so I get an "out-of-memory exception." The component also accepts an input as input, so I thought I will wrap my file inputstream in another stream, which gives the file as hex string.
Although I'm not sure how to do this, and InputStream looks simple enough while subclassaging, I see it is prone to very different learning methods and with special cases. It would also be good if this wheel already exists and I do not have to reprint it.
Suggestions?
This is the basic idea
class HexInputStream FilterInputStream {spreads in HexInputStream (In InputStream) {super (in); } @ Override Public en Read (Byte [] Bref, Int Close, Int Lane) IOException throws {int b = super.read (); String hex = string Format ("% 02x", b); Buff [0 + off] = (byte) hex.chart at (0); Buff [1 + off] = (byte) hex. Chart at (1); Return 2; }} We create an InputStream
InputStream = new BufferedInputStream (New HexInputStream (New FileInputStream ("1.test")); Pass more components. Is on. Read we always read 1 byte and convert it to 2 hex characters.
There have been some attempts to get this idea to work really.
Comments
Post a Comment