Questions tagged [dataoutputstream]

A mechanism for writing abstract data to a stream

A DataOutputStream is a mechanism for writing any abstract data to a stream, regardless of the type of the data. A stream is usually comprised of data to write to a local file, or data being transmitted to a remote server over a network protocol such as HTTP or FTP.

An DataOutputStream is abstract, and doesn't describe the type of data that is being written. Typically, if you are able to, you would implement one of the subclasses instead, such as FileOutputStream, which more appropriately describes the type of data being handled, and provides additional methods appropriate for that data type.

257 questions
21
votes
3 answers

Android: Streaming audio over TCP Sockets

For my app, I need to record audio from MIC on an Android phone, and send it over TCP to the other android phone, where it needs to be played. I am using AudioRecord and AudioTrack class. This works great with a file - write audio to the file using…
Chaitanya
  • 2,039
  • 4
  • 25
  • 32
18
votes
2 answers

Why does DataOutputStream.writeUTF() add additional 2 bytes at the beginning?

When I was trying to parse xml using sax over sockets I came across a strange occurence. Upon analysing I noticed that DataOutputStream adds 2 bytes in front of my data. Message send by DataOutputStream: 0020 50 18 00 20 0f df 00 00 00 9d 3c 3f 78…
Xeno Lupus
  • 1,504
  • 3
  • 12
  • 17
17
votes
3 answers

Java sockets: DataOutputStream or OutputStream?

I'm still relatively new to sockets, and I haven't seen any information regarding this subject. To write to a connected socket, you can either use socket.getOutputStream().write Or create a new DataOutputStream from the socket OutputStream and…
David
  • 15,652
  • 26
  • 115
  • 156
16
votes
1 answer

DataOutputStream: purpose of the "encoded string too long" restriction

There is a strange restriction in java.io.DataOutputStream.writeUTF(String str) method, which limits the size of an UTF-8 encoded string to 65535 bytes: if (utflen > 65535) throw new UTFDataFormatException( "encoded string…
Andremoniy
  • 34,031
  • 20
  • 135
  • 241
15
votes
2 answers

DataOutputSteam is throwing me a 'java.io.IOException: unexpected end of stream'?

I'm trying to make a Request to a WebService from an android application, using HttpUrlConnection. But sometimes it works, and sometimes it does not. When I try sending this value: JSON value {"Calle":"Calle Pérez…
Laggel
  • 1,356
  • 3
  • 19
  • 36
13
votes
8 answers

Command-line to reverse byte order/change endianess

I'm hacking around in some scripts trying to parse some data written by Javas DataOutputStream#writeLong(...). Since java always seems to write big endian, I have a problem feeding the bytes to od. This is due to the fact that od always assumes that…
Alexander Torstling
  • 18,552
  • 7
  • 62
  • 74
13
votes
6 answers

How to use ByteArrayOutputStream and DataOutputStream simultaneously in Java?

I'm having quite a problem here, and I think it is because I don't understand very much how I should use the API provided by Java. I need to write an int and a byte[] into a byte[]. I thought of using a DataOutputStream to solve the data writing…
Manuel Araoz
  • 15,962
  • 24
  • 71
  • 95
11
votes
3 answers

Appending Byte[] to end of a binary file

I'm parsing a file. I'm creating a new output file and will have to add the 'byte[] data' to it. From there I will need to append many many other 'byte[] data's to the end of the file. I'm thinking I'll get the user to add a command line…
john stamos
  • 1,054
  • 5
  • 17
  • 36
8
votes
3 answers

Writing large strings with DataOutputStream

I've been doing some socket programming to transmit information across the wire. I've run into a problem with DataOutputStream.writeUTF(). It seems to allow strings of up to 64k but I have a few situations where I can run over this. Are there any…
Glen
  • 791
  • 2
  • 8
  • 16
6
votes
3 answers

How to append to DataOutputStream in Java?

I want my program to save URL addresses, one at a time, to a file. These addresses need to be saved in UTF format to ensure they are correct. My problem is that the file is overwritten all the time, instead of appended: DataOutputStream DOS =…
Berit Larsen
  • 739
  • 1
  • 12
  • 29
6
votes
3 answers

DataOutputStream#writeBytes(String) vs BufferedWriter#write(String)

I would like to create a HTML file for my report. The content in the report can be created either by using BufferedWriter#write(String) File f = new File("source.htm"); BufferedWriter bw = new BufferedWriter(new…
Java Beginner
  • 1,635
  • 11
  • 29
  • 51
4
votes
2 answers

Sending data from Java to C using socket programming

i am making a program that sends a string from a Java client to a C server using WinSock2. I am using DataOutputStream to send the data through the socket. The C server, acknowledges the bytes received, but when i try accessing the data, nothing is…
user761968
  • 41
  • 1
  • 2
4
votes
1 answer

Compare DataOutputStream to String in Java

I have a DataOutputStream I would like to copy into a string. I've found a lot of tutorials on converting DataOutputStreams by setting it to a new ByteArrayOutputStream, but I just want to read the string it sends when it flushes, and my…
Andrew Feather
  • 173
  • 2
  • 14
4
votes
3 answers

Why DataOutputStream doesn't create a "Resource leak: stream never closed " warning

Why DataOutputStream doesn't create a "Resource leak: stream never closed " warning. public static void main(String[] args) { try{ DataOutputStream o = new DataOutputStream(System.out); o.writeInt(12); } catch(IOException…
Mohamed Kamaly
  • 127
  • 3
  • 10
4
votes
2 answers

Unable to write into DataOutputStream beyond a specific size - OutOfMemoryError

I have the following code which produces an OutOfMemory exception: byte[] buf = new byte[10240]; int len = 0; DataOutputStream dataOS = new DataOutputStream(conn.getOutputStream()); while ((len = _inputStream.read(buf)) > 0) { …
Ram
  • 1,097
  • 2
  • 12
  • 24
1
2 3
17 18