Questions tagged [datainputstream]

A DataInputStream lets an application read primitive Java data types from an underlying input stream in a machine-independent way.

The DataInputStream class enables you to read Java primitives from InputStream's instead of only bytes. Wrap an InputStream in a DataInputStream and then you can read primitives from it. DataInputStreams represent Unicode strings in a format that is a slight modification of UTF-8.

339 questions
4
votes
1 answer

How to write and read the byte array to DataInput and DataOutput Stream

Hbase acts as a source and sink for my Map reduce job. I have written my custom writable class called (vector writable) and it has two fields in it. private DoubleVector vector; // It is a Double Array private byte[] rowKey; // The row key of…
yesh
  • 2,052
  • 4
  • 28
  • 51
4
votes
3 answers

"available" of DataInputStream from Socket

I have this code on the client side : DataInputStream dis = new DataInputStream(socketChannel.socket().getInputStream()); while(dis.available()){ SomeOtherClass.method(dis); } But available() keeps returning 0, although there is readable data…
uahakan
  • 576
  • 1
  • 6
  • 23
4
votes
2 answers

Getting byte arrays using TCP connections

I was using UDP to send/receive data but I now want to switch to TCP to avoid packet loss. I've read several tutorials on TCP and noticed that instead of using DatagramPacket like UDP, TCP uses InputStream/OutputStream. How do we get the byte[]…
Dao Lam
  • 2,837
  • 11
  • 38
  • 44
3
votes
4 answers

Sockets and DataInputStream

I am trying to understand this snippet of code DataInputStream stream = new DataInputStream( new ByteArrayInputStream(messageBuffer)); int messageLength = stream.readInt(); char recordType …
ziggy
  • 15,677
  • 67
  • 194
  • 287
3
votes
3 answers

Reading from a URL Connection Java

I'm trying to read html code from a URL Connection. In one case the html file I'm trying to read includes 5 line breaks before the actual doc type declaration. In this case the input reader throws an exception for EOF. URL pageUrl = new URL( …
Penny
  • 31
  • 1
  • 1
  • 3
3
votes
2 answers

Reading data from binary file (Java)?

For a class I'm working on, I have to create a program that writes binary data to a file (based on user input) and then reads it to the console. This is done with two separate programs, one that processes data and one that gets user input. Whenever…
Becca
  • 35
  • 5
3
votes
1 answer

DataInputStream and UTF-8

I'm kind of a new programmer, and I'm having a couple of problems with the code I'm handling. Basically what the code does is receive a form from another JSP, read the bytes, parse the data, and submit the results to SalesForce, using…
jorgemoya
  • 55
  • 1
  • 2
  • 7
3
votes
2 answers

EOFException DataInputStream using readUTF

I ve coded a simple Server that Listen for client and when the client is connected it opens a Datainputstream that read all the data sent from client( my client wirte UTF data). This is the ServerCode: @Override public void run() { // TODO…
Alessio Trecani
  • 713
  • 2
  • 10
  • 25
3
votes
2 answers

java indexOf returns -1 when it's supposed to return a positive number

I'm new to Network programming and I never used Java for network programming before. I'm writing a server using Java and I have some problem processing message from client. I used DataInputStream inputFromClient = new DataInputStream(…
Armin
  • 107
  • 1
  • 5
3
votes
2 answers

DataInputStream readLong() is getting the wrong value

Hi I'm having some troubles with the readLong() method of DataInputStream. When I put a value via DataOutputStream.writeLong() it is the right value but when it is sent it is a lot bigger than it should be, I have the code all in a runnable statment…
Luke Griffiths
  • 119
  • 1
  • 1
  • 12
3
votes
2 answers

DataInputStream readLine() deprecated

I need to use the DataInputStream, since I need the deprecated readLine() functionality and I don't know the exact file format of the input file (i.e. what line ending is used), but also need to read binary encoded primitives. This is similar to…
vincent
  • 1,953
  • 3
  • 18
  • 24
3
votes
3 answers

ReadFully() Comes at the risk of choking?

I noticed when I use readFully() on a file instead of the read(byte[]), processing time is reduced greatly. However, it occured to me that readFully may be a double edged sword. If I accidentlly try to read in a huge, multi-gigabyte file, it could…
E.S.
  • 2,733
  • 6
  • 36
  • 71
3
votes
3 answers

Java - Want to parse through eof. Code only parses once

My code below only parses through the data file once. I'm trying to get it to parse through the whole file. Every time it finds a marker, parse the data and append it to the output file. Currently it successfully parses the data once and then…
john stamos
  • 1,054
  • 5
  • 17
  • 36
3
votes
3 answers

Java, need a while loop to reach eof. i.e.while !eof, keep parsing

I currently have a working parser. It parses a file once(not what I want it to do) and then outputs parsed data into a file. I need it to keep parsing and appending to the same output file until the end of the input file. Looks something like…
john stamos
  • 1,054
  • 5
  • 17
  • 36
3
votes
2 answers

Java DataInputStream vs. BufferedInputStream

I'm looking for an efficient solution to receive and process asynchronous messages (of varying size) from a socket connection to a server. It is a good amount of bandwidth coming over (maybe 250 kB/s steady state, and can have short bursts up to 1…
JCB
  • 1,797
  • 5
  • 18
  • 22
1
2
3
22 23