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
1
vote
2 answers

Having problems with .getInputStream()

I am trying to program a TCP chat server, but am having difficulties with the .getInputStream() and .getOutputStream() methods, the compiler says it "Cannot find symbol- method .getInputStream(). Here is my code, I have not progressed very far…
Alon and Idan
  • 87
  • 1
  • 10
1
vote
0 answers

Reading bucket of elements from RandomAccessFile

I have a RandomAccessFile and I want to read fixed sized buckets of ints from this file, but each of them starts at different locations. What I am doing is creating a new DataInputStream(new BufferedInputStream(new FileInputStream(rfile2.getFD()),…
Dimitris
  • 303
  • 1
  • 6
1
vote
1 answer

Detect DataInputStream end of stream

I'm working on the server for a game right now. The server's packet reading loop is blocking, and typically waits until a packet is received to continue through the loop. However, if the client disconnects, the DataInputStream returns a single byte…
TheNewGuy
  • 411
  • 1
  • 7
  • 13
1
vote
0 answers

Input stream to pdf on Android

I am trying to save an input stream from a HTTPSUrlConnection to a PDF file stored on the device. It looks like it goes smoothly. However, when I loads the document in PDFView, I receive the following error: PDF is corrupted. private void…
7heViking
  • 7,137
  • 11
  • 50
  • 94
1
vote
1 answer

PrintStream Error with no reason?

I am making a server client system in which the client will write a message to the server and the server will save it as a string and print it in the console. But when ever the System tries to read the line I get "PrintStream error" in the console.…
Alex
  • 13
  • 2
1
vote
4 answers

java socket DataInputStream

I have a multithreaded program java java socket and I receive the information bizare. like this ¤¤¤¤¤¤23456718900263678722¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ public void run() { try { byte[] bs = new…
1
vote
0 answers

Client-server Java programm using sockets stucks while runnig, but works while debbuging

I have created a simple utility, that implements server and client. Server waits for incomming connection, client connects and if there are any files in folder on server - they are sending to client. I used DataInput/OutputStreams - writeUTF/readUTF…
1
vote
1 answer

DataInputStream hangs at the end of the stream

My Java project (I'm the client side) consists of sending requests and reading responses through TCP socket connection. Over the socket I create an Output and Input Stream for sending and receiving data, respectively. All works well, except the end…
rmpt
  • 606
  • 1
  • 4
  • 24
1
vote
2 answers

How to serialize a java object which contains object references without serializing the objects referred to?

I am implementing B Plus Tree in java . I have a node class in which I am maintaining references to child object Nodes . Now When I serialize any node , it also serialize all the child nodes also. What I want is to serialize only that node and the…
1
vote
2 answers

issue while extending InputStream class

I am trying to extend InputStream class and use customized read() methods. This is my class snapshot: class MyClass { /** Input stream */ private final MyInputStream in = new MyInputStream(); /**get the InputStream public…
1
vote
1 answer

How to continue looping through DataInputStream?

I am reading a binary file and I have to parse through the headers in this file. I have a DataInputStream set up and I need to get it to continue looping through the file until the end. I am new to Java so not sure how I would carry this over from…
mark602
  • 11
  • 1
1
vote
1 answer

If -1 is the standard EOF byte, why does DataInputStream do this?

The readInt() function from java.io.DataInputStream is as follows: public final int readInt() throws IOException { int ch1 = in.read(); int ch2 = in.read(); int ch3 = in.read(); int ch4 = in.read(); if ((ch1 | ch2 | ch3 | ch4) <…
Steven
  • 1,709
  • 3
  • 17
  • 27
1
vote
1 answer

TCP can't receive text messages after sending a file from server in Java

I'm new to socket programming and I have a problem that I can not understand. I am trying to send a file from server to client. After that, server and client start chatting until client says "Bye.". When I start the program, it works well until…
Orcun
  • 1,031
  • 1
  • 10
  • 15
1
vote
3 answers

Java DataOutputStream / DataInputStream OutOfMemoryError

I'm trying to send a byte array containing 16 items over sockets using DataOutputStream on the client and DataInputStream on the server. These are the methods I am using for sending/receiving. public void sendBytes(byte[] myByteArray) throws…
pjmil
  • 2,087
  • 8
  • 25
  • 41
1
vote
3 answers

Reading a .dat file into an array in Java

The code that I'm writing has two classes: writeInts and readInts. I wrote writeInts to randomly generate 100 numbers between 0 and 1000 and output them to a data.dat file. readInts is supposed to open a DataInputStream object and read in the "raw"…
Ben
  • 95
  • 1
  • 4
  • 16