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

Send packet over UDP socket

I am trying to send the following data to a server, that will be using C++: static int user_id; // 4 Bytes static byte state; // 1 Byte static String cipher_data; // 128 Bytes static String hash; // 128 Bytes static final int PACKET_SIZE =…
3
votes
1 answer

How to know number of bytes of a Binary File?

How to count number of bytes of this binary file (t.dat) without running this code (as a theoretical question) ? Assuming that you run the following program on Windows using the default ASCII encoding. public class Bin { public static void…
dave
  • 61
  • 6
3
votes
1 answer

Uploading large file from Android app gives out of memory error despite buffering

I'm trying to upload a large video file (about 900mb) to a PHP server using POST. I'm using FileInputStream to read the file and writing it to a HTTPUrlConnection using a DataOutputStream. I eventually get out of memory despite a 1024 byte buffer,…
Hamzah Malik
  • 2,540
  • 3
  • 28
  • 46
3
votes
2 answers

Send Multiple POST Requests Through a DataOutputStream in Java

I am trying to use a for loop to send multiple POST requests through a DataOutputStream and then close it. At the moment, only the first index of the "trades" array list is sent to the website. Any other indexes are ignored and I'm assuming they are…
lsnow2017
  • 139
  • 1
  • 2
  • 13
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
3 answers

writeUTF(String s) vs writeObject(String s)

In this Java project I'm working on for university, I have a situation where I am currently sending strings through the network successfully using streamOut = ObjectOutputStream streamIn = ObjectInputStream streamOut.writeUTF(msgs.peek()); where…
boris dzhelali
  • 197
  • 1
  • 10
3
votes
2 answers

Android TCP does not flush until socket is closed

I have been trying various implementations to make this work, and have searched StackOverflow and Android Developers for a solution, but I am not too experienced in programming and cannot get this block to code to work properly. My Intent: This is…
Nissi
  • 205
  • 3
  • 13
2
votes
3 answers

Writing unicode to rtf file

I´m trying write strings in diffrent languages to a rtf file. I hav tried a few different things. I use japanese here as an example but it´s the same for other languages i have tried. public void writeToFile(){ String strJapanese = "日本語"; …
Oglop
  • 260
  • 1
  • 3
  • 11
2
votes
1 answer

sending a file using DataOutputStream in java

I am trying to build a client that sends the file size and contents to server. I am trying to use DataOutputStream. I am assuming that I need to open the file and and get size of file and read the contents and send it. But I am not sure how to…
in His Steps
  • 3,075
  • 6
  • 30
  • 38
2
votes
2 answers

Pros and cons for using ObjectInputStream/ObjectOutputStream to implement network "packets" in Java?

I'm working on a simple client/server application that uses sockets for all the communications. Communications are packet-based and the concept of packets is implemented using a set of classes and ObjectInputStream/ObjectOutputStream wrapper for…
Andrey Agibalov
  • 7,624
  • 8
  • 66
  • 111
2
votes
2 answers

Stuck in write operation when reading from Socket

I'm sending a file and its name through Socket to a ServerSocket. It works "partially" -- the server gets the file and saves it to disk but it does not exit the loop in the copy() method in the ClientSession class. public class Client{ …
aloy
  • 53
  • 6
2
votes
1 answer

Writing the contents of a ByteBuffer to a DataOutput?

The object to which I need to write a ByteBuffer is typed as an instance of interface DataOutput, rather than as an instance of class DataOutputStream (which implements DataOutput). I need to assume ByteBuffer.hasArray() can return false, so I don't…
Nathan Ryan
  • 12,893
  • 4
  • 26
  • 37
2
votes
0 answers

How to perform seek in a Dataoutput Stream?

I am using a dataoutput/datainputStream to make a binary Tree over a file,reading a 50000 lines .csv file to build it. Initially i thought to achieve this with the RandomAccesFile class, but it has serious permormance issues (it's very slow on…
2
votes
1 answer

Write to an offset using DataOutputStream

In my project, we are writing a file using DataOutputStream. We are writing different data types like short, byte, int and long and we are using respective methods in DataOutputStream like writeShort(), writeByte() etc. Now, I want to edit one…
Bagira
  • 2,149
  • 4
  • 26
  • 55
2
votes
0 answers

JavaFX Can't send data via socket from Controller

I have a simple JavaFX app when I start the app it extablishes a connection with a server via Socket and listen for data from this server continously. Now I have a created a Button that should send dat to server. This is how I did it Controller: …
Alessio Trecani
  • 713
  • 2
  • 10
  • 25
1
2
3
17 18