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.

291 questions
0
votes
2 answers

BufferedInputStream says it is not available, but works anyway

Can someone explain to me why this works just fine with in.available()>0 commented out, but when I put it back in it breaks? mySocket = new Socket("blahblah", 12345); BufferedInputStream in = new…
Kalina
  • 5,504
  • 16
  • 64
  • 101
0
votes
2 answers

BufferOutputStream write zero byte when merge the file

I am trying merge n pieces of file become single file. But I got strange behavior on my function. The function are called for x times in n seconds. Let say I have 100 files which I will merge, every second I call 5 files and merger it. and in the…
0
votes
2 answers

inputstream.read has no response when downloading large image(size > 300K)

Hi guys. I have a problem when downloading large size images.It's very strange, while read bytes from stream always no response. My code is as follows, any suggestion is welcome. public class ImageTestActivity extends Activity { public static…
breeze
  • 53
  • 2
  • 8
0
votes
1 answer

unbuffered stream behaving like line buffered

i was reading about streams and found out that we could control streams by using setvbuf() function...it was written tat in line buffered mode stream sends the data to the file when a newline is encountered and in unbuffered there is no…
AvinashK
  • 3,309
  • 8
  • 43
  • 94
0
votes
1 answer

Issues with RXTX - Erronous amount of bytes being received

I'm having some difficulties with retrieving data from a microcontroller. I'm transferring data in chunks of exactly 2000 bytes, and have written a thread to handle these 2000 bytes before make a new call to send the next 2k bytes. For the most part…
user1240989
  • 619
  • 1
  • 6
  • 5
0
votes
1 answer

How to drop the buffer of inputstream with buffer?

Consider the InputStream with buffer,for example AudioInputStream (i.e.available() return >=0) The inputstream is reading a changing file (a file which is kept downloading from internet and the undownloaded part is packed with zeros). When it read…
Bear
  • 5,138
  • 5
  • 50
  • 80
-1
votes
1 answer

Write to BufferedReader from another class

I need a method to write to a BufferedReader input from another class. In class A I use BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); and str = stdin.readLine(); to get input from the user, which then takes this input,…
BetaLyte
  • 111
  • 10
-1
votes
1 answer

BufferedInputStream.mark() method not working as expected

Code : import java.io.*; public class BufferedInputStreamDemo { public static void main(String[] args) throws IOException { String phrase = "Hello World #This_Is_Comment# #This is not comment#"; byte[] bytes = phrase.getBytes(); …
Shiv Patel
  • 114
  • 7
-1
votes
2 answers

why DataOutputStream is preferred in Server Client program

Why DataInputStream/DataOutputStream is used or preferred over any other stream of java like BufferedInputStream/BufferedOutputStream , BufferedReader/BufferedWriter in Socket programming like Server Client program ? Please explain the difference…
-1
votes
1 answer

Why am i not able to print the whole character as i have entered it?

As an amateur java learner i was trying out different combinations of java file and I/O methods, as i tried out this code where i wanted to print whatever i entered into the file tom.txt through my code(i understand what i want could be easily done…
-1
votes
2 answers

How to use BufferedInputStream to read a large microsoft word document in Java 7?

Is it possible to use the solution to this question for Microsoft Word files that are large? In other words, will the following code work if I replace "file.txt" below with "file.doc" ? final InputStream in = new BufferedInputStream(new…
user1068636
  • 1,871
  • 7
  • 33
  • 57
-1
votes
1 answer

ByteBuffer vs BufferInputStream

Would a NIO ByteBuffer consistently offer a faster read performance than an IO BufferedStream? If so,what would the reason be (keeping aside the multi-threading capbilities of NIO). I read about minimized copying of the read data in the former…
IUnknown
  • 9,301
  • 15
  • 50
  • 76
-1
votes
1 answer

Need to improve performance in file unzipping from DB

I am getting zipped blob from db and using that blob in below way, Ex:- byte[] inputBlob = blobfile.getBytes(1, (int) blobfile.length()); After getting the blob, the way i got the zippedStream and passed it into another Class…
-1
votes
1 answer

Loading a file from Internal storage to InputStream same way as from Assets

I am successfully loading and using an PKCS12 file Cert.pfx from Assets like this: String certLocation = "certificates/Cert.pfx"; InputStream isCert = null; try { isCert = getAssets().open(certLocation); } catch (Exception e) { Log.d(TAG,…
-1
votes
2 answers

inconsistent BufferedInputStream read(byte[]) behaviour

My understanding of BufferedInputStream.read(byte[]) is that the read operation starts from pos, and reads until either the byte array is full or end of stream occurs. I am calling the readInt method below on a BufferedInputStream. public class…
gjr
  • 1
  • 1
1 2 3
19
20