Questions tagged [bufferedinputstream]

An abstract mechanism for reading a data stream into a buffer, for improved reading performance

An BufferedInputStream is a wrapper around an InputStream, whereby the data being read is buffered locally. Buffering can be either fully-buffered or partially-buffered. Fully-buffered is where the entire contents of the InputStream is held locally in a variable. Partially-buffered is where a small portion of the stream data is held in a local variable, and as you read data from the buffer, those bytes are replaced with the next X bytes from the stream - ie the buffer overwrites itself as the data is consumed from it.

An InputStream is usually buffered to improve performance, as it allows data to be read from a network of file in large efficient chunks, rather than a number of smaller reads. This removes the overhead and performance impact of the multiple small reads. The downside, however, is that the buffer consumes some memory and has some CPU impact, but these downsides are usually very tiny, and are far outweighed by the benefits of buffering.

279 questions
9
votes
3 answers

Java Being Blocked By Antivirus Software (Specifically AVG)

I have a program that I've been working on that downloads files. Everything works perfectly, unless a user is using AVG. Oddly enough, it seems that in order to fix the issue AVG's "Email Protection" must be disabled; adding either my program or the…
Samusaaron3
  • 472
  • 1
  • 7
  • 17
9
votes
2 answers

Convert BufferedInputStream to String in Clojure

mock.request is returning the response :body as a BufferedInputStream. I need to print and compare this as a string. How do I convert it? When I try to pass response as a message to my assertion, I see a raw output, e.g. (is (= 200 (:status…
Petrus Theron
  • 25,051
  • 30
  • 137
  • 263
8
votes
2 answers

BufferedInputStream into byte[] to be send over a Socket to a Database

I have been looking around for an answer to this, but couldn't really find anything on it. Earlier today, I asked how I could make a File into a String through a byte array, and then back again, for retrieval later. What people told me, was that I…
OmniOwl
  • 4,893
  • 14
  • 52
  • 99
7
votes
2 answers

Java - Using DataInputStream with Sockets, buffered or not?

I'm writing a simple client/server application and I found that using DataInputStream to read data was very convenient because it allows you to chose what to read (without having to convert it yourself from bytes), but I'm wondering if it would be…
Anton
  • 258
  • 2
  • 6
7
votes
2 answers

Reading InputStream of NANOHTTPD gives Socket TimeOut Exception

I am trying to read the InputStream from IHTTPSession.getInputStream() using the following code but its gives Socket TimeOut Exception every time. private String readInStream(InputStream in){ StringBuffer outBuffer=new StringBuffer(); …
6
votes
4 answers

Get FileNotFoundException when initialising FileInputStream with File object

I am trying to initialise a FileInputStream object using a File object. I am getting a FileNotFound error on the line fis = new FileInputStream(file); This is strange since I have opened this file through the same method to do regex many times. My…
Ankur
  • 47,089
  • 107
  • 237
  • 309
6
votes
2 answers

BufferedInputStream and Blocking

I am using a BufferedInputStream to read from a socket. The BufferedInputStream reads as follows: socketInput.read(replyBuffer, 0, 7); It is instantiated by socketInput = new BufferedInputStream(mySocket.getInputStream()); mySocket is defined as…
user195488
6
votes
1 answer

InputStream won't close, or takes forever to

I'm attempting to download an external mp3 into internal storage. However, the files I'm attempting to download are big, so I'm trying to download them in 1MB chunks so that you can begin playing them while the rest is downloaded. Here's my stream…
Jason Robinson
  • 29,432
  • 18
  • 72
  • 128
6
votes
4 answers

How does BufferedReader read files from S3?

I have a very large file (several GB) in AWS S3, and I only need a small number of lines in the file which satisfy a certain condition. I don't want to load the entire file in-memory and then search for and print those few lines - the memory load…
6
votes
4 answers

How to clone an inputstream in java in minimal time

Can someone tell me how to clone an inputstream, taking as little creation time as possible? I need to clone an inputstream multiple times for multiple methods to process the IS. I've tried three ways and things don't work for one reason or…
Classified
  • 4,859
  • 15
  • 59
  • 89
5
votes
0 answers

Java InputStream + BufferedInputStream swallows exceptions

I have a problem where my program is not ending as expected when an exception is thrown. I have tracked it down to the combination of InputStream and BufferedInputStream swallowing the exceptions. The following code demonstrates the problem: import…
5
votes
1 answer

Why am I getting java.io.IOException: Mark has been invalidated?

I'm trying to download imags from a url and then decode them. The problem is that I don't know how large are they and if I decode them right away, the app crashes with too-big images. I'm doing the following and it works with most of the images but…
sergi
  • 929
  • 5
  • 14
  • 21
5
votes
0 answers

Should BufferedInputStream be used when fetching bitmap data using HttpURLConnection?

I've read that wrapping a BufferedInputStream around an input stream is only of benefit if you're reading the input stream in small chunks. Otherwise, using it may actually have adverse effects. What is the situation when the input stream is bitmap…
drmrbrewer
  • 8,355
  • 11
  • 60
  • 138
5
votes
2 answers

Seeking out the optimum size for BufferedInputStream in Java

I was profiling my code that was loading a binary file. The load time was something around 15 seconds. The majority of my load time was coming from the methods that were loading binary data. I had the following code to create my…
Brad
  • 8,805
  • 10
  • 39
  • 67
5
votes
1 answer

Java buffered base64 encoder for streams

I have lots of PDF files that I need to get its content encoded using base64. I have an Akka app which fetch the files as stream and distributes to many workers to encode these files and returns the string base64 for each file. I got a basic…
fforbeck
  • 120
  • 3
  • 11
1
2
3
18 19