Using Java IO seeking bytearrayinputstream
How to find (change location) bytearrayinputstream (Java. IO)? This is obvious, but I can't seem to find a way anywhere (marking / resetting is not enough, I need to set the location anywhere on the InputStream)
If you can't use Java IO, you must switch to Java NiO and ByteBuffer, how to get is similar to using Java NiO packaging bytearrayoutputstream's dataoutputstream and similar things? I didn't find any type of auto - resizing buffer
Editor: I've found a way to do what I'm trying to do, but it's a bit confusing ImageIO. Createimageinputstream create an imageinputstream, which is exactly what I want (you can find and read primitives) However, using bytearrayinputstream returns a filecacheimageinputstream, which basically means that it copies the byte array into a file to find it
This is my first attempt to use Java IO classes, which is completely negative It lacks some basic (IMO) functions. It has many methods to do the same thing (for example, reading primitives from files, using RandomAccessFile, datainputstream, FileInputStream, fileimageinputstream, filechannel, ByteBuffer, and even more)
Solution
You can use reset () / skip () I can't say it's the best API in the world, but it should work:
public void seek(ByteArrayInputStream input,int position) throws IOException { input.reset(); input.skip(position); }
Of course, suppose no one calls it mark ()