dataoutputstream

Reading a .dat file into an array in Java

徘徊边缘 提交于 2019-12-08 08:15:02
问题 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" data from the data.dat file and store the 100 integers in an array. My problem is that I can't seem to read the data correctly. Any help with this would be greatly appreciated. Thanks! writeInts: import java.io.*; public class WriteInts { public

sending a file using DataOutputStream in java

痴心易碎 提交于 2019-12-06 12:02:49
问题 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 implement those because I am really new to java... Can anyone help me about this? Thank you! 回答1: It's quite simple, but the code is a bit long to write it all and sounds like homework. I can give you some indications. Just open the file, use the long

Command-line to reverse byte order/change endianess

回眸只為那壹抹淺笑 提交于 2019-12-05 14:51:24
问题 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 the endianess matches the endianess of the arch that you are currently on, and I'm on a little endian machine. I'm looking for an easy one-liner to reverse the byte order. Let's say that you know that the last 8 bytes of a file is a long written

sending a file using DataOutputStream in java

放肆的年华 提交于 2019-12-04 18:03:53
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 implement those because I am really new to java... Can anyone help me about this? Thank you! It's quite simple, but the code is a bit long to write it all and sounds like homework. I can give you some indications. Just open the file, use the long length() method of the class File to get the size, and the writeLong(long) method of DataOutputStream to send

Command-line to reverse byte order/change endianess

ぐ巨炮叔叔 提交于 2019-12-04 00:29:34
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 the endianess matches the endianess of the arch that you are currently on, and I'm on a little endian machine. I'm looking for an easy one-liner to reverse the byte order. Let's say that you know that the last 8 bytes of a file is a long written by the aforementioned writeLong(...) method. My current best attempt to print this long is tail -c 8

Java sockets: DataOutputStream or OutputStream?

妖精的绣舞 提交于 2019-12-03 16:53:49
问题 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 write to that. What is considered "good practice", using a DataOutputStream or OutputStream? Most of the examples I find on the internet use DataOutputStream (to send Strings, such as in a two way chat). Are there any advantages or disadvantages from

Writing large strings with DataOutputStream

戏子无情 提交于 2019-12-03 13:30:34
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 good alternatives that support larger strings or do I need to roll my own? It actually uses a two bytes to write the length of the string before using an algorithm that compacts it into one, two or three bytes per character. (See the documentation on java.io.DataOutput) It is close to UTF-8, but even though documented as being so, there are

Java sockets: DataOutputStream or OutputStream?

喜欢而已 提交于 2019-12-03 05:18:24
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 write to that. What is considered "good practice", using a DataOutputStream or OutputStream? Most of the examples I find on the internet use DataOutputStream (to send Strings, such as in a two way chat). Are there any advantages or disadvantages from using DataOutputStream over OutputStream? Is there any difference in performance that is noticeable

Android: Streaming audio over TCP Sockets

我的梦境 提交于 2019-12-03 03:45:32
问题 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 DataOutputStream , and read from it using DataInputStream . However, if I obtain the same stream from a socket instead of a File, and try writing to it, I get an exception. I am at a loss to understand what could possibly be going wrong. Any help

Android: Streaming audio over TCP Sockets

≡放荡痞女 提交于 2019-12-02 17:13:05
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 DataOutputStream , and read from it using DataInputStream . However, if I obtain the same stream from a socket instead of a File, and try writing to it, I get an exception. I am at a loss to understand what could possibly be going wrong. Any help would be greatly appreciated. EDIT: The problem is same even if I try with larger buffer sizes (65535