Using Streams and StreamSupplier: forEach closes StreamSupplier instead of instance of stream

I am making a obj file loader for an engine that I’m writing and I am trying to use Streams to load vertex index, uvcoord, and normals from this file. The way I intended to do this was to create a new …

Java InputStream wrapper which limits the nuber of read bytes

We need to have a process “peek” into the incoming InputStream and using a JSON streaming parser and ensure then no more then XXX bytes are read (i.e. we NEVER want to read past byte XX). …

Can you access files on the remote FTP server with RandomAccessFile?

I’m trying to read the file on the FTP remote-server using Apache Commons Net library. retrieveFileStream returns InputStream and put it in BufferedReader. But, I want to use RandomAccessFile (to …

BufferInputStream vs ByteArrayInputStream

Here are three ways to read an entire file into memory before processing it: Approach A: fis = new FileInputStream(file); bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); …

Determine the size of an InputStream

My current situation is: I have to read a file and put the contents into InputStream. Afterwards I need to place the contents of the InputStream into a byte array which requires (as far as I know) the …

How do I read / convert an InputStream into a String in Java?

If you have a java.io.InputStream object, how should you process that object and produce a String? Suppose I have an InputStream that contains text data, and I want to convert it to a String, so for …