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
2
votes
2 answers

Why DataInput interface in Java doesn't have readUnsignedInt method

Java does not support unsigned integer types and the easiest way to represent an unsigned integer in Java is using a larger integer type. DataInput interface does provide methods for reading unsigned integer types - readUnsignedByte, which returns…
JeB
  • 11,653
  • 10
  • 58
  • 87
2
votes
0 answers

Read bytes in NanoHttpd post with octet-stream

I am using Nanohttpd in Android to create an app that receives bytes from other instance of the same app. In my case, my application works and send data normally to a web service, but when I tried to send data between two instance of this…
2
votes
1 answer

Multithreaded Server receives data from just one client JAVA

I ve created a simple MultiThreaded server. Everytime it accepts client a DataInputStream and DataOutputStream is created and the comunication start Server: public class Connection implements Runnable{ boolean isAlreadyOpened =…
Alessio Trecani
  • 713
  • 2
  • 10
  • 25
2
votes
0 answers

Performing both character and byte input from java socket inputstream at same time

I am writing a raw socket server (for learning purpose), which on any request, should parse the Content-Length header and should then extract bytes equal to Content-Length from the socket input stream and echo it back to the client. I found only one…
Anand Patel
  • 6,031
  • 11
  • 48
  • 67
2
votes
2 answers

How to serialize/deserialize with DataOutputStream and DataInputStream?

I'm trying to serialize/deserialize things with DataOutputSteam and DataInputSteam instead of ObjectInputStream/ObjectOutputStream. The serialization fails. The txt file remains empty. Of course, the test2 strings are all empty in the end (can't…
2
votes
2 answers

Send a Secret key over JAVA DataOutputStream

I am developing a FTP tool using symmetric key + RSA. I want to send my secret key to the server over dataoutputstream.How can I do this? I tried following, Client: SecretKey secretKey = en_de_cryptor.returnSecretKey(); String encodedKey =…
2
votes
1 answer

Java - Socket read from datainputstream and not get stuck in it

I've been trying to do communication from another language to Java, but when I try read data from DataInputStream in a while loop... static String getData(DataInputStream stream){ int charbyte; StringBuilder strbuilder = new…
user3818650
  • 581
  • 1
  • 7
  • 19
2
votes
1 answer

DataInputStream receives inaccurate

This problem is really giving me headache. Very simple scenario. Send and receive file over TCP using DataInputStream. This is the write method private boolean send(File file) { try { FileInputStream fileIStream = new…
OmerHalit
  • 401
  • 5
  • 18
2
votes
2 answers

Java DataInputStream sometimes returns empty

I currently am making a messaging application which I will also add encryption to later. I have a server which opens a socket and waits for clients to connect. Once client connects, it creates a new thread for that client. and then waits for…
2
votes
1 answer

Broken pipe using DataInputStream and DataOutputStream and sockets

I set up a client and server sockets. When I use classes ObjectOutputStream and ObjectInputStream and the method readObject/writeObject everything works fine. It simulates communication with a robot that I know for sure interprets correctly only…
2
votes
2 answers

java infinite loop calling datainputstream receives out of memory exception

I have the following infinite loop which listens for incoming messages: public static void listenForMessages(){ while (true) { dsocket.receive(receivepacket); byte[] rcvMsg = receivepacket.getData(); …
Atma
  • 29,141
  • 56
  • 198
  • 299
2
votes
2 answers

Using DataInputStream and DataOutputStream

I want to send several strings from A to B using the DataInputStream. I know how to send these across using .write() but I'm unsure of the best method to seperate the strings. In fact - after research, it doesn't seem as if it's possible unless I…
David Jackson
  • 31
  • 2
  • 6
2
votes
1 answer

OutputStream to DataOutputStream for bluetooth communication

I already wrote with the help of tutorials I found on the Internet a app for Android that connect to a Bluetooth device. This app used the InputStream and OutputStream object to connect and establish a connection. Because I had to transfer small…
2
votes
2 answers

C# <-> Java socket communication

I am making a .NET application which is supposed to communicate with a Java application over the sockets. Here is the .NET code: string str = " MSG1234"; TcpClient client = new TcpClient(); client.Connect("127.0.0.1", 8080); byte[] msg =…
user2109153
  • 21
  • 1
  • 3
2
votes
1 answer

Can I read a local text file line by line into a string array?

The question "How to read a local (res/raw) file line by line?" deals with a similar issue but I was unable to construct a solution base on the answers provided there. I did get a very useful piece of info (the DataInputStream class which has a…
Yak Attack
  • 105
  • 2
  • 11