Questions tagged [inputstreamreader]

206 questions
45
votes
7 answers

What is the difference between Java's BufferedReader and InputStreamReader classes?

What is the difference between Java's BufferedReader and InputStreamReader classes?
Ajay Yadav
  • 1,483
  • 4
  • 14
  • 26
31
votes
8 answers

Read all lines with BufferedReader

I want to type a multiple line text into the console using a BufferedReader and when I hit "Enter" to find the sum of the length of the whole text. The problem is that it seems I'm getting into an infinite loop and when I press "Enter" the program…
deadpixels
  • 595
  • 1
  • 8
  • 20
14
votes
3 answers

How do an InputStream, InputStreamReader and BufferedReader work together in Java?

I am studying Android development (I'm a beginner in programming in general) and learning about HTTP networking and saw this code in the lesson: private String readFromStream(InputStream inputStream) throws IOException { StringBuilder output = new…
schv09
  • 895
  • 9
  • 14
11
votes
6 answers

InputStreamReader buffering issue

I am reading data from a file that has, unfortunately, two types of character encoding. There is a header and a body. The header is always in ASCII and defines the character set that the body is encoded in. The header is not fixed length and must…
Mike Q
  • 21,350
  • 19
  • 80
  • 124
11
votes
2 answers

Closing BufferedReader and InputStreamReader

This piece of code is creating memory leak issues cause of BufferedReader and InputStreamReader which I think might be happening cause of some exceptions. How should I change it? try{ URL url = new URL(sMyUrl); BufferedReader in = new…
Pit Digger
  • 8,992
  • 23
  • 70
  • 120
7
votes
2 answers

Read both text and binary data from InputStream

I am trying to read data from a binary stream, portions of which should be parsed as UTF-8. Using the InputStream directly for the binary data and an InputStreamReader on top of it for the UTF-8 text does not work as the reader will read ahead and…
tajmahal
  • 1,563
  • 3
  • 15
  • 29
7
votes
3 answers

problem using base64 encoder and InputStreamReader

I have some CLOB columns in a database that I need to put Base64 encoded binary files in. These files can be large, so I need to stream them, I can't read the whole thing in at once. I'm using org.apache.commons.codec.binary.Base64InputStream to do…
karoberts
  • 9,518
  • 3
  • 38
  • 38
7
votes
6 answers

DataInputStream vs InputStreamReader, trying to conceptually understand the two

As I tentatively understand it at the moment: DataInputStream is an InputStream subclass, hence it reads and writes bytes. If you are reading bytes and you know they are all going to be ints or some other primitive data type, then you can read those…
ross studtman
  • 916
  • 8
  • 19
7
votes
2 answers

BufferedReader in a multi-core environment

I have 8 files. Each one of them is about 1.7 GB. I'm reading those files into a byte array and that operation is fast enough. Each file is then read as follow: BufferedReader br=new BufferedReader(new InputStreamReader(new…
DotNet
  • 667
  • 2
  • 6
  • 22
7
votes
2 answers

How make InputStreamReader fail on invalid data for encoding?

I have some bytes which should be UTF-8 encoded, but which may contain a text is ISO8859-1 encoding, if the user somehow didn't manage to use his text editor the right way. I read the file with an InputStreamReader: InputStreamReader reader = new…
Daniel
  • 25,883
  • 17
  • 87
  • 130
5
votes
2 answers

Readline is too slow - Anything Faster?

I am reading in from a stream using a BufferedReader and InputStreamReader to create one long string that gets created from the readers. It gets up to over 100,000 lines and then throws a 500 error (call failed on the server). I am not sure what…
butler_alfred
  • 73
  • 2
  • 10
5
votes
6 answers

Java inputStreamReader Charset

I want to ping a target IP address and receive a response. To achieve this, I'm using windows command line in Java with runtime.exec method and process class. I'm getting the response using inputStreamReader. My default charset is windows-1254, it's…
Maozturk
  • 324
  • 1
  • 4
  • 18
4
votes
1 answer

Why does InputStreamReader read() block instead of returning -1?

I'm using java's InputStreamReader read() function. When I reach the end of the input stream i'm supposed to get in to my int variable the value of -1, but instead it goes to block. Why don't I get a -1 at the end of the input stream? (i've debugged…
Guy
  • 41
  • 2
4
votes
5 answers

Java BufferedReader.readLine() not waiting for EOL?

Sorry if I'm missing something obvious here...but please take a look at this code snippet: String readString; String writeString = "O hai world."; BufferedReader br = new BufferedReader( new InputStreamReader( new…
4
votes
2 answers

java.io dilemma

The classes java.io.Reader and java.io.InputStreamReader both have read methods with the exact same signature public int read(char[] charbuf, int offset, int length) throws IOException Now according to the java documentation the class…
Surender Thakran
  • 3,560
  • 9
  • 39
  • 76
1
2 3
13 14